Skip to content
All simulations

Mean reversion and pairs trading

Simulate a spread that snaps back to its average and trade it, until the relationship breaks.

0.050

θ: the share of the gap to the average closed each day.

0.0
1.0
±1.5 sd

Bet on a snap back once the spread is this many standard deviations from its average.

Half-life13.5 days
Trades7
Win rate86%
Final profit+24.9In spread points, one unit

The first 100 days are used to measure the average and the bands. Teal shading: long the spread. Coral: short.

The spread closes half its gap to the average in about 13.5 days. Fading moves beyond ±1.5 standard deviations, the strategy won 86% of 7 trades. High win rates are typical here. The danger is the one trade that never comes back.

Profit over time, same shocks

Across 300 simulated markets

Profitable, mean-reverting spread100%
Profitable, random-walk spread50%
Average profit, mean-reverting34.3

One good chart proves little. The edge is real only if it holds across many markets, and only while the relationship itself holds.

Try this

  • Set the pull to zero. The bands still trigger trades, but across 300 markets the strategy is a coin flip.
  • Raise the pull toward 0.3. The half-life shrinks to a couple of days and trades come quickly.
  • Switch on the relationship break and watch one open trade wipe out months of small wins.

The math

xt+1=xt+θ (μ−xt)+σ εt,t1/2=ln⁡2−ln⁡(1−θ)x_{t+1} = x_t + \theta\,(\mu - x_t) + \sigma\,\varepsilon_t, \quad t_{1/2} = \frac{\ln 2}{-\ln(1-\theta)}
xtx_t
the spread on day t, for example the price gap between two related stocks
θ\theta
speed of mean reversion
μ\mu
long-run average
σ\sigma
size of daily noise
εt\varepsilon_t
a standard normal shock
t1/2t_{1/2}
half-life: days to close half the gap