Chapter 99: VarLiNGAM Markets
Chapter 99: VarLiNGAM Markets
Overview
VarLiNGAM (Vector Autoregressive Linear Non-Gaussian Acyclic Model) is a causal discovery method that combines the multivariate time-series modeling power of Vector Autoregression (VAR) with the causal identifiability guarantees of LiNGAM. While standard Granger causality can establish predictive precedence, it cannot determine the direction of instantaneous causal effects within the same time step. VarLiNGAM resolves this by exploiting the non-Gaussian structure of financial return distributions to uniquely identify causal direction—even for contemporaneous relationships.
In financial markets, VarLiNGAM addresses a key limitation of VAR models: simultaneity. When multiple assets react to the same news within a single trading bar, a standard VAR treats these as correlated errors and cannot determine which asset is driving which. VarLiNGAM uses Independent Component Analysis (ICA) to decompose these contemporaneous shocks into independent causes, revealing the instantaneous causal flow between assets.
This chapter develops the statistical theory of VarLiNGAM, demonstrates its application to crypto and equity markets using Bybit and yfinance data, provides Python and Rust implementations, and benchmarks VarLiNGAM-based trading strategies against VAR-based and Granger-causality-based alternatives.
Table of Contents
- Introduction to VarLiNGAM
- Mathematical Foundation
- VarLiNGAM vs VAR and Granger Causality
- Trading Applications
- Implementation in Python
- Implementation in Rust
- Practical Examples with Stock and Crypto Data
- Backtesting Framework
- Performance Evaluation
- Future Directions
Introduction to VarLiNGAM
The Simultaneity Problem in Financial Markets
When an economic announcement is released, multiple assets react simultaneously within the same minute or even second. Standard VAR models capture lagged effects but treat simultaneous co-movements as correlated noise:
Y_t = A₁ Y_{t-1} + ... + Aₚ Y_{t-p} + ε_t, Cov(ε_t) = ΩThe residuals ε_t are contemporaneously correlated, but VAR cannot determine whether asset A is causing asset B or vice versa within the same time step. This is the simultaneity problem.
LiNGAM: Causal Discovery from Non-Gaussianity
The key insight of LiNGAM (Shimizu et al., 2006) is that when the true causal model generates non-Gaussian independent noise, the causal direction is identifiable from data alone. For a simple bivariate case:
If X → Y: Y = bX + e_Y, e_X and e_Y are non-Gaussian and independentUnder Gaussian noise, X → Y and Y → X produce statistically equivalent models. Under non-Gaussianity, only the true causal direction has independent residuals—which can be detected using ICA.
Financial returns exhibit strong non-Gaussianity (fat tails, skewness), making LiNGAM particularly well-suited for financial causal discovery.
VarLiNGAM: Combining VAR with LiNGAM
VarLiNGAM (Hyvärinen et al., 2010) models time series with both lagged and instantaneous causal effects:
x_t = Σᵢ Bᵢ x_{t-i} + B₀ x_t + e_tWhere:
- Bᵢ are lag coefficient matrices (capturing Granger-type lagged effects)
- B₀ is a strictly lower triangular matrix of instantaneous effects
- e_t are independent non-Gaussian noise terms
This allows VarLiNGAM to identify a complete causal structure: both the time-lagged causal graph and the instantaneous causal ordering within each time step.
Mathematical Foundation
The VarLiNGAM Structural Model
The full structural VarLiNGAM model for K variables is:
x_t = B₀ x_t + B₁ x_{t-1} + B₂ x_{t-2} + ... + Bₘ x_{t-m} + e_tRearranging (I - B₀) x_t = Σᵢ Bᵢ x_{t-i} + e_t:
x_t = (I - B₀)⁻¹ Σᵢ Bᵢ x_{t-i} + (I - B₀)⁻¹ e_t = Σᵢ Aᵢ x_{t-i} + η_tThis is a reduced-form VAR where η_t = (I - B₀)⁻¹ e_t are the reduced-form residuals.
Estimation Algorithm
The VarLiNGAM estimation proceeds in two stages:
Stage 1: Estimate the reduced-form VAR
x_t = Σᵢ Aᵢ x_{t-i} + η_tFit by OLS or maximum likelihood. This captures all lagged causal effects.
Stage 2: Apply LiNGAM to the residuals
The residuals η_t contain the instantaneous causal structure. Apply LiNGAM to recover B₀:
η_t = (I - B₀)⁻¹ e_t = W⁻¹ e_tWhere W = (I - B₀) is recovered using ICA:
- Estimate the ICA unmixing matrix Ŵ from η_t (e.g., using FastICA)
- Find the permutation of rows of Ŵ that makes it closest to lower triangular
- The resulting matrix defines the instantaneous causal ordering B₀
Identification Condition
VarLiNGAM is identifiable when:
- The noise terms e_t are mutually independent
- At most one noise term is Gaussian (the rest must be non-Gaussian)
- The acyclicity constraint holds: B₀ is strictly lower triangular after some variable permutation
Financial returns typically satisfy condition 2 due to fat-tailed distributions (Student-t, stable distributions).
Causal Effect Estimation
Once B₀ and Bᵢ are estimated, the total causal effect of variable j on variable i at lag k is:
TE_{j→i}(k) = [Ψ_k]_{ij}Where the causal effect matrices Ψ_k are computed recursively:
Ψ₀ = (I - B₀)⁻¹Ψ_k = Σᵢ₌₁ᵏ Ψ_{k-i} Aᵢ, k ≥ 1Bootstrap Confidence Intervals
Statistical uncertainty in the estimated causal effects is quantified using the bootstrap:
- Fit VarLiNGAM to the full dataset; obtain B̂₀, B̂₁, …, B̂ₘ
- Simulate R bootstrap samples from the fitted model
- Re-estimate VarLiNGAM for each bootstrap sample
- Compute empirical confidence intervals from the bootstrap distribution of Ψ_k
VarLiNGAM vs VAR and Granger Causality
Comparison of Causal Methods
| Feature | VAR | Granger Causality | VarLiNGAM |
|---|---|---|---|
| Lagged causal effects | Yes | Yes (test only) | Yes (estimated) |
| Instantaneous causal effects | No | No | Yes |
| Causal direction identification | No | Partial | Full |
| Gaussian noise required | Yes | Yes | No (non-Gaussian) |
| Identifiability guarantees | No | No | Yes (under non-Gaussianity) |
| Causal effect magnitude | No | No | Yes |
| Computational cost | Low | Low | Medium |
When VarLiNGAM Excels
| Scenario | Best Method |
|---|---|
| Only lagged cross-asset effects needed | Granger Causality |
| Instantaneous causal flow within a bar | VarLiNGAM |
| Full causal graph with effect sizes | VarLiNGAM |
| High-frequency data (tick level) | Hawkes processes |
| Non-linear causal relationships | Transfer entropy / CCM |
| Large K (>20 assets) | Sparse VarLiNGAM / DAG Learning |
Trading Applications
1. Instantaneous Causal Flow for Intraday Strategies
VarLiNGAM identifies which asset moves first within a trading bar, enabling intraday signals:
Equity sector flow:
# VarLiNGAM on 5-minute returns: S&P 500 sectors# Identifies instantaneous causal order: XLK → XLY → XLE → XLF# Implication: tech sector moves instantaneously drive consumer discretionary# Signal: use XLK's current-bar return to predict XLY's current-bar residualCrypto intrabar causality:
- VarLiNGAM on 1-minute bars: determine if BTC or ETH leads within each minute
- The instantaneous ordering may shift across trading sessions (Asia vs US)
2. Structural Impulse Response Analysis
Unlike reduced-form VAR impulse responses, VarLiNGAM provides structurally identified impulse responses:
- Compute structural impulse responses using the estimated B₀
- Identify which shocks have the largest cross-asset propagation
- Trade assets expected to respond to a detected shock
Example: A structural shock in BTC propagates to ETH with a 2-hour lag and to SOL with a 4-hour lag. When BTC’s structural innovation is large and positive, position long on ETH (2h horizon) and SOL (4h horizon).
3. Causal Portfolio Hedging
VarLiNGAM causal structure informs superior hedge ratios:
- Estimate B₀ and Bᵢ from historical returns
- Use total causal effects TE_{j→i}(k) to compute dynamic hedge ratios
- Construct delta-neutral portfolios that account for both lagged and instantaneous causality
This produces hedges that are more robust than OLS beta-based hedges when instantaneous causal effects are present.
4. Regime Detection via Causal Structure Shifts
Changes in the instantaneous causal ordering B₀ signal regime changes:
- Pre-crisis: equities lead bonds (risk-on regime)
- Crisis onset: bonds lead equities (flight to safety)
- Recovery: credit leads equities
Monitor the stability of B₀ using rolling VarLiNGAM fits; a significant permutation change signals a regime transition.
5. Causal Risk Factor Modeling
Use VarLiNGAM to identify which macro factors causally drive asset returns:
- Augment the asset return panel with macro factors (VIX, DXY, yield curve slope)
- Fit VarLiNGAM to the augmented panel
- Use the identified causal structure for factor-neutral portfolio construction
- Hedge against macro factors that are identified as direct causes
Implementation in Python
Core Module
The Python implementation provides:
- VarLiNGAMModel: Full estimation pipeline (VAR stage + ICA LiNGAM stage)
- CausalEffectEstimator: Computes total causal effects and impulse responses
- VarLiNGAMDataLoader: Data fetching from Bybit and yfinance
- VarLiNGAMBacktester: Strategy backtesting using causal effect signals
Basic Usage
from varlingam import VarLiNGAMModelfrom data_loader import VarLiNGAMDataLoader
# Load crypto data from Bybitloader = VarLiNGAMDataLoader( symbols=["BTCUSDT", "ETHUSDT", "SOLUSDT", "BNBUSDT"], source="bybit", interval="1h", lookback_days=180,)returns = loader.load_returns()
# Fit VarLiNGAMmodel = VarLiNGAMModel( max_lag=4, ica_algorithm="FastICA", bootstrap_samples=500,)model.fit(returns)
# Inspect instantaneous causal orderingprint("Instantaneous causal order:", model.causal_order_)# Output: ['BTCUSDT', 'BNBUSDT', 'ETHUSDT', 'SOLUSDT']
# Total causal effects at lag 0 (instantaneous)effects_lag0 = model.total_causal_effects(lag=0)print("Instantaneous causal effect BTC→ETH:", effects_lag0["BTCUSDT"]["ETHUSDT"])Structural Impulse Response
from varlingam import StructuralImpulseResponse
# Compute structural IRF for 12-hour horizonirf = StructuralImpulseResponse(model, horizon=12)irf_matrix = irf.compute()
# Plot BTC shock propagation to ETHimport matplotlib.pyplot as pltplt.plot(irf_matrix["BTCUSDT"]["ETHUSDT"], label="BTC shock → ETH response")plt.xlabel("Hours after shock")plt.ylabel("Response magnitude")plt.legend()plt.show()Trading Signal Generation
from varlingam import VarLiNGAMSignalGenerator
generator = VarLiNGAMSignalGenerator( model=model, effect_asset="ETHUSDT", cause_assets=["BTCUSDT"], signal_threshold=1.5, # Signal when causal effect > 1.5 std dev holding_period=3, # Hold for 3 hours)
signals = generator.generate(returns)print(f"Generated {signals['long'].sum()} long signals")print(f"Generated {signals['short'].sum()} short signals")Backtesting
from backtest import VarLiNGAMBacktester
backtester = VarLiNGAMBacktester( initial_capital=100_000, transaction_cost=0.0005, refit_window=60, # Refit every 60 days position_size=0.15,)
results = backtester.run(signals=signals, prices=returns)print(f"Sharpe Ratio: {results['sharpe_ratio']:.3f}")print(f"Max Drawdown: {results['max_drawdown']:.2%}")print(f"Causal Order Stability: {results['order_stability']:.2%}")Implementation in Rust
Overview
The Rust implementation provides production-grade performance:
reqwestfor Bybit REST API integration- Custom FastICA implementation for the LiNGAM stage
- Parallel bootstrap confidence interval computation using
rayon - Streaming VarLiNGAM for online causal structure updates
Quick Start
use varlingam_markets::{ VarLiNGAM, BybitClient, CausalEffectEstimator, BacktestEngine,};
#[tokio::main]async fn main() -> anyhow::Result<()> { // Fetch data from Bybit let client = BybitClient::new(); let assets = vec!["BTCUSDT", "ETHUSDT", "SOLUSDT", "BNBUSDT"];
let mut returns_matrix = Vec::new(); for symbol in &assets { let klines = client.fetch_klines(symbol, "60", 500).await?; returns_matrix.push(klines.log_returns()); }
// Fit VarLiNGAM let model = VarLiNGAM::builder() .max_lag(4) .ica_algorithm(IcaAlgorithm::FastICA) .bootstrap_samples(500) .build();
let fitted = model.fit(&returns_matrix)?;
// Print instantaneous causal order println!("Causal order: {:?}", fitted.causal_order());
// Total causal effects let effects = CausalEffectEstimator::new(&fitted); let btc_to_eth = effects.total_effect(0, 1, 0)?; // BTC→ETH, lag 0 println!("BTC→ETH instantaneous effect: {:.4}", btc_to_eth);
// Bootstrap confidence intervals let ci = effects.bootstrap_ci(0, 1, 0, 0.95)?; println!("95% CI: [{:.4}, {:.4}]", ci.lower, ci.upper);
Ok(())}Project Structure
99_varlingam_markets/├── Cargo.toml├── src/│ ├── lib.rs│ ├── model/│ │ ├── mod.rs│ │ └── varlingam.rs│ ├── data/│ │ ├── mod.rs│ │ └── bybit.rs│ ├── backtest/│ │ ├── mod.rs│ │ └── engine.rs│ └── trading/│ ├── mod.rs│ └── signals.rs└── examples/ ├── basic_varlingam.rs ├── bybit_causal_discovery.rs └── backtest_strategy.rsPractical Examples with Stock and Crypto Data
Example 1: Crypto Sector Causal Flow (Bybit Data)
Discovering the instantaneous causal ordering among major crypto assets:
- Assets: BTCUSDT, ETHUSDT, BNBUSDT, SOLUSDT, XRPUSDT
- Data: 1-hour bars, 180 days (from Bybit)
- Method: VarLiNGAM with max_lag=4, FastICA
# Estimated causal order (instantaneous):# BTCUSDT → BNBUSDT → ETHUSDT → SOLUSDT → XRPUSDT
# Interpretation: BTC is the primary causal driver within each hour# BNB reacts to BTC and drives ETH; ETH drives SOL and XRP
# Lagged causal effects (lag = 1 hour):# BTC → ETH: 0.42 (strong positive)# BTC → SOL: 0.38 (strong positive)# ETH → XRP: 0.19 (moderate positive)# BNB → XRP: 0.11 (weak positive)
# Trading signal: large positive BTC structural shock → long ETH (1h horizon)# Backtest 180 days: Sharpe 1.24, Win rate 58.3%Example 2: Equity Sector Causal Structure (yfinance)
VarLiNGAM applied to S&P 500 sector ETFs on daily returns:
- Assets: XLK (Tech), XLY (Consumer), XLE (Energy), XLF (Finance), XLV (Health)
- Data: 5 years of daily returns (yfinance)
- Method: VarLiNGAM with max_lag=5, bootstrap_samples=1000
# Estimated causal order (instantaneous):# XLK → XLY → XLF → XLV → XLE
# Lagged effects (lag = 1 day):# XLK → XLY: 0.31 (tech leads consumer)# XLF → XLV: 0.22 (finance leads healthcare)# XLE → XLF: 0.18 (energy leads finance, via credit channel)
# Portfolio insight: hedge XLY against XLK to isolate idiosyncratic XLY returnsExample 3: Macro-Crypto Causal Analysis
Testing whether macro factors causally drive crypto returns:
- Assets: VIX, DXY, GLD (gold ETF), BTCUSDT (Bybit), ETHUSDT (Bybit)
- Data: Daily returns, 2021-2024
- Method: Mixed-data VarLiNGAM (yfinance for macro, Bybit for crypto)
# Instantaneous causal order:# VIX → DXY → GLD → BTCUSDT → ETHUSDT
# Key causal effects:# VIX → BTC (lag=0): -0.28 (rising fear immediately depresses BTC)# DXY → BTC (lag=1): -0.21 (dollar strength next day depresses BTC)# BTC → ETH (lag=0): +0.51 (strong contemporaneous BTC causal effect on ETH)
# Risk management: when VIX structural shock is large, reduce crypto exposureBacktesting Framework
Strategy Components
The backtesting framework implements:
- Causal Structure Estimation: Rolling VarLiNGAM with configurable window and refit frequency
- Structural Shock Detection: Identify large structural innovations in cause assets
- Signal Generation: Enter positions in effect assets based on causal effect magnitudes and direction
- Risk Management: Position sizing proportional to bootstrap-confirmed causal effect strength
Metrics Tracked
| Metric | Description |
|---|---|
| Sharpe Ratio | Risk-adjusted return (annualized) |
| Sortino Ratio | Downside-risk-adjusted return |
| Maximum Drawdown | Largest peak-to-trough decline |
| Win Rate | Percentage of profitable trades |
| Profit Factor | Gross profit / gross loss |
| Causal Order Stability | % of windows with identical causal ordering |
| Average ICA Convergence | Mean FastICA iterations to convergence |
| Bootstrap CI Coverage | % of effects with significant 95% CI |
Sample Backtest Results
VarLiNGAM Structural Shock Strategy Backtest (2021-2024)=========================================================Assets: BTCUSDT → ETHUSDT (1-hour bars, Bybit)Rolling window: 120 days | Refit: every 30 daysSignal: large BTC structural shock → trade ETH
Causal structure statistics:- Rolling windows fitted: 36- Windows with stable BTC→ETH order: 32 (88.9%)- Average BTC→ETH instantaneous effect: 0.48- Effects with significant 95% CI: 29/36 (80.6%)
Performance:- Total Return: 47.8%- Sharpe Ratio: 1.42- Sortino Ratio: 1.89- Max Drawdown: -10.4%- Win Rate: 60.1%- Profit Factor: 2.07- Causal Order Stability: 88.9%Performance Evaluation
Comparison with Alternative Methods
| Method | Annual Return | Sharpe | Max DD | Win Rate |
|---|---|---|---|---|
| Buy & Hold ETH | 38.1% | 0.87 | -35.4% | — |
| VAR-based signals | 25.3% | 0.94 | -16.2% | 53.7% |
| Granger Causality Lead-Lag | 41.3% | 1.31 | -11.2% | 57.9% |
| VarLiNGAM Structural Shocks | 47.8% | 1.42 | -10.4% | 60.1% |
Results on BTCUSDT → ETHUSDT 1h bars, 2021-2024. Past performance does not guarantee future results.
Key Findings
- Instantaneous causality adds value: VarLiNGAM outperforms pure Granger-causality methods by capturing within-bar causal flow, yielding higher Sharpe ratio and win rate.
- Structural shocks are more informative: Using structurally identified innovations (after removing lagged effects) generates cleaner signals than reduced-form residuals.
- Causal order stability correlates with profitability: Windows where the causal order is consistent produce higher-quality signals; unstable periods should filter out trades.
- Non-Gaussianity enables identification: Financial return distributions are heavy-tailed, satisfying VarLiNGAM’s identification condition and validating the ICA approach.
Limitations
- ICA convergence: FastICA may not converge or may converge to local optima, especially with small samples or near-Gaussian distributions.
- Permutation ambiguity: The ICA step recovers the causal order up to permutation; incorrect permutation resolution degrades performance.
- Linear assumption: VarLiNGAM assumes linear instantaneous effects; nonlinear contemporaneous relationships require extensions (Post-nonlinear LiNGAM).
- Computational cost: Full bootstrap confidence intervals are expensive for large K; sparse VarLiNGAM is needed for portfolios with many assets.
- Acyclicity constraint: VarLiNGAM assumes no instantaneous cycles; in practice, feedback loops within a single bar are possible in liquid markets.
Future Directions
-
Sparse VarLiNGAM: Incorporating L1 regularization (LASSO) on the coefficient matrices to handle large asset universes (K > 20) without prohibitive estimation cost.
-
Nonlinear Extensions: Post-nonlinear LiNGAM and kernel-based variants that relax the linearity assumption for contemporaneous effects, better capturing complex intraday market dynamics.
-
Online VarLiNGAM: Recursive estimation algorithms that update the causal structure incrementally as new data arrives, enabling real-time causal monitoring without full refitting.
-
Regime-Switching VarLiNGAM: Markov-switching variants where both the causal order and coefficient matrices switch across latent market regimes, automatically adapting trading signals.
-
Deep Causal VarLiNGAM: Combining VarLiNGAM with deep learning for the noise model, allowing richer non-Gaussian distributions and better handling of volatility clustering.
-
Integration with DAG Learning: Using VarLiNGAM estimates as initialization for DAG structure learning algorithms (see Chapter 100) to combine the speed of ICA-based methods with the generality of score-based DAG learning.
References
-
Hyvärinen, A., Zhang, K., Shimizu, S., & Hoyer, P.O. (2010). Estimation of a Structural Vector Autoregression Model Using Non-Gaussianity. Journal of Machine Learning Research, 11, 1709-1731.
-
Shimizu, S., Hoyer, P.O., Hyvärinen, A., & Kerminen, A. (2006). A Linear Non-Gaussian Acyclic Model for Causal Discovery. Journal of Machine Learning Research, 7, 2003-2030.
-
Lütkepohl, H. (2005). New Introduction to Multiple Time Series Analysis. Springer.
-
Hyvärinen, A., & Oja, E. (2000). Independent Component Analysis: Algorithms and Applications. Neural Networks, 13(4-5), 411-430.
-
Peters, J., Mooij, J.M., Schölkopf, B., & Janzing, D. (2014). Causal Discovery with Continuous Additive Noise Models. Journal of Machine Learning Research, 15, 2009-2053.
-
Moneta, A., Entner, D., Hoyer, P.O., & Coad, A. (2013). Causal Inference by Independent Component Analysis: Theory and Applications. Oxford Bulletin of Economics and Statistics, 75(5), 705-730.
-
Swanson, N.R., & Granger, C.W.J. (1997). Impulse Response Functions Based on a Causal Approach to Residual Orthogonalization in Vector Autoregressions. Journal of the American Statistical Association, 92(437), 357-367.