← Back to Learn
III AdvancedWeek 18 • Lesson 54Duration: 55 min

PT Pairs Trading Introduction

The original market-neutral strategy — buy one, short the other, profit from the gap

Learning Objectives

  • Understand pairs trading mechanics and why they work
  • Learn the spread, hedge ratio, and z-score framework
  • Evaluate risk factors specific to pairs strategies

Explain Like I'm 5

Pairs trading is one of the cleanest strategies in quantitative finance. Find two assets that move together (like EUR/USD and GBP/USD). When one becomes temporarily expensive relative to the other, sell the expensive one and buy the cheap one. You profit when they converge. The elegant part: you're long AND short simultaneously, so overall market direction doesn't matter.

Think of It This Way

Think of pairs trading as a bet on siblings. They're different people but share genetics. If one suddenly becomes far more successful than the other, you bet the gap narrows — either the laggard catches up or the leader falls back. You don't care if both do well or both struggle. You only care about the DIFFERENCE between them.

1How Pairs Trading Works

The mechanics are straightforward: 1. Find a pair: Two assets that are historically linked (e.g., EUR/USD and GBP/USD, or gold and silver). Not just correlated — they need to be economically connected. 2. Compute the spread: spread=log(A)β×log(B)\text{spread} = \log(A) - \beta \times \log(B), where β\beta is the hedge ratio. 3. Compute the z-score: z=spreadspreadˉσspreadz = \frac{\text{spread} - \bar{\text{spread}}}{\sigma_{\text{spread}}} 4. Trade the z-score: - z > 2: Sell A, buy B (spread is too wide, expect convergence) - z < -2: Buy A, sell B (spread is too narrow, expect expansion) - z0z \approx 0: Close positions (spread has reverted) The reason this works is intuitive: correlated assets diverge temporarily due to random events, liquidity imbalances, and timing differences. Strong economic relationships pull them back together like a rubber band. You profit from the mean reversion of the SPREAD, not from predicting direction. Classic FX pairs: EUR/USD vs GBP/USD and AUD/USD vs NZD/USD are natural candidates because they share economic drivers. Production stat arb systems use these heavily.

2The Spread is Everything

If you take one thing from this lesson, let it be this: in pairs trading, you're not trading assets — you're trading the SPREAD between assets. The spread is a synthetic instrument with its own properties: - Its own mean - Its own volatility - Its own half-life (how fast it reverts) - Its own trend or lack thereof When you compute z=StSˉσSz = \frac{S_t - \bar{S}}{\sigma_S}, you're treating the spread like any other instrument and asking "is it overbought or oversold?" The z-score thresholds are your entry signals: - |z| > 2.0: Spread is 2 standard deviations from mean — fairly stretched - |z| > 2.5: Very stretched, higher conviction entry - |z| < 0.5: Spread has reverted, take profit The entire game reduces to one question: does this spread mean-revert reliably? That's literally what cointegration tests answer (next lesson).

Pairs Trading Spread (Z-Score Over Time)

3Risk and Reality Check

Pairs trading sounds like free money, but there are real risks that will humble you quickly: Divergence risk. The spread can keep widening after you enter. Mean reversion is not guaranteed. The pair might decorrelate permanently (structural break). This is the most dangerous risk. Execution risk. You need to enter both legs simultaneously. Slippage on one leg costs you. On M15 this is manageable, but on faster timeframes it becomes brutal. Capital efficiency. You're using margin for two positions but profiting from a small spread. It's capital-intensive for what you get. Drawdown duration. Pairs trades can take weeks to converge. You need patience and capital. Not everyone is built for that tempo. Correlation breakdown. Correlations change. Pairs that worked for years can suddenly stop working. The 2020 COVID crisis broke essentially everything.

4A Real PnL Profile

Here's what a pairs trading equity curve actually looks like, because it's very different from directional trading. The thing about pairs PnL is it's usually smoother than directional. You don't get those massive swings because you're hedged. But the flip side — your winners are smaller too. Typical pairs trade profile: - Average winner: 0.5-1.0R (small but frequent) - Average loser: 1.0-1.5R (when the spread blows out) - Win rate: 55-65% (higher than directional because mean reversion is predictable) - Sharpe ratio: 1.5-2.5 (excellent risk-adjusted returns) The equity curve below shows what 200 pairs trades might look like. Notice how it grinds upward steadily — no massive drawdowns but also no moonshots. This is the stat arb lifestyle: consistent, unexciting, profitable.

Pairs Trading Cumulative PnL (200 Trades)

5Practical Implementation Tips

From experience, here's what actually matters when implementing pairs trading: - Use tight z-score thresholds (1.5-2.0) for entry — wider thresholds give fewer but higher-quality trades - Always have a stop-loss on the spread (e.g., |z| > 4 = cut the loss immediately, something structural may have changed) - Validate with cointegration tests, not just correlation — this is the single biggest mistake beginners make - Re-test regularly — cointegration can break. Test monthly at minimum - Position size conservatively — pairs trades tie up capital in two legs The number one mistake I see: people finding a pair with 0.95 correlation, not testing cointegration, and then getting destroyed when the spread trends for 3 months straight. Correlation is not cointegration. We'll cover this properly in the next lesson.

Key Formulas

Spread Z-Score

Where S_t is the current spread, S-bar is the mean spread, sigma_S is the standard deviation. z > 2 suggests the spread is unusually wide (sell). z < -2 suggests unusually narrow (buy).

Hedge Ratio (OLS)

The hedge ratio determines how many units of B to trade for each unit of A, making the combined position market-neutral.

Hands-On Code

Basic Pairs Trading Strategy

python
import numpy as np
from sklearn.linear_model import LinearRegression

def pairs_trading(price_a, price_b, lookback=100, entry_z=2.0, exit_z=0.5):
    """Simple pairs trading strategy."""
    log_a = np.log(price_a)
    log_b = np.log(price_b)
    
    # Compute hedge ratio
    model = LinearRegression()
    model.fit(log_b.reshape(-1, 1), log_a)
    beta = model.coef_[0]
    
    # Compute spread
    spread = log_a - beta * log_b
    
    # Rolling z-score
    spread_mean = np.mean(spread[-lookback:])
    spread_std = np.std(spread[-lookback:])
    z = (spread - spread_mean) / spread_std
    
    print(f"=== PAIRS ANALYSIS ===")
    print(f"Hedge ratio (beta): {beta:.4f}")
    print(f"Current z-score: {z[-1]:.2f}")
    
    if z[-1] > entry_z:
        print(f"  SELL spread (sell A, buy B)")
    elif z[-1] < -entry_z:
        print(f"  BUY spread (buy A, sell B)")
    elif abs(z[-1]) < exit_z:
        print(f"  EXIT positions (spread reverted)")
    else:
        print(f"  HOLD current position")
    
    return z, beta

Computes the hedge ratio via OLS, constructs the log spread, and generates entry/exit signals based on rolling z-score thresholds.

Knowledge Check

Q1.The spread between EUR/USD and GBP/USD has z-score = 2.5. What should you do?

Assignment

Implement a pairs trading strategy for EUR/USD vs GBP/USD. Compute the spread, z-score, and generate entry/exit signals. Backtest and compare performance to a pure directional strategy.