Skip to content
LeetQuant
QR05 Time Series and Econometrics

QR05 · Time Series and Econometrics · Lesson 3 of 5

Cointegration

Spurious regression between random walks, unit roots and the ADF test, the Engle–Granger two-step method with its own critical values, error-correction dynamics, hedge-ratio estimation and the usual pitfalls.

18 min

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 ∣t∣>1.96|t| > 1.96 | Median R2R^2 | | --- | --- | --- | | 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 R2R^2 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

Δyt=α+γ yt−1+∑i=1kδi Δyt−i+et,\Delta y_t = \alpha + \gamma\,y_{t-1} + \sum_{i=1}^{k}\delta_i\,\Delta y_{t-i} + e_t ,

with H0:γ=0H_0: \gamma = 0 (unit root, ϕ=1\phi = 1) against H1:γ<0H_1: \gamma < 0 (stationary, ϕ=1+γ<1\phi = 1 + \gamma < 1). The lagged differences soak up short-run autocorrelation so that ete_t is white noise.

The t-statistic on γ\gamma does not have a t or normal distribution under the null, because the regressor yt−1y_{t-1} is non-stationary. Its distribution (Dickey–Fuller) is shifted left: with a constant, the 5% critical value is about −2.86-2.86, against −1.645-1.645 for a one-sided normal test. Including a trend shifts it further (about −3.41-3.41).

Two practical facts:

  • Low power. A spread with ϕ=0.98\phi = 0.98 (half-life about 34 days) is very hard to distinguish from ϕ=1\phi = 1 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

  1. Regress yt=a+βxt+uty_t = a + \beta x_t + u_t by OLS (in log prices for pairs).
  2. Run an ADF test on the residuals u^t\hat u_t, using Engle–Granger critical values, not the ADF table.

Why different critical values? OLS chooses β\beta 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 −3.34-3.34 (and about −3.90-3.90 at 1%).

A further property: if the series are cointegrated, β^\hat\beta is super-consistent: it converges at rate 1/n1/n rather than 1/n1/\sqrt n. 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 ln⁡PA\ln P^A on ln⁡PB\ln P^B gives β^=1.2\hat\beta = 1.2. The ADF regression on the residuals (constant, no extra lags needed) gives Δu^t=−0.08 u^t−1+et\Delta\hat u_t = -0.08\,\hat u_{t-1} + e_t with standard error 0.020.02 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 solution

The test statistic is −0.08/0.02=−4.0-0.08/0.02 = -4.0. Compare with the Engle–Granger 5% value of about −3.34-3.34: −4.0-4.0 is further left, so reject the unit root and treat the pair as cointegrated.

The implied AR(1) coefficient is ϕ=1−0.08=0.92\phi = 1 - 0.08 = 0.92, so the half-life is ln⁡2/(−ln⁡0.92)≈8.3\ln 2 / (-\ln 0.92) \approx 8.3 days.

Had the statistic been −3.0-3.0 instead, a normal one-sided test (−1.645-1.645) and the plain ADF table (−2.86-2.86) would both call the pair cointegrated, while the Engle–Granger value (−3.34-3.34) would not. Only the Engle–Granger value accounts for β\beta 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 st=yt−βxts_t = y_t - \beta x_t (demeaned):

Δyt=αy st−1+⋯+εty,Δxt=αx st−1+⋯+εtx,\Delta y_t = \alpha_y\,s_{t-1} + \dots + \varepsilon^y_t, \qquad \Delta x_t = \alpha_x\,s_{t-1} + \dots + \varepsilon^x_t ,

where the dots are lagged differences. The α\alpha's are adjustment speeds. When the spread is wide (st−1>0s_{t-1} > 0, yy rich), correction needs αy<0\alpha_y < 0 (yy falls) and/or αx>0\alpha_x > 0 (xx rises). At least one must be non-zero, otherwise nothing pulls the series together.

Subtracting β\beta times the second equation from the first:

Δst=(αy−βαx) st−1+…,ϕs=1+αy−βαx.\Delta s_t = (\alpha_y - \beta\alpha_x)\,s_{t-1} + \dots, \qquad \phi_s = 1 + \alpha_y - \beta\alpha_x .

The relative sizes of ∣αy∣|\alpha_y| and β∣αx∣\beta|\alpha_x| 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 β=1.2\beta = 1.2, an estimated error-correction model gives αA=−0.05\alpha_A = -0.05 and αB=0.03\alpha_B = 0.03 (daily). What is the spread's AR(1) coefficient and half-life, and which leg does more of the adjusting?

Show solution

ϕs=1−0.05−1.2×0.03=1−0.05−0.036=0.914\phi_s = 1 - 0.05 - 1.2 \times 0.03 = 1 - 0.05 - 0.036 = 0.914. Half-life =ln⁡2/(−ln⁡0.914)≈7.7= \ln 2 / (-\ln 0.914) \approx 7.7 days.

Of the daily correction of 0.0860.086 per unit of spread, 0.050.05 comes from A falling and 0.0360.036 from B rising, so A does a little more of the adjusting. Both coefficients have the right sign. If αB\alpha_B 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 σA,σB\sigma_A, \sigma_B and correlation ρ\rho:

β^A∣B=ρ σAσB,1β^B∣A=1ρ σAσB.\hat\beta_{A \mid B} = \rho\,\frac{\sigma_A}{\sigma_B}, \qquad \frac{1}{\hat\beta_{B \mid A}} = \frac{1}{\rho}\,\frac{\sigma_A}{\sigma_B} .

They agree only if ∣ρ∣=1|\rho| = 1. With σA=0.30\sigma_A = 0.30, σB=0.25\sigma_B = 0.25 and ρ=0.96\rho = 0.96 over the sample, regressing A on B gives 1.1521.152 while inverting the B-on-A slope gives 1/0.8=1.251/0.8 = 1.25: 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 β\beta drift with a rolling window or a Kalman filter, accepting more noise for adaptivity.

From β\beta to positions. In log prices, a small move in the spread is rA−βrBr^A - \beta r^B, so the hedge is in dollars: long 1 dollar of A against short β\beta dollars of B. In price levels, β\beta 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 β\beta estimated on the whole sample is look-ahead bias, and it flatters the spread's stationarity. Estimate β\beta 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 β=1\beta = 1 and spread s=A−Bs = A - B, an error-correction model gives αA=+0.02\alpha_A = +0.02 and αB=+0.04\alpha_B = +0.04. 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 γ=0\gamma = 0 in Δyt=α+γyt−1+…\Delta y_t = \alpha + \gamma y_{t-1} + \dots against non-standard critical values (about −2.86-2.86 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 −3.34-3.34 at 5% for two series).
  • Error correction: ϕs=1+αy−βαx\phi_s = 1 + \alpha_y - \beta\alpha_x; 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 β\beta in a backtest.

Practice problems

Finished reading?

Answer the 3 knowledge checks to complete this lesson (0 done).