Back

Pairs Trading Cointegration Scanner

Run Engle-Granger cointegration tests, compute hedge ratios, plot spreads with z-score signals, and backtest a pairs trading strategy.

Feb 23, 2026, Eric

The Core Idea

Two stocks can be individually non-stationary (trending) but their spread can be stationary — they are tied together by an economic relationship. This is cointegration. A pairs trading strategy exploits this: when the spread deviates from its mean, bet on reversion. Cointegration is the mathematical foundation of pairs trading, statistical arbitrage, and relative value strategies.

Pair Selection

CSV: date, asset_a, asset_b

400 observations loaded

Engle-Granger Cointegration Test

Hedge Ratio (β)

1.3458

Intercept (α)

2.5695

ADF Test Stat

-7.808

p-value

0.0050

Cointegrated (p < 0.01)Critical values: 1%: -3.9, 5%: -3.34, 10%: -3.04

Visual Analysis

Price Series

34.844.453.924.131.338.6Asset AAsset B

Spread (A − β·B − α)

EntryEntryExitExitMean-4.09-2.22-0.361.513.38

Z-Score with Signals

-3.1-1.60.01.63.1

Backtest Equity Curve

-56.6-42.4-28.3-14.10.0

Backtest Results

Total Return

-56.60

Round-Trip Trades

17

Win Rate

100.0%

Avg Trade PnL

4.297

Max Drawdown

56.60

Sharpe Ratio

-2.99

What This Means

Cointegrated (p = 0.005). These assets share a long-run equilibrium — the spread mean-reverts. Hedge ratio: 1.346 (for every $1 of Asset A, short $1.35 of Asset B). The backtest produced 17 round-trip trades with a 100% win rate.
Strategy assessment: Negative risk-adjusted returns despite cointegration. The spread reverts too slowly relative to the noise. Consider wider entry thresholds or a different pair.