Quant Memo
Advanced

The Johansen Cointegration Test

A test for how many long-run equilibrium relationships exist among a group of price series, letting a quant find and rank multiple cointegrating pairs or baskets at once rather than testing one pair at a time.

Prerequisites: The Vector Error Correction Model, The Engle-Granger Two-Step Procedure

Suppose you're not looking at two stocks but ten related ones — say a basket of gold miners — and you suspect several of them drift together in long-run lockstep even though each one wanders individually. Testing every pair separately (45 pairs from 10 stocks) is slow, and pairwise tests can miss relationships that only show up when three or more series move together as a group. The Johansen test looks at the whole basket at once and answers two questions simultaneously: how many independent long-run equilibrium relationships exist among these series, and what do they look like.

An analogy: dogs on leashes

Picture several dogs on leashes held by walkers who wander around a park. Each dog's own position looks like a random walk — no obvious destination. But if some dogs are tied to the same walker (or to each other), their positions can't drift arbitrarily far apart; a leash pulls them back into a stable relative arrangement. The number of leashes in the group is not obvious from watching any one dog — you have to look at the whole group's joint motion to count them. Cointegration works the same way: individual price series look non-stationary (like the dogs' raw positions), but leashes (cointegrating relationships) tie certain linear combinations of them into stationary, mean-reverting behavior. The Johansen test counts the leashes.

The test, one piece at a time

Start from a vector autoregression (VAR) written in error-correction form for a vector of nn price series yty_t:

Δyt=Πyt1+i=1p1ΓiΔyti+εt,\Delta y_t = \Pi y_{t-1} + \sum_{i=1}^{p-1} \Gamma_i \Delta y_{t-i} + \varepsilon_t,

where Δyt\Delta y_t is the vector of period-to-period changes, yt1y_{t-1} is last period's levels, and Π\Pi is a matrix that captures any long-run pull back toward equilibrium. In words: today's change in prices depends partly on how far last period's levels sat from equilibrium (captured by Πyt1\Pi y_{t-1}), plus some short-run momentum terms, plus noise. The entire question of cointegration reduces to the rank of Π\Pi — call it rr. If r=0r = 0, there's no equilibrium pull at all (the series are just separately non-stationary, no leashes). If r=nr = n (full rank), every series is already stationary on its own. Anything in between, 0<r<n0 < r < n, means there are exactly rr independent cointegrating relationships — rr leashes — among the nn series. Johansen's method estimates Π\Pi and factors it as Π=αβ\Pi = \alpha \beta', where β\beta (the cointegrating vectors) tells you which linear combinations of prices are stationary, and α\alpha (adjustment speeds) tells you how fast each series corrects when the combination drifts from equilibrium. The test itself — the trace test — checks, starting from r=0r=0 upward, whether adding one more relationship significantly improves the fit, stopping at the first rr that isn't rejected.

Worked example 1: three ETFs by hand (conceptual)

Suppose you run Johansen on three energy ETFs and get eigenvalues (roughly, "strength of pull") λ1=0.15\lambda_1 = 0.15, λ2=0.04\lambda_2 = 0.04, λ3=0.01\lambda_3 = 0.01 from the estimation, with trace statistics of 42.3 (testing r=0r=0), 11.7 (testing r1r \le 1), and 2.1 (testing r2r \le 2). Comparing each to critical values (roughly 29.8, 15.5, 3.8 at 5%): 42.3 > 29.8 rejects r=0r=0 (there's at least one relationship); 11.7 < 15.5 fails to reject r1r \le 1, so we stop there. Conclusion: r=1r = 1 — exactly one cointegrating relationship ties the three ETFs together, meaning one specific weighted combination of the three prices is mean-reverting even though each ETF individually is not.

Worked example 2: reading the cointegrating vector

Suppose the estimated cointegrating vector for those three ETFs (normalized on the first) is β=(1,0.8,0.3)\beta = (1, -0.8, -0.3). This means the combination

zt=P1,t0.8P2,t0.3P3,tz_t = P_{1,t} - 0.8\, P_{2,t} - 0.3\, P_{3,t}

is stationary — it oscillates around a constant mean rather than drifting. In plain English: buying one share of ETF 1, shorting 0.8 shares of ETF 2, and shorting 0.3 shares of ETF 3 creates a synthetic spread that mean-reverts, even though buying any single ETF alone would not. If $100 of capital is allocated so ztz_t currently sits two standard deviations above its historical mean of $0.50, a mean-reversion trader would short this basket, expecting ztz_t to pull back toward $0.50.

Individual series (non-stationary) Cointegrating combination z_t mean
Each individual price wanders without bound, but the specific weighted combination β identified by Johansen oscillates around a stable mean — the leash holding the group together.
statistic 42.3 r=0 11.7 r≤1 2.1 r≤2
The trace statistic clears the critical value (dashed line) at r=0 but not at r≤1, so the test stops and concludes exactly one cointegrating relationship.

What this means in practice

The Johansen test is the standard tool for building statistical-arbitrage baskets from more than two instruments — index-versus-constituents trades, commodity curve trades, or currency baskets — because it finds cointegrating relationships jointly rather than pair by pair, and it hands back both the hedge weights (β\beta) and the speed of mean reversion (α\alpha) in one estimation. It also underlies the vector error correction model used to forecast how a basket corrects after a shock. The output feeds directly into spread construction: see Spread Construction and Hedge Ratios.

Johansen's test finds the rank rr of long-run equilibrium relationships hiding inside a group of non-stationary series, and hands back both the cointegrating combinations (β\beta) and their correction speeds (α\alpha) — turning a basket of individually unpredictable prices into one or more tradeable, mean-reverting spreads.

A common mistake is treating a statistically significant cointegrating relationship as permanently stable. The rank rr and the vector β\beta are estimated on a historical sample; if the underlying economic link between the series breaks (a merger falls through, a subsidy ends, one company changes its business), the "leash" can snap with no warning in the test statistic itself. Always re-test on rolling windows and treat any Johansen-derived basket as conditional on the relationship continuing to hold, not as a law of nature.

Related concepts

Practice in interviews

Further reading

  • Johansen, Likelihood-Based Inference in Cointegrated Vector Autoregressive Models, ch. 6
  • Hamilton, Time Series Analysis, ch. 20
ShareTwitterLinkedIn