Strategy Archetypes · Statistical Arbitrage · Module 8

Pairs Trading: Cointegration, Hedge Ratio, and Z-Score Rules

Pairs trading is the two-instrument implementation of statistical arbitrage. It trades the mean-reverting spread between two cointegrated instruments — one long, one short — with the goal of being approximately market-neutral. The strategy is not about predicting direction; it is about predicting that a spread that has deviated from its historical mean will return to it.

Pairs trading is a child of stat arb:

Step 1 — Finding and Testing Pairs

Three approaches, in order of reliability:

  1. Domain knowledge first. Instruments with shared economics — two oil majors, two gold ETFs, commodity producer and commodity price, dual-listed shares — have a fundamental reason to be cointegrated. Domain knowledge narrows the universe to plausible pairs before statistical testing.
  2. Cointegration test. Use the Engle-Granger two-step test (statsmodels.tsa.stattools.coint) on the candidate pair. If the p-value is below 0.05, the null of no cointegration is rejected. For baskets of three or more, use the Johansen test.
  3. Half-life filter. Even a cointegrated pair with a 200-day half-life is not tradeable at daily frequency after costs. Filter pairs by estimated half-life — typically require half-life below 20–30 days for a daily strategy.

Multiple testing hazard: Testing all N*(N-1)/2 pairs in a universe and selecting the top-k by p-value inflates the false positive rate. With 100 instruments, 4,950 pairs generate approximately 248 cointegration false positives at p < 0.05 by chance alone. Use a Bonferroni correction or holdout validation on independent data to distinguish genuine cointegration from sampling coincidence.

Step 2 — Estimating the Hedge Ratio

The hedge ratio β defines how many units of B to trade against one unit of A to construct the spread:

S(t) = P_A(t) − β × P_B(t)

Estimation methods:

Method Description Best for
OLS regression Regress P_A on P_B over formation window; β = OLS coefficient Stable pairs; simple implementation
Kalman filter Dynamically updates β bar by bar as new prices arrive Pairs where relationship drifts slowly; reduces lag
Johansen eigenvector Eigenvector of the Johansen test defines the hedge weights Baskets of 3+ instruments; symmetric weighting

Step 3 — Z-Score Signal and Entry/Exit Rules

With the spread S(t) constructed, compute the rolling z-score over window L (set L ≈ 2 × half-life):

z(t) = (S(t) − mean(S[t-L:t])) / std(S[t-L:t])

Condition Signal Action
z > +2 A expensive vs B Short A, long B (scaled by β)
z < −2 A cheap vs B Long A, short B (scaled by β)
|z| < 0.5 Reversion complete Exit position
|z| > 3.5 Spread extreme — regime risk Stop-loss: exit to cap loss

Key Risks

1. Cointegration breakdown (the primary risk)

The cointegrating relationship is not permanent. A merger, acquisition, regulatory change, or fundamental divergence can cause the spread to permanently reprice. Once the relationship breaks, the spread will not revert. The strategy will keep adding to a losing position if there is no stop-loss. Monitor the rolling cointegration test p-value over time; if it rises above 0.10–0.20, the relationship may be weakening.

2. Transaction cost drag

Every pairs trade involves two legs. Transaction costs (commission + spread + market impact) are higher than single-leg strategies. A short half-life that looks profitable on gross P&L may be unprofitable after costs. Model costs explicitly before sizing.

3. Market-neutral assumption

The hedge ratio β makes the spread approximately market-neutral, not perfectly so. During market crashes, correlations spike and both legs may move adversely simultaneously. The position is not dollar-neutral unless specifically sized that way; β measures the price relationship, not the dollar exposure.


Frequently Asked Questions

How do you find pairs for pairs trading?
Three methods: (1) Domain knowledge — pairs within the same sector, business line, or with shared cost structure (two oil majors, two airline stocks) are natural candidates. Sector membership narrows the universe before statistical testing. (2) Statistical screening — test all combinations in a universe for cointegration using the Engle-Granger two-step test (statsmodels.tsa.stattools.coint). Filter by p-value below 0.05. Beware: testing all N*(N-1)/2 pairs in a universe and selecting the top-k is a multiple testing problem that inflates the false positive rate. (3) Fundamental linkage — ETFs and their component stocks, commodity producers and commodity prices, dual-listed shares of the same company. Fundamental linkage provides economic justification for cointegration that pure statistical screening cannot.
How is the hedge ratio estimated in pairs trading?
The hedge ratio beta is the coefficient from OLS regression of price A on price B: P_A = alpha + beta * P_B + epsilon. Beta represents the number of units of B to short (or long) for each unit of A to achieve market neutrality on the spread. The spread S = P_A - beta * P_B should be stationary if the pair is cointegrated. Two refinements: (1) Kalman filter hedge ratio — updates beta dynamically bar by bar, tracking a time-varying relationship better than a fixed OLS estimate over a rolling window. (2) Johansen method — for basket arb with three or more instruments, the Johansen test yields eigenvectors that define the stationary portfolios.
What is the risk of pairs trading?
The primary risk is cointegration breakdown: the historical relationship between the pair changes permanently, and the spread diverges without reverting. This can happen because of a merger, acquisition, regulatory change, earnings divergence, or sector rotation. A second risk is transaction cost drag: pairs trading involves two legs per trade, so costs are higher than single-leg strategies. At tight spreads, costs can eliminate the profitability of a short-half-life strategy. A third risk is correlated drawdowns: during market crises, correlations spike and pairs that appeared market-neutral may both move in the same direction simultaneously, generating losses on both legs. Stop-losses based on z-score extremes (e.g., exit at |z| > 3.5) are the standard defense against runaway spread divergence.

Drill pairs trading mechanics, cointegration testing, and stat arb trade-offs with AlgoDrill's spaced-repetition flashcards.

Start Strategy Flashcards →   Statistical Arbitrage Overview →