pairs-trading-lab
ongoing research projectdeterministic synthetic data

Sector-neutral
pairs trading,
end to end.

An interactive lab built from the literature: cointegration via Engle-Granger, hedge ratios from rolling OLS and a Kalman filter, walk-forward backtests with realistic frictions, and risk-parity sizing across pairs. Bring no data — six pairs come pre-loaded.

cointegration vector
z-score signal
half-life (OU)
live preview
MEGA/WHENBanks
z-score · spread
β 1.017ADF τ -7.96p≈ 0.005

Live render of the MEGA-WHEN synthetic spread. Bands at ±2σ, hedge ratio from full-sample OLS, z-score on a 60-day rolling window.

01 / pipeline

From a price universe to a risk-managed book.

UUniverseSector clusters01𝜏CointegrationEngle-Granger / ADF02βHedge ratioOLS · rolling · Kalman03zZ-scoreRolling std04ExecuteCosts · slippage · stops05ΣSizeRisk parity · β-hedge06THE PIPELINESTATISTICAL EDGERISK-MANAGED EXECUTION
03 / built on the literature

The papers behind every module.

Cointegration
Engle & Granger (1987)

Two-step procedure: estimate the long-run relationship, then test residuals for a unit root. Foundation of the entire pairs framework.

Critical values
MacKinnon (1996, 2010)

Finite-sample response surfaces for ADF and cointegration test critical values. Used directly to compute T-adjusted thresholds in this app.

Distance + cointegration
Gatev, Goetzmann & Rouwenhorst (2006)

Empirical demonstration that mean-reverting pairs delivered ~11% annualized excess return 1962–2002. The seminal benchmark.

Time-varying β
Elliott, van der Hoek & Malcolm (2005)

Mean-reverting Gaussian state-space model — the textbook motivation for using a Kalman filter to estimate hedge ratios.

Statistical arbitrage
Avellaneda & Lee (2010)

PCA / sector-residual approach with the s-score signal. Maps neatly onto the sector-neutral framing used here.

Decline & costs
Do & Faff (2010, 2012)

Explicit decomposition showing how transaction costs gradually erode pairs profitability post-2002. Why the Backtest Studio takes costs seriously.

OU thresholds
Bertram (2010)

Analytic optimal entry/exit bands for an Ornstein-Uhlenbeck spread under fixed costs. Reference for the band-suggestion overlay.

Risk parity
Maillard, Roncalli & Teiletche (2010)

Equal-risk-contribution portfolio construction. Used in Portfolio to size pairs by risk rather than capital.

Liquidity
Amihud (2002)

Daily price-impact-per-dollar-of-volume measure. Used here to filter out pairs whose worse leg is too thin to trade.

Multivariate cointegration
Johansen (1988, 1991)

Trace and max-eigenvalue tests give the full rank of the cointegration space. The Methods page runs the 2-variable form against Osterwald-Lenum CVs.

Stationarity null
Kwiatkowski-Phillips-Schmidt-Shin (1992)

Reverses the ADF null. A pair worth trading rejects ADF and fails to reject KPSS — the Lab requires both.

Random walk null
Lo & MacKinlay (1988)

Variance ratio test with heteroskedasticity-robust z. The Methods page reports VR(q) at six horizons from 2 to 64.

Self-similarity
Hurst (1951), Mandelbrot (1969)

Rescaled-range slope tells you whether a series is mean-reverting (H<0.5), random (H=0.5), or trending (H>0.5).

Structural breaks
Brown, Durbin & Evans (1975)

CUSUM of recursive residuals with Brownian-motion bands. The Lab's primary breakdown-warning system.

Tail risk
Rockafellar & Uryasev (2002)

Conditional VaR / Expected Shortfall — coherent risk measure used throughout the Risk Lab.

Bootstrap
Politis & Romano (1994)

Stationary bootstrap with geometric block lengths. Honest standard errors on Sharpe under serial correlation.

Implementations are educational and audited against textbook results; the synthetic universe is constructed so OLS, ADF, Engle-Granger, OU and Kalman behave as theory predicts.