Sam, Editor-in-Chief
Reviewed by Sam · Last reviewed 2026-04-01
This article synthesizes Engle-Granger and Johansen cointegration testing into a unified pairs trading workflow, connecting the theoretical error correction framework to practical trading parameters including half-life filtering, z-score thresholds, and rolling reestimation protocols.

Cointegration: The Math Behind Pairs Trading

2026-04-01 · 14 min

Cointegration provides the rigorous statistical framework that separates robust pairs trading from naive correlation-based approaches. The Engle-Granger two-step method and Johansen test identify long-run equilibrium relationships between stock prices, while the error correction model and Ornstein-Uhlenbeck half-life determine how quickly trading opportunities resolve.

CointegrationPairs TradingStatistical ArbitrageMean ReversionEngle GrangerJohansen TestError Correction ModelTime Series
Source: Quant Decoded Research

Practical Application for Retail Investors

Before deploying a pairs trading strategy, test candidate pairs for cointegration using both the Engle-Granger and Johansen methods over a 12-24 month formation window. Compute the half-life of mean reversion and filter for pairs with half-lives between 5 and 60 trading days. Use z-score thresholds of 2.0 for entry and 0.0 for exit, with a stop-loss at 3.5 sigma. Reestimate the hedge ratio and retest cointegration every one to three months, discarding pairs that no longer pass.

Key Takeaway

Financial data analysis on screens

Cointegration is the mathematical foundation that separates rigorous pairs trading from naive correlation-based approaches. Two stock prices can have zero correlation over a period yet still be cointegrated, meaning their linear combination reverts to a stable mean. The Engle-Granger two-step method and the Johansen test provide formal statistical tools for identifying these long-run equilibrium relationships. Once a cointegrated pair is found, the error correction model governs how the spread behaves, and the half-life of mean reversion determines how quickly trading opportunities resolve. Pairs trading strategies built on cointegration have a structural advantage over distance-based methods because they test for a genuine economic relationship rather than relying on historical price proximity.

The Drunk and Her Dog

Imagine a woman leaving a bar late at night with her dog on a leash. Both wander somewhat randomly; the woman stumbles along an unpredictable path, and the dog darts from side to side chasing scents. Individually, neither follows a predictable trajectory. But the leash constrains the maximum distance between them. No matter how erratically each one moves, the distance between them remains bounded and tends to revert to the length of the leash.

This is cointegration in a single image. The woman and dog are each non-stationary processes (I(1) series in the language of time series econometrics), meaning their positions individually follow random walks. But the difference between their positions is stationary (I(0)), meaning it fluctuates around a stable mean and reverts when it deviates too far.

This analogy, often attributed to Murray (1994), captures a subtle distinction that many traders miss. Correlation measures how two series move together over short intervals. Cointegration measures whether a long-run equilibrium relationship exists between them. Two stocks can have high correlation but no cointegration (they move together day-to-day but drift apart permanently over time). Conversely, two stocks can have low short-term correlation but strong cointegration (they follow different short-term paths but a linear combination of their prices always reverts to equilibrium).

Stationarity and Integration Order

Before testing for cointegration, it is necessary to understand the concept of integration order. A time series is integrated of order d, written I(d), if it requires d rounds of differencing to become stationary.

Most individual stock prices are I(1). In levels, they follow a random walk with drift. But their first differences (daily returns) are approximately stationary, fluctuating around a mean with constant variance. You cannot profitably trade a single I(1) series on the assumption that it will revert to any particular level, because it has no fixed level to revert to.

Cointegration offers an escape from this problem. If two I(1) series X and Y can be combined as Z = Y - beta * X, and the resulting series Z is I(0), then X and Y are cointegrated with cointegrating vector (1, -beta). The spread Z is the tradeable quantity: it has a fixed mean, and deviations from that mean are temporary.

The Augmented Dickey-Fuller (ADF) test is the standard tool for testing whether a series is stationary. It tests the null hypothesis that the series has a unit root (is I(1)) against the alternative that it is stationary (I(0)). The test regression is:

Delta_Z(t) = alpha + gamma * Z(t-1) + sum of lagged Delta_Z terms + epsilon(t)

