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.
On This Page
Before You Start
Set up the inputs that make the next steps easier
Guide Steps
Move through it in order
Each step focuses on one decision so you can keep momentum without losing the thread.
- 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
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 ToolPlaygroundsPair 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
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 ToolPlaygroundsCointegration 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
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
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
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.
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.
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
Correlation Matrix Visualizer
Paste a multi-asset returns CSV. See the Pearson correlation heatmap, condition number, average absolute correlation, and eigenvalue concentration.
Execution Simulator
Model realistic order fills — square-root market impact, linear temporary impact, latency jitter, partial fills, and queue position. See the real cost.
FAQ
Questions people ask next
The short answers readers usually want after the first pass.
Sources & References
- Co-Integration and Error Correction: Representation, Estimation, and Testing — Engle and Granger, Econometrica (1987)
- Pairs Trading: Performance of a Relative-Value Arbitrage Rule — Gatev, Goetzmann, Rouwenhorst, Review of Financial Studies (2006)
Related Content
Keep the topic connected
Monte Carlo Simulation
Monte Carlo simulation in trading: when it's the right tool, when it's overkill, and the seed-discipline gotcha that ruins most published examples.
Look-Ahead Bias
Look-ahead bias: when a backtest accidentally uses data the strategy wouldn't have had at decision time. The most common variants and how to catch them.
Volatility
Volatility as the standard deviation of returns: realized vs implied, the annualization gotcha, and why volatility-of-volatility matters.
Overfitting
Overfitting in trading-strategy backtests: how multiple-testing inflates apparent edges and the diagnostics that catch it.