Two prices that stay together
Prices wander: they behave like random walks, so each is non-stationary. Two wandering series are cointegrated when some combination of them does not wander, the spread st=yt−βxt keeps returning to a mean. That is the idea behind pairs trading. The Engle–Granger test has two steps. First regress y on x by least squares to get the hedge ratio β^ and the spread. Then run an augmented Dickey–Fuller test on the spread: Δst=γst−1+εt, and ask whether γ<0. The t-statistic must be below special critical values, about −3.34 at 5% for two series, which are stricter than the usual ones because the spread was estimated. In statsmodels this is coint(y, x).
st=yt−β^xt,Δst=γst−1+εt,ϕ=1+γ,t1/2=lnϕln0.5(1) A five-day spread by handTake
x=1,2,3,4,5 and
y=3,5,6,9,10. Regressing gives
β^=18/10=1.8, so the spread
y−1.8x is
1.2,1.4,0.6,1.8,1.0 with mean
1.2 and standard deviation
0.447. Today's spread
1.0 has z-score
(1.0−1.2)/0.447=−0.45: it is a bit below normal. If the spread follows
st=0.9st−1+ε, a gap closes by half in
ln0.5/ln0.9=6.58 days. A test regression
Δs=γst−1 with
γ^=−0.1 and standard error
0.04 has
t=−2.5, above the critical
−3.34, so you cannot call the pair cointegrated. On real daily data since 2000 (
6,696 days), regressing one log price on another gives
R2 of
0.85 to
0.93 for pairs such as KO and PEP, XOM and CVX, or HD and LOW, yet the Engle–Granger statistics are
−2.69,
−1.80 and
−3.97, so only HD and LOW pass at 5% (
p=0.008). Even that fragile: each half of the sample alone fails (
t=−1.58 and
−2.63) and the hedge ratio moves from
0.13 to
0.93. The full-sample spread has
ϕ=0.998, a half-life of about
332 days, too slow to trade. For comparison, in
1000 simulated pairs of independent random walks,
85% show a slope with
∣t∣>1.96.
High R-squared is not evidenceTwo wandering prices always look related when you regress one on the other. Only the stationarity of the spread, tested with the Engle–Granger critical values, says the link is real. Check stability across sub-periods before trading it.
- Two steps: regress for the hedge ratio, then test the spread for a unit root with Engle–Granger values.
- The half-life tells you whether a real mean reversion is fast enough to trade.
Lab · what's graded
- The hedge ratio10 pts
- The mean spread10 pts
- A z-score15 pts
- A half-life15 pts
- A Dickey–Fuller statistic15 pts
- Reading the test10 pts
- Passing is not enough25 pts