If gamma is significantly negative (the test statistic falls below the critical value), we reject the null of a unit root and conclude the series is stationary. Critical values for cointegration residuals differ from standard ADF tables because the residuals are generated from an estimated regression rather than observed directly.

The Engle-Granger Two-Step Method

Engle and Granger (1987), the paper that earned Robert Engle and Clive Granger the 2003 Nobel Prize in Economics, formalized the concept of cointegration and introduced a practical two-step testing procedure.

Step one: estimate the cointegrating regression. Run an ordinary least squares (OLS) regression of one I(1) variable on the other:

Y(t) = alpha + beta * X(t) + epsilon(t)

The residuals from this regression represent the spread: the deviation of Y from its estimated long-run equilibrium relationship with X. If Y and X are cointegrated, these residuals should be stationary.

Step two: test the residuals for stationarity. Apply the ADF test to the estimated residuals. If the test rejects the null of a unit root, the evidence supports cointegration between Y and X. The critical values for this test are more stringent than standard ADF critical values, as tabulated by MacKinnon (1991), because the residuals are estimated rather than observed.

The Engle-Granger method is intuitive and easy to implement, which is why it remains the most common starting point for pairs trading research. However, it has important limitations. It can only detect a single cointegrating relationship between two variables. It requires the researcher to choose which variable is the dependent variable (swapping Y and X can change the conclusion). And the first-step OLS estimator may perform poorly in small samples.

The Johansen Test: A More Powerful Alternative

Johansen (1988) developed a maximum likelihood approach that addresses the limitations of the Engle-Granger method. The Johansen test works within a vector autoregressive (VAR) framework and can simultaneously test for multiple cointegrating relationships among multiple variables.

The key output of the Johansen test is the number of cointegrating vectors (the cointegration rank) among a set of variables. For a pairs trading application with two stocks, the test determines whether zero or one cointegrating relationship exists. The trace statistic and maximum eigenvalue statistic provide two alternative test statistics; both test the null hypothesis of at most r cointegrating relationships against the alternative of more.

The Johansen approach offers several advantages for practitioners. It does not require choosing a dependent variable. It handles multiple time series simultaneously, allowing traders to search for cointegrated baskets (three or more stocks that share an equilibrium). And it provides maximum likelihood estimates of the cointegrating vectors, which are asymptotically more efficient than the Engle-Granger OLS estimates.

For a bivariate system with stocks A and B, a Johansen rank of 1 confirms cointegration and provides the estimated cointegrating vector directly. A rank of 0 means no cointegration exists, and the pair should not be traded as a mean-reverting spread.

The Error Correction Model

Once cointegration is established, the error correction model (ECM) describes how the system adjusts back toward equilibrium when the spread deviates. The ECM, derived directly from the Granger representation theorem in Engle and Granger (1987), takes the form:

Delta_Y(t) = alpha_Y + lambda_Y * Z(t-1) + lagged terms + epsilon_Y(t)

Delta_X(t) = alpha_X + lambda_X * Z(t-1) + lagged terms + epsilon_X(t)

Here Z(t-1) is the lagged spread (error correction term), and the lambda coefficients measure the speed at which each stock adjusts toward the equilibrium. If lambda_Y is negative and significant, it means Y moves back toward the equilibrium when the spread is positive (Y is above equilibrium). If lambda_X is positive and significant, X moves in the opposite direction.

The ECM is valuable for pairs traders because it reveals which stock does the adjusting. In many real pairs, one stock adjusts more quickly than the other. A trader can exploit this asymmetry by placing larger positions in the faster-adjusting stock, or by using the ECM to forecast the direction of the spread over the next several periods.

Half-Life of Mean Reversion

The speed at which a cointegrated spread reverts to its mean determines whether a pairs trade is practically viable. A spread that takes two years to revert is statistically interesting but operationally useless; a spread that reverts in five to fifteen trading days is actionable.

The half-life is derived from the Ornstein-Uhlenbeck (OU) process, the continuous-time analog of the discrete AR(1) process used to model the spread. If the spread Z follows:

Z(t) = phi * Z(t-1) + epsilon(t)

where phi is the autoregressive coefficient (0 < phi < 1 for a stationary process), then the half-life is:

t_half = -ln(2) / ln(phi)

