Pairs Trading: Finding Market Relationships
Pairs trading is a market-neutral strategy that profits from the temporary divergence between two historically correlated assets. When the spread between the two assets widens beyond its historical norm, you go long the underperformer and short the outperformer, betting on convergence.
Correlation vs. Cointegration
This distinction is critical and frequently misunderstood. Correlation measures the contemporaneous relationship between two return series. Cointegration measures whether two price series share a long-run equilibrium relationship.
Two stocks can be highly correlated in returns but not cointegrated in prices — meaning their prices can drift apart indefinitely. For pairs trading, you need cointegration, not just correlation.
The Engle-Granger test for cointegration:
1from statsmodels.tsa.stattools import coint
2
3def find_cointegrated_pairs(prices: pd.DataFrame,
4 pvalue_threshold: float = 0.05) -> list:
5 pairs = []
6 cols = prices.columns
7 for i in range(len(cols)):
8 for j in range(i+1, len(cols)):
9 _, pvalue, _ = coint(prices[cols[i]], prices[cols[j]])
10 if pvalue < pvalue_threshold:
11 pairs.append((cols[i], cols[j], pvalue))
12 return sorted(pairs, key=lambda x: x[2])The Hedge Ratio
The hedge ratio determines how many shares of asset B to short for each share of asset A you're long. The standard approach is OLS regression of one price series on the other. The slope coefficient is your hedge ratio.
For time-varying hedge ratios — more appropriate for long-term pairs — use the Kalman filter, which updates the hedge ratio estimate in real time as new data arrives.
Risk Management for Pairs
The primary risk in pairs trading is divergence risk: the spread continues to widen rather than converging. Always set a maximum spread width beyond which you cut the position, regardless of your conviction in the long-run relationship. Cointegration relationships can break permanently — sector disruptions, regulatory changes, and M&A activity can all destroy a previously stable pair.
Applied Ideas
The frameworks discussed above translate directly into deployable trading logic. Here are concrete next steps for practitioners:
- ▸Backtest first: Validate any signal-generation or risk-management approach with walk-forward analysis before committing capital.
- ▸Start small: Deploy with fractional position sizing and paper-trade for at least one full market cycle.
- ▸Monitor regime shifts: Set automated alerts for when your model detects a regime change — manual review before large rebalances is prudent.
- ▸Iterate on KPIs: Track Sharpe, Sortino, max drawdown, and win rate weekly. If any metric degrades beyond your predefined threshold, pause and re-evaluate.
- ▸Combine signals: The strongest edges come from combining uncorrelated signals — pair the ideas in this post with your existing alpha sources.
Found this useful? Share it with your network.
