Skip to main content
aifinhub
Backtesting & Validation Guide

How to Test a Pair for Cointegration

Pairs trading rests on a strong claim: that two prices move together so tightly that their spread is mean-reverting. Cointegration is the statistical test of that claim. Correlation is not enough, because correlated series can still drift apart forever. The Engle-Granger procedure, the half-life that tells you whether the mean reversion is fast enough to trade, and the out-of-sample check that keeps you honest are all covered in the steps below.

By AI Fin Hub Research · AI Fin Hub Team

On This Page

Before You Start

Set up the inputs that make the next steps easier

Two price series of the same length and frequency for the instruments in the pair.
Enough history to estimate the relationship stably and to hold out an out-of-sample period.
A reason to expect the pair to be linked, since data-mined pairs cointegrate by chance.

Guide Steps

Move through it in order

Each step focuses on one decision so you can keep momentum without losing the thread.

  1. 1

    Start from an economic reason, not a screen

    Before testing, have a reason the two instruments should be linked: same sector, same supply chain, a hedging relationship, or an index-and-constituent tie. Screening thousands of pairs for cointegration guarantees false positives, because some will pass by chance just like any large multiple-comparison search. A prior reason constrains the search and makes a passing test meaningful rather than a coincidence you will trade until it breaks.

    If you screened many pairs, the ones that pass are partly selection luck. Treat a data-mined cointegration result with the same suspicion as any over-searched backtest.

  2. 2

    Estimate the hedge ratio

    Regress one price series on the other using ordinary least squares. The slope coefficient is the hedge ratio: how many units of the second instrument offset one unit of the first to form the spread. This ratio defines the spread you will test and trade. Getting it right matters, because a mis-estimated hedge ratio produces a spread that is not actually balanced and will not mean-revert the way the test suggests.

    The hedge ratio can drift over time. Re-estimate it periodically rather than fixing it once, since a stale ratio quietly unbalances the spread.

    Use The ToolPlaygrounds

    Pair Trading Cointegration Tester

    Paste two price series. Engle-Granger cointegration test: OLS hedge ratio, Augmented Dickey-Fuller on residuals, Ornstein-Uhlenbeck half-life, z-score.

    ToolOpen ->
  3. 3

    Run an ADF test on the residual

    Take the residual of the regression, which is the spread, and run an Augmented Dickey-Fuller test on it. The ADF test checks whether the spread is stationary, meaning it reverts to a stable mean rather than wandering. A low p-value rejects the null of a non-stationary, drifting spread, which is the evidence that the pair is cointegrated. A high p-value means the spread can wander indefinitely and the pair is not safe to trade as a mean-reverting spread.

    Cointegration, not correlation, is the property that matters. Two highly correlated series can still have a non-stationary spread that drifts apart and never comes back.

    Use The ToolPlaygrounds

    Cointegration Half-Life Solver

    Engle-Granger residual ADF + Ornstein-Uhlenbeck half-life from any two price/return series. Hedge ratio, p-value, spread chart. Browser-only.

    ToolOpen ->
  4. 4

    Measure the mean-reversion half-life

    A stationary spread is necessary but not sufficient; it also has to revert fast enough to trade. Fit an Ornstein-Uhlenbeck process to the spread and compute the half-life, the expected time for a deviation to decay halfway back to the mean. A half-life of a few days suits a short-horizon strategy; a half-life of many months means your capital is tied up too long for the spread to be useful. The half-life turns a yes-or-no test into a tradeability assessment.

    Match the half-life to your holding horizon and capital cost. A statistically perfect spread with a six-month half-life is not tradeable for a strategy that needs to turn capital over weekly.

  5. 5

    Validate out of sample and monitor for breaks

    Cointegration relationships break, often when a structural change hits one of the instruments. Confirm the relationship holds on data after the period you estimated it on, and once live, monitor the spread for signs the cointegration has broken: a spread that stops reverting and trends away is the warning. A pair that cointegrated historically but has broken is a trap that looks like an opportunity. Build the break check in from the start.

    Have a rule for when a pair has broken and you exit, decided before you enter. The most dangerous pair is one that used to cointegrate and quietly stopped.

Common Mistakes

The misses that undo good inputs

1

Trading correlation instead of cointegration

Correlated series can still have a spread that drifts apart forever. Only cointegration guarantees a mean-reverting spread, and trading correlation alone risks holding a divergence that never reverts.

2

Screening many pairs and trading the best

Testing thousands of pairs guarantees some pass by chance. Without an economic reason, a passing cointegration test from a large screen is largely selection luck and tends to break soon after you start trading it.

3

Ignoring the half-life

A stationary spread that reverts over many months ties up capital far too long to be tradeable for a short-horizon strategy. Cointegration without a workable half-life is a statistical curiosity, not a trade.

Try These Tools

Run the numbers next

FAQ

Questions people ask next

The short answers readers usually want after the first pass.

Correlation measures whether two series move together in the short run, but two correlated series can still drift apart without bound over time. Cointegration is the stronger property that a particular linear combination of the two series, the spread, is stationary and mean-reverting. Pairs trading needs cointegration, not just correlation, because the strategy depends on the spread reliably returning to its mean rather than wandering off permanently.

Sources & References

Related Content

Keep the topic connected

Planning estimates only — not financial, tax, or investment advice.