This formula gives the expected number of periods for a deviation from the mean to decay by half. A phi of 0.95 implies a half-life of approximately 13.5 trading days. A phi of 0.99 implies a half-life of approximately 69 trading days.

For practical pairs trading, a half-life between 5 and 60 trading days tends to work best. Below 5 days, the spread reverts too quickly for most execution systems to capture profitably after transaction costs. Above 60 days, the capital is tied up for too long and the risk of the cointegrating relationship breaking down increases.

Pair ExampleADF Statisticp-valueCointegrated?Half-Life (days)Phi
KO / PEP-3.420.011Yes18.20.963
XOM / CVX-3.890.003Yes12.70.947
JPM / BAC-2.150.228No43.10.984
MSFT / AAPL-1.870.347No61.40.989
HD / LOW-3.610.006Yes15.30.956
GLD / GDX-4.120.001Yes8.90.925

Practical Implementation: From Theory to Trading

Building a cointegration-based pairs trading strategy involves a systematic workflow that maps directly from the theory above.

The first stage is candidate identification. Rather than testing all possible stock pairs (which creates a severe multiple comparisons problem), practitioners narrow the universe using economic logic. Stocks in the same industry, with similar business models, exposure to the same commodity inputs, or subject to the same regulatory framework are more likely to share a genuine long-run equilibrium. Coca-Cola and PepsiCo, ExxonMobil and Chevron, Home Depot and Lowe's are classic examples. Starting from economic fundamentals reduces the risk that a statistically significant cointegration result is a spurious artifact of data mining.

The second stage is cointegration testing over a rolling formation window, typically 12 to 24 months of daily data. Both the Engle-Granger and Johansen tests are applied, with pairs kept only if both methods confirm cointegration at the 5% significance level. The cointegrating vector (the hedge ratio beta) is estimated from this window.

The third stage is spread construction and normalization. The spread Z(t) = Y(t) - beta * X(t) is computed and standardized to z-scores using the formation-period mean and standard deviation. This normalization allows universal entry and exit thresholds to be applied across different pairs.

The fourth stage is signal generation. The standard approach opens a position when the z-score exceeds a threshold (typically 2.0 standard deviations) and closes when it reverts to zero or crosses a stop-loss threshold (typically 3.0 to 4.0 standard deviations). The direction is determined by the sign of the z-score: a positive z-score means Y is expensive relative to X, so the trader shorts Y and buys X; a negative z-score triggers the opposite trade.

ParameterConservativeModerateAggressive
Formation window24 months18 months12 months
Entry threshold (sigma)2.52.01.5
Exit threshold (sigma)0.50.00.0
Stop-loss (sigma)4.03.53.0
Max holding period60 days40 days20 days
Half-life filter5-40 days5-50 days5-60 days

Empirical Evidence: Does It Work?

Gatev, Goetzmann, and Rouwenhorst (2006), the most cited empirical study of pairs trading, documented that a simple distance-based pairs trading strategy earned approximately 11% annualized excess returns over 1962 to 2002 in U.S. equities. The strategy was market-neutral and required no fundamental analysis; it was purely statistical.

However, subsequent research has told a more nuanced story. Do and Faff (2010) extended the Gatev sample through 2008 and found that profits had declined substantially, with much of the edge disappearing after accounting for realistic transaction costs. By the 2010s, the simple distance-based approach produced near-zero or negative returns after costs.

Avellaneda and Lee (2010) proposed a more sophisticated framework using principal component analysis and the Ornstein-Uhlenbeck process. Their approach, which is closer to the cointegration methodology described here, achieved Sharpe ratios above 1.0 in U.S. equities by systematically trading residuals from a factor model. The key insight was that incorporating the mean-reversion speed (the OU parameter) into the trading signal improved performance significantly compared to simple distance methods.

StudyPeriodMethodAnnualized ReturnSharpe Ratio
Gatev et al. (2006)1962-2002Distance~11%~0.75
Do & Faff (2010)1962-2009Distance~4% (declining)~0.35
Avellaneda & Lee (2010)1997-2007OU / Factor~8-15%~1.0-1.5
Krauss (2017) surveyVariousVariousDeclining trendStrategy-dependent

The academic consensus is clear: cointegration-based and mean-reversion-speed-aware methods have significantly outperformed simple distance methods, particularly in more recent periods when markets have become more efficient and competition among quantitative traders has intensified.

