Methodology · Playground · Last updated 2026-04-20
How Pair Trading Cointegration Tester works
How the Pair Trading Cointegration Tester tool actually works — algorithms, critical values, limitations.
Scope
Implements the full Engle-Granger two-step cointegration test for a pair of price series, plus the Ornstein-Uhlenbeck mean-reversion half-life and a rolling z-score of the spread with configurable entry/exit bands. Verdict: tradable pair, borderline, or not cointegrated.
Inputs
date,asset_a,asset_b
2024-01-02,100.12,50.08
2024-01-03,100.35,50.21
... The two numeric columns (A, B) are treated as price series (positive values enforced). Prices are log-transformed internally. Minimum 60 aligned observations. Columns are assumed to share the same time index (no re-alignment is attempted).
Step 1 — OLS hedge ratio
log A_t = α + β · log B_t + ε_t
Standard ordinary least squares. The slope β is the
hedge ratio in log-space — how many units of log B to short for each
unit of long log A to construct the spread.
Step 2 — Augmented Dickey-Fuller on residuals
Δε_t = ρ · ε_{t−1} + Σ_i δ_i · Δε_{t−i} + u_t
Test statistic is the t-statistic on ρ.
Under H₀ (unit root, not cointegrated), this t
follows a non-standard distribution. Critical values come from
MacKinnon (2010) asymptotics for the "no deterministic trend" case:
1%: −2.56574
5%: −1.94097
10%: −1.61682 The default ADF lag order is 1; the tool exposes lag count as an input for user-supplied preferences. Note that Engle-Granger's ADF step uses slightly different (more conservative) critical values than plain ADF because the residuals are estimated, not observed — this tool uses the standard ADF values, which is a known mild approximation. For high-stakes trading decisions, verify with a dedicated econometrics package (e.g. statsmodels).
Ornstein-Uhlenbeck half-life
Δε_t = −θ · ε_{t−1} + noise → half_life = ln(2) / θ
Regress the first-difference of the spread on the lagged spread.
A positive θ indicates mean reversion; the half-life is
how many periods it takes for a displacement to revert by half.
Half-life below 30 days on daily data usually indicates a tradable
rhythm; 30–90 days is borderline; above 90 is too slow for
capital-intensive statarb.
Z-score of the spread
The rolling z-score is computed with a user-configurable window (default 60 observations). Signal bands:
- Entry:
|z| > entry_thresholdopens a position. - Exit:
|z| < exit_thresholdcloses it.
The tool reports entry/exit event counts as a sanity check — if there are very few events over the sample, either the spread does not reach the band or the band is too wide; if hundreds, the band is too tight.
Verdict bands
- Tradable: ADF stationary at 5% AND half-life < 30 days.
- Borderline: stationary but slow-reverting, OR fast-reverting but ADF-marginal.
- Not cointegrated: neither.
Assumptions + limitations
- Stationary cointegrating vector. β is assumed constant over the sample. Regime-changing relationships (e.g. post-merger, index-inclusion) require a structural-break-aware extension (Gregory-Hansen).
- Engle-Granger, not Johansen. EG assumes one cointegrating vector and is sensitive to which side of the regression is the "dependent" variable. For more than two assets or when the direction matters, Johansen's test is preferred.
- ADF critical values approximation. Using plain ADF critical values on estimated residuals is mildly conservative; for a precise Engle-Granger test, use PO critical values (Phillips-Ouliaris). The direction of the approximation is toward false rejection, not false acceptance.
- No serial-correlation-robust standard errors. OLS standard errors are not Newey-West-corrected. Hedge ratio
βmay be more uncertain than the point estimate suggests. - No transaction cost model. The z-score entry/exit counts ignore costs. Real pair trades at $1–5k size on retail venues lose 5–20 bps per round trip; on fast-reverting pairs this can consume the statistical edge entirely.
- Stationarity is a necessary, not sufficient, condition. A cointegrated pair with a half-life of 200 days or a stationary test barely passing 5% is not a tradeable edge — it is a sample-peculiarity survivor.
Privacy
All parsing, regression, ADF, and z-score computation run in the browser. No data is uploaded.
References
- Engle, R. F., & Granger, C. W. J. (1987). "Co-integration and Error Correction: Representation, Estimation, and Testing." Econometrica 55(2), 251–276.
- Dickey, D. A., & Fuller, W. A. (1979). "Distribution of the Estimators for Autoregressive Time Series With a Unit Root." JASA 74(366).
- MacKinnon, J. G. (2010). "Critical Values for Cointegration Tests." Queen's Economics Department Working Paper No. 1227.
- Chan, E. (2013). Algorithmic Trading: Winning Strategies and Their Rationale. Wiley.
- Phillips, P. C. B., & Ouliaris, S. (1990). "Asymptotic Properties of Residual Based Tests for Cointegration." Econometrica 58(1).
Connects to
- Risk-Adjusted Returns Calculator — evaluate the z-score signal's backtested Sharpe after you pick bands.
- Backtest Overfitting Score — before trading a pair, measure whether the edge survives in-sample / out-of-sample cross-validation.
- Correlation Matrix Visualizer — pair trades lose diversification when market-wide correlations spike.
Changelog
- 2026-04-20 — Initial release: Engle-Granger OLS + ADF, OU half-life, rolling z-score with entry/exit bands.