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 price series :
where is the vector of period-to-period changes, is last period's levels, and 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 ), plus some short-run momentum terms, plus noise. The entire question of cointegration reduces to the rank of — call it . If , there's no equilibrium pull at all (the series are just separately non-stationary, no leashes). If (full rank), every series is already stationary on its own. Anything in between, , means there are exactly independent cointegrating relationships — leashes — among the series. Johansen's method estimates and factors it as , where (the cointegrating vectors) tells you which linear combinations of prices are stationary, and (adjustment speeds) tells you how fast each series corrects when the combination drifts from equilibrium. The test itself — the trace test — checks, starting from upward, whether adding one more relationship significantly improves the fit, stopping at the first 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") , , from the estimation, with trace statistics of 42.3 (testing ), 11.7 (testing ), and 2.1 (testing ). Comparing each to critical values (roughly 29.8, 15.5, 3.8 at 5%): 42.3 > 29.8 rejects (there's at least one relationship); 11.7 < 15.5 fails to reject , so we stop there. Conclusion: — 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 . This means the combination
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 currently sits two standard deviations above its historical mean of $0.50, a mean-reversion trader would short this basket, expecting to pull back toward $0.50.
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 () and the speed of mean reversion () 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 of long-run equilibrium relationships hiding inside a group of non-stationary series, and hands back both the cointegrating combinations () and their correction speeds () — 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 and the vector 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