What is pairs trading? The market-neutral strategy explained
Pairs trading is the canonical market-neutral strategy and the simplest entry point into quantitative trading. The idea is elegant: find two assets whose prices have historically moved together, and when they temporarily drift apart, buy the laggard and short the leader, betting the gap closes. Because you hold one long and one short, a market-wide rally or crash mostly cancels out — your profit depends on the relationship, not the direction. This guide explains how to find a tradable pair, build the spread signal, and the risks that sink naive versions.
What pairs trading is
Pairs trading opens two opposing positions at once: long one asset and short a closely related one. It is the textbook form of statistical arbitrage. The bet is not “this will go up” but “these two will move back toward their normal relationship.” Classic pairs are two companies in the same sector, two ETFs tracking similar baskets, or in crypto two large-cap coins that trade in lockstep.
Finding a tradable pair
Correlation alone is not enough — you need cointegration, meaning the spread between the two prices is stationary and reliably reverts to a mean. Two assets can be correlated yet drift apart forever; a cointegrated pair’s spread keeps coming home. Test candidate pairs with an Augmented Dickey-Fuller test on the spread before trusting any backtest, then validate on the backtester.
The spread signal
Compute the spread (often the log-price difference or a hedge-ratio-weighted difference), then its rolling z-score. Enter when the z-score breaches ±2 standard deviations and exit as it returns toward 0 — the same engine as in the stat arb guide, applied to exactly two legs.
A pairs trade in code
python · pairs.pyimport numpy as np
def pair_position(price_a, price_b, win=30):
spread = np.log(price_a) - np.log(price_b)
z = (spread - spread.rolling(win).mean()) / spread.rolling(win).std()
if z.iloc[-1] > 2:
return "short A / long B"
if z.iloc[-1] < -2:
return "long A / short B"
return "flat"
Why market-neutral matters
Holding one long and one short means a broad rally lifts your long but hurts your short, and the two largely offset — your P&L tracks the spread, not the market. That low correlation to everything else makes a pairs bot a genuinely useful diversifier in a portfolio of bots, even if its raw return is modest.
The risks
The fatal risk is a structural break: one company gets acquired, one coin suffers a hack or delisting, and the historical relationship dies. The spread widens forever and both legs lose. Add double trading fees, short-borrow costs (often unavailable in crypto), and funding/liquidation on crypto shorts. Always cap the trade with a stop on the spread itself — see risk management.
Frequently asked questions
What is pairs trading?
Pairs trading is a market-neutral strategy that opens two opposing positions at once — long one asset and short a closely related one — betting that two historically linked prices that have drifted apart will converge again. Because you hold a long and a short, broad market moves largely cancel and profit depends on the relationship between the two, not market direction.
How do you find a good pair to trade?
Correlation alone is not enough; you need cointegration, meaning the spread between the two prices is stationary and reliably reverts to a mean. Two assets can be correlated yet drift apart forever, whereas a cointegrated pair’s spread keeps returning home. Test candidates with an Augmented Dickey-Fuller test on the spread before trusting any backtest.
Why is pairs trading called market-neutral?
Because holding one asset long and a related one short means a broad rally lifts the long but hurts the short, and the two largely offset. The position’s profit and loss therefore tracks the spread between the two assets rather than the overall market direction, which also makes it a useful diversifier in a portfolio of strategies.
What is the biggest risk in pairs trading?
The biggest risk is a structural break in the relationship — a merger, hack, delisting or regulatory shock — after which the spread widens indefinitely instead of reverting and both legs lose money. Pairs trading also pays double trading fees plus short-borrow costs, and crypto shorts add funding and liquidation risk, so a stop on the spread is essential.