Where Cointegration Breaks Down

Cointegration is a statistical relationship, not a law of nature. It can and does break down. A structural change in one company's business model, a merger or acquisition, a regulatory shift, or a permanent change in competitive dynamics can destroy the equilibrium that held historically. When the leash between the drunk and her dog snaps, the spread can diverge permanently, and a pairs trade based on mean reversion will accumulate unlimited losses.

This is why stop-loss discipline is non-negotiable in pairs trading. It is also why rolling reestimation of the cointegrating relationship is essential. Practitioners typically reestimate the hedge ratio and retest for cointegration every one to three months, dropping pairs that no longer pass the statistical tests.

The multiple comparisons problem is another critical pitfall. Testing thousands of pairs and selecting those that pass cointegration tests at the 5% level will, by chance alone, identify many spurious relationships. Bonferroni corrections or economic filtering (restricting to same-industry pairs) help mitigate this problem, but some degree of overfitting is inevitable in any data-driven pair selection process.

From Pairs to Baskets: Multivariate Extensions

The Johansen framework naturally extends to baskets of three or more cointegrated assets. If three stocks share two cointegrating relationships, the trader can construct two independent mean-reverting spreads, potentially improving diversification and reducing the risk that a single pair relationship breaks down.

Avellaneda and Lee (2010) used eigenportfolios derived from PCA to construct baskets of stocks that are stationary by construction relative to their sector factors. This approach generalizes pairs trading to a full statistical arbitrage framework, where the number of tradeable mean-reverting signals scales with the number of significant eigenportfolios.

The mathematical machinery is the same: cointegration testing, error correction dynamics, half-life estimation. But the portfolio construction becomes more complex, requiring careful attention to position sizing, margin requirements, and the correlation structure among the multiple spreads.

Written by Sam · Reviewed by Sam

This article is based on the cited primary literature and was reviewed by our editorial team for accuracy and attribution. Editorial Policy.

References

Evidence assessment

  • 5/5Engle and Granger (1987) formalized cointegration theory and the error correction representation, earning the 2003 Nobel Prize in Economics for methods of analyzing non-stationary time series
  • 4/5Cointegration-based and mean-reversion-speed-aware pairs trading methods have outperformed simple distance-based approaches, with Avellaneda and Lee (2010) achieving Sharpe ratios above 1.0 using Ornstein-Uhlenbeck models
  • 4/5Simple distance-based pairs trading returns declined from approximately 11% annualized (1962-2002) to near zero after transaction costs by the 2010s, while cointegration methods have retained more of their edge

Frequently Asked Questions

What is the difference between correlation and cointegration in pairs trading?
Correlation measures how two price series move together over short intervals, while cointegration tests whether a long-run equilibrium relationship exists between them. Two stocks can have high correlation but no cointegration, meaning they move together day-to-day but drift apart permanently over time. Conversely, cointegrated stocks may have low short-term correlation but their linear combination always reverts to a stable mean. Cointegration-based pairs trading exploits this mean-reverting spread, providing a more statistically rigorous foundation than correlation alone.
How do you calculate the half-life of mean reversion for a pairs trade?
The half-life is derived from the Ornstein-Uhlenbeck process. First, fit an AR(1) model to the spread: Z(t) = phi * Z(t-1) + epsilon. The autoregressive coefficient phi must be between 0 and 1 for the spread to be mean-reverting. Then apply the formula: t_half = -ln(2) / ln(phi). For example, a phi of 0.95 gives a half-life of about 13.5 trading days, meaning a deviation from the mean decays by half in roughly two and a half weeks. A practical range for tradeable pairs is 5 to 60 days.
What are the main risks of cointegration-based pairs trading?
The primary risks are cointegration breakdown, multiple comparisons bias, and execution challenges. Structural changes such as mergers, regulatory shifts, or business model pivots can permanently destroy the equilibrium relationship, causing the spread to diverge without limit. Testing thousands of pairs creates a multiple comparisons problem where many statistically significant results are spurious. Additionally, transaction costs erode profits significantly, as pairs trades involve four legs (two entries, two exits) and may require frequent rebalancing of the hedge ratio.

Educational only. Not financial advice.