Objective
The stat-arb primer explained why pairs trading needs cointegration rather than correlation, and how to turn a spread's AR(1) coefficient into a half-life. This lesson is the econometrics underneath: why regressions between price levels lie, how a unit-root test works, how to run and interpret Engle–Granger correctly, what an error-correction model says about who does the adjusting, and how the hedge ratio can go wrong.
Spurious regression
Regress one random walk on another, independent random walk and the output looks like a discovery. Simulating pairs of independent Gaussian random walks and running OLS of one on the other:
| Sample length | Share of regressions with | Median | | --- | --- | --- | | 100 | about 76% | about 0.17 | | 500 | about 89% | about 0.17 |
A valid 5% test would reject 5% of the time. Worse, the rejection rate rises with the sample: more data makes you more confident in a relationship that does not exist. The reason is that the residual of the regression is itself a random walk, so the OLS standard errors (which assume stationary errors) are wildly too small. Telltale signs: a respectable with a Durbin–Watson statistic near zero, and residuals that wander rather than cross zero often.
The rule: never draw conclusions from a regression of non-stationary levels unless the residual is stationary. If it is, the series are cointegrated and the regression is meaningful; if not, difference the data.
Unit roots and the ADF test
The augmented Dickey–Fuller regression is
with (unit root, ) against (stationary, ). The lagged differences soak up short-run autocorrelation so that is white noise.
The t-statistic on does not have a t or normal distribution under the null, because the regressor is non-stationary. Its distribution (Dickey–Fuller) is shifted left: with a constant, the 5% critical value is about , against for a one-sided normal test. Including a trend shifts it further (about ).
Two practical facts:
- Low power. A spread with (half-life about 34 days) is very hard to distinguish from with a year of daily data. Failing to reject a unit root is weak evidence of one.
- Reverse-null tests. KPSS takes stationarity as the null. Agreement between ADF and KPSS is more convincing than either alone.
Engle–Granger two-step
- Regress by OLS (in log prices for pairs).
- Run an ADF test on the residuals , using Engle–Granger critical values, not the ADF table.
Why different critical values? OLS chooses to make the residual variance as small as possible, which also makes the residuals look as stationary as possible. Even when there is no cointegration, the fitted residual looks more mean-reverting than a raw random walk, so the bar must be higher. For two series with a constant, the 5% critical value is about (and about at 1%).
A further property: if the series are cointegrated, is super-consistent: it converges at rate rather than . It can still have noticeable finite-sample bias, and its usual t-statistics are not valid for inference.
Worked example
running Engle–Granger
Over 500 days, OLS of on gives . The ADF regression on the residuals (constant, no extra lags needed) gives with standard error on the coefficient. Is the pair cointegrated at 5%? What is the spread's half-life? What would go wrong if you used the normal critical value?
Show solutionHide solution
The test statistic is . Compare with the Engle–Granger 5% value of about : is further left, so reject the unit root and treat the pair as cointegrated.
The implied AR(1) coefficient is , so the half-life is days.
Had the statistic been instead, a normal one-sided test () and the plain ADF table () would both call the pair cointegrated, while the Engle–Granger value () would not. Only the Engle–Granger value accounts for having been fitted; the other two accept far too many pairs.
Error correction: who does the adjusting
The Granger representation theorem says that cointegrated series have an error-correction form. With spread (demeaned):
where the dots are lagged differences. The 's are adjustment speeds. When the spread is wide (, rich), correction needs ( falls) and/or ( rises). At least one must be non-zero, otherwise nothing pulls the series together.
Subtracting times the second equation from the first:
The relative sizes of and tell you which leg moves to close the gap. That matters for execution: if the "follower" does all the adjusting, the "leader" is where price discovery happens, and its quote moves first.
Worked example
reading an error-correction model
With , an estimated error-correction model gives and (daily). What is the spread's AR(1) coefficient and half-life, and which leg does more of the adjusting?
Show solutionHide solution
. Half-life days.
Of the daily correction of per unit of spread, comes from A falling and from B rising, so A does a little more of the adjusting. Both coefficients have the right sign. If had been insignificant, B would be "weakly exogenous": the spread would close only through A, and you could think of B as the anchor.
Estimating the hedge ratio
The Engle–Granger regression is not symmetric. For level series with standard deviations and correlation :
They agree only if . With , and over the sample, regressing A on B gives while inverting the B-on-A slope gives : an 8% difference in the hedge. The test result can also differ with the direction. Options:
- Run both directions and require both to pass (conservative).
- Use total least squares (orthogonal regression), which treats the two series symmetrically, though it depends on their scaling.
- Use Johansen, a system method that is direction-free and handles more than two assets.
- Let drift with a rolling window or a Kalman filter, accepting more noise for adaptivity.
From to positions. In log prices, a small move in the spread is , so the hedge is in dollars: long 1 dollar of A against short dollars of B. In price levels, is a share ratio instead. Mixing the two is a common bug.
Engle–Granger in code
import numpy as np
import statsmodels.api as sm
from statsmodels.tsa.stattools import coint
rng = np.random.default_rng(7)
n = 1000
b = np.cumsum(rng.normal(0, 0.01, n)) # log price of B: a random walk
u = np.zeros(n) # stationary spread, phi = 0.9
for t in range(1, n):
u[t] = 0.9 * u[t - 1] + rng.normal(0, 0.005)
a = 0.1 + 1.2 * b + u # log price of A
# Step 1: estimate the hedge ratio by OLS of A on B
fit = sm.OLS(a, sm.add_constant(b)).fit()
beta = fit.params[1]
resid = a - fit.params[0] - beta * b
phi = np.polyfit(resid[:-1], resid[1:], 1)[0]
print(f"beta={beta:.3f} spread AR(1) phi={phi:.3f}")
# Step 2: unit-root test on the residuals with Engle-Granger critical
# values (coint runs both steps), not the plain ADF table.
eg_stat, eg_p, eg_crit = coint(a, b, maxlag=1, autolag=None)
print(f"EG stat={eg_stat:.2f} 5% crit={eg_crit[1]:.2f} p={eg_p:.1e}")
Output:
beta=1.196 spread AR(1) phi=0.909
EG stat=-6.75 5% crit=-3.34 p=3.3e-08
The hedge ratio is recovered closely and the statistic is far beyond the critical value. Real pairs are rarely this clean.
Pitfalls
- Multiple testing. Screening every pair in a universe produces false positives by the hundred. Require an economic link before testing and confirm out of sample.
- In-sample hedge ratios. Backtesting a spread built with a estimated on the whole sample is look-ahead bias, and it flatters the spread's stationarity. Estimate on past data only.
- Breaks. A cointegrating relation can end (a merger, a change of index membership, a new business line). Low ADF power cuts both ways: a broken relation can keep passing for months.
- Lag choice and deterministic terms. Too few ADF lags leaves autocorrelation in the errors; including or omitting a trend changes the critical values. Decide the specification before looking at the result.
- Cointegration is not tradability. A stationary spread with a 200-day half-life or a volatility below transaction costs is statistically real and economically useless.
Knowledge check
Why does the Engle–Granger residual test use critical values more negative than the ordinary ADF table?
Knowledge check
You run a 5% Engle–Granger test on every pair among 100 stocks, none of which is truly cointegrated. Roughly how many pairs pass?
Knowledge check
With and spread , an error-correction model gives and . What does it imply?
Key takeaways
- Regressing one random walk on another gives "significant" results most of the time, and more so with more data; only a stationary residual makes a levels regression meaningful.
- ADF tests in against non-standard critical values (about at 5% with a constant), and has low power near a unit root.
- Engle–Granger: OLS in levels, then a residual unit-root test with stricter critical values (about at 5% for two series).
- Error correction: ; the adjustment speeds tell you which leg closes the gap.
- The OLS hedge ratio depends on the direction of the regression; consider both directions, Johansen or adaptive estimates, and never use full-sample in a backtest.
Practice problems
Finished reading?
Answer the 3 knowledge checks to complete this lesson (0 done).