Loading market pulse…
Tools

Pairs Trading Starts Here. How Cointegration Finds Stocks That Want to Stay Together.

By FatNarwhal·

Two stocks can be correlated without being cointegrated. Correlation means they tend to move in the same direction over short time periods. Cointegration means something stronger; it means the two price series are fundamentally linked and when they diverge from each other, they will eventually come back together. The spread between them mean-reverts.

That mean-reverting spread is the foundation of pairs trading, one of the most popular strategies in quantitative finance. You buy the underperformer and short the outperformer when they diverge, then close the position when they converge back to their historical relationship. If the cointegration is real and stable, this strategy captures the spread without taking on significant directional market risk.

The FatNarwhal Cointegration tool tests any pair of stocks for cointegration, estimates the spread and the hedge ratio, and shows you the historical spread to assess how mean-reverting it actually looks.

How to Use It

Go to fatnarwhal.com/cointegration and enter two tickers.

Natural pairs to start with are companies in the same industry, or ETFs tracking related indices; SPY and QQQ, Coca-Cola and Pepsi, JPMorgan and Goldman Sachs, or crude oil ETFs and energy company stocks. The idea is to find pairs where the economic relationship is real enough that divergence tends to be temporary.

The tool runs the Engle-Granger cointegration test and gives you a test statistic, a p-value, and a verdict. It also shows you the optimal hedge ratio (how many shares of stock B to hold against each share of stock A to make the spread as stationary as possible), the historical spread using that hedge ratio, and the half-life of mean reversion, which tells you roughly how many days it takes for the spread to revert halfway back to its mean.

A half-life of 10 days is a tight, fast-reverting pair; a half-life of 60 days is slower and may require more patience (and capital tied up) before the trade closes.

The Math Behind It

Two non-stationary series y1 and y2 are cointegrated if there exists a coefficient β such that:

zt=y1,tβy2,tz_t = y_{1,t} - \beta\, y_{2,t}

is stationary, where z_t is called the spread or the cointegrating residual.

The Engle-Granger test estimates β via ordinary least squares (regressing y1 on y2) and then runs an ADF test on the residuals z_t. If the residuals are stationary (ADF p-value below 0.05), the pair is cointegrated. The OLS slope is the hedge ratio.

The half-life of mean reversion is estimated from an AR(1) model on the spread:

Δz_t = α × z_(t-1) + ε_t

The half-life is −log(2) / log(1 + α), where α is the AR coefficient. If α is close to 0, mean reversion is fast; if α is close to -1, mean reversion is slow.

When to Use It and When Not To

Use it when screening for potential pairs trading candidates, particularly within sectors where economic linkages make a long-run relationship plausible. The test works best with a meaningful amount of history; at least two or three years of daily data gives a more reliable cointegration estimate than a few months.

The biggest risk in pairs trading is cointegration breakdown; the pair looks cointegrated historically but the underlying relationship changes structurally, the spread never reverts, and the trade becomes a directional bet rather than a hedge. Monitoring the spread and exiting if it breaches a wide threshold is standard risk management for this reason.

Also note that finding cointegration in-sample does not guarantee it will hold out of sample. The more pairs you test, the more likely you are to find spurious cointegration by chance. Apply some economic judgment to whether the relationship makes sense before trading, rather than purely relying on the statistical test.

Try It

Go to fatnarwhal.com/cointegration and test a few natural pairs in the same sector. Look at the p-value and then look hard at the spread chart. A statistically significant result combined with a spread that looks visually mean-reverting is a much stronger signal than the p-value alone. A result that passes the test but whose spread chart looks like it has been trending in one direction for two years is something to be skeptical of.

Two stocks, one spread, one trade. The cointegration test is how you find out if it is real.