# Cointegration

> Cointegration means two non stationary series share a long run relationship. Learn the Engle Granger and Johansen tests, hedge ratios and pairs trading uses.

Source: https://learn.tradelabsai.com/math/cointegration/  
Track: Math and Statistics · Level: Advanced · Updated: 2026-10-03  
Publisher: TradeLabs AI (https://tradelabsai.com). Education, not financial advice.  
Cite as: TradeLabs Learn, "Cointegration", https://learn.tradelabsai.com/math/cointegration/

Two price series can each wander randomly, yet stay tied together over the long run. When a combination of them is stationary, they are said to be cointegrated. Think of a person walking a dog on a long lead: both wander, but they never drift too far apart. Cointegration is the statistical foundation of pairs trading and statistical arbitrage, because it identifies spreads that tend to revert to a stable level. Clive Granger and Robert Engle shared the 2003 Nobel Memorial Prize in Economic Sciences in part for their work on it.

## The idea

If prices X and Y are both non stationary, but there is a coefficient β such that

```
spread = Y - β × X
```

is stationary, then X and Y are cointegrated, and β is the cointegrating coefficient (the hedge ratio). See [Stationarity, Differencing and Unit Roots](https://learn.tradelabsai.com/math/stationarity/).

## Correlation vs cointegration

| | Correlation | Cointegration |
|---|---|---|
| Measures | Co movement of returns, usually short term | Long run relationship between price levels |
| Data used | Returns | Prices |
| High value means | Returns move together | The spread stays bounded and reverts |
| Trading use | Diversification, hedging | Pairs trading, spread trading |

Two stocks can be highly correlated but not cointegrated, drifting apart over time. Two cointegrated stocks can have modest daily correlation but still be pulled back together. See [Covariance and Correlation](https://learn.tradelabsai.com/math/covariance-and-correlation/).

## The Engle Granger test

1. **Regress** Y on X (in price levels) to estimate β.
2. **Calculate the residuals** (the spread).
3. **Test the residuals for stationarity** with an ADF test, using special critical values because β was estimated.

**Example: Testing two stocks**
A trader regresses the daily price of stock Y on stock X over three years and finds β = 1.6. The residual spread is tested with an ADF test, giving a statistic of minus 4.1, beyond the 5% critical value for cointegration tests (about minus 3.37 for two variables). The pair appears cointegrated. The trader computes the spread's z score and plans to buy the spread (long Y, short 1.6 units of X) when z falls below minus 2, and sell it when z rises above +2. See [Pairs Trading](https://learn.tradelabsai.com/strategies/pairs-trading/) and [Percentiles, Quantiles and Z-Scores](https://learn.tradelabsai.com/math/z-scores/).

## The Johansen test

The Johansen test, developed by Søren Johansen, tests for cointegration among several series at once and can find more than one cointegrating relationship. It is used for baskets, such as a stock against several peers or a group of related futures contracts. See [Statistical Arbitrage](https://learn.tradelabsai.com/strategies/statistical-arbitrage/).

## Error correction models

Cointegrated series can be modelled with an error correction model, where today's changes depend on how far the spread is from equilibrium:

```
ΔY_t = α × (Y_(t-1) - β X_(t-1)) + other terms + ε_t
```

A negative α means deviations shrink over time; its size shows how quickly. See [Econometrics](https://learn.tradelabsai.com/math/econometrics/).

## Practical issues

| Issue | Explanation |
|---|---|
| Relationships break | Mergers, business changes or regulation can end cointegration |
| Look ahead bias | Estimating β on the full sample then trading in the same period inflates results. See [Look-Ahead Bias](https://learn.tradelabsai.com/research/look-ahead-bias/) |
| Multiple testing | Testing thousands of pairs finds some cointegrated pairs by chance. See [P-Hacking and Multiple Testing](https://learn.tradelabsai.com/research/p-hacking-and-multiple-testing/) |
| Unstable hedge ratios | β can drift; rolling estimates or Kalman filters help |
| Costs and shorting | Borrow fees and trading costs eat small edges. See [Borrow Fees and Stock Loan Costs](https://learn.tradelabsai.com/orders/borrow-fees-and-stock-loan-costs/) |

## Good candidates for cointegration

- **Companies with similar businesses and exposures,** such as two large banks or two oil majors.
- **Different share classes** of the same company.
- **ETFs and their underlying baskets.**
- **Related futures:** different delivery locations or closely linked commodities.
- **Currency pairs** of linked economies (with caution).

Economic reasoning for why the relationship should hold makes results much more trustworthy.

## Frequently asked questions

### What is cointegration?

A property of two or more non stationary series whose combination is stationary, meaning they share a long run relationship and tend to move back together.

### What is the difference between correlation and cointegration?

Correlation measures how returns move together in the short term; cointegration measures whether prices stay tied together over the long run.

### How is cointegration used in trading?

Mainly in pairs trading and statistical arbitrage, where traders buy and sell the spread between cointegrated assets when it moves away from its average.

Next, learn whether one series helps predict another in [Granger Causality](https://learn.tradelabsai.com/math/granger-causality/).

## Continue learning

- Next lesson: [Granger Causality](https://learn.tradelabsai.com/math/granger-causality/)
- Previous lesson: [Stationarity, Differencing and Unit Roots](https://learn.tradelabsai.com/math/stationarity/)
- Related: [Stationarity, Differencing and Unit Roots](https://learn.tradelabsai.com/math/stationarity/): A stationary series has stable statistical properties over time. Learn why prices are non stationary, how to test with ADF and KPSS and how to make data stationary.
- Related: [Pairs Trading](https://learn.tradelabsai.com/strategies/pairs-trading/): Pairs trading buys one asset and shorts a related one when their spread stretches, betting it will converge. Learn pair selection, hedge ratios, z scores and risks.
- Related: [Statistical Arbitrage](https://learn.tradelabsai.com/strategies/statistical-arbitrage/): Statistical arbitrage trades many small, mean reverting mispricings across a portfolio of securities. Learn how stat arb works, its models, costs and risks.
- Related: [Regression Analysis](https://learn.tradelabsai.com/math/regression-analysis/): Regression models how one variable relates to others. Learn linear regression, beta, R squared, multiple regression for factors, hedge ratios and common pitfalls.
- Related: [Covariance and Correlation](https://learn.tradelabsai.com/math/covariance-and-correlation/): Covariance and correlation measure how two assets move together. Learn the formulas, how to read them, why correlations change in crises and their portfolio role.
