Pairs Trading Lab is a free online tool that simulates how statistical pairs
trading works: it generates a synthetic cointegrated stock pair in your browser, estimates the
hedge ratio with OLS regression, tracks the spread's z-score against ±σ entry/exit bands, and
backtests the mean-reversion trade with a full trade log.
No live market data, no sign-up, no API keys — every price series is simulated with a
seedable random generator, so the experiment is reproducible. TICKER A / TICKER B are fictional.
Market & strategy
How hard the spread is pulled back to its mean. 0 = pure random walk.
Daily shock to the spread. More noise = wider bands, sloppier pair.
The hidden ratio used to build pair B. The Lab re-estimates it — see how close it gets.
A slow, smooth pull on the spread. The rolling window mostly absorbs this — try the shift below for a real break.
The spread's equilibrium jumps at day 126 and stays there — a takeover, a broken thesis. This is what kills pairs books.
Open a spread trade when |z| crosses this band.
Close the trade when |z| falls back below this band.
Flat friction per side — spread costs both entry and exit.
No trades fired in this window — widen the entry band or slow the pair down.
How to read this
Practical pairs trading is a statistical bet: two prices share a long-run equilibrium, so when they drift apart, the spread should snap back. This Lab walks through the whole pipeline on simulated data, in five steps:
Generate. Stock A is a random walk; the spread follows a mean-reverting process (Ornstein–Uhlenbeck) with speed θ, plus optional smooth drift and a one-time regime shift halfway through; Stock B = β·A + spread.
Estimate β — without peeking. Regress B on A over a 60-day formation window only (the shaded region on the spread chart). The residual is the estimated spread. Fitting on the full sample would be cheating: demeaning a random walk manufactures fake mean reversion, making even a broken pair look tradable.
Score it. A rolling 60-day z-score normalises the spread, so "+2" means the same thing on day 100 and day 200.
Test stationarity. A simplified ADF check asks whether the spread genuinely mean-reverts. t-stat below −2.86 ≈ stationary.
Trade the bands. Short the spread above +entry σ (short B, long β̂·A), buy it below −entry σ, exit near zero. Positions are sized to $10,000 notional per leg, the way a real pairs book would size them — a flat per-side cost is then economically meaningful.
Drifting pair — barely any pull-back: the "stationary" verdict gets shaky and half-life explodes.
Broken pair — a mid-sample regime shift: the spread jumps to a new level and never comes home. Fading the jump is the classic pairs-trade blow-up — the heuristic flags it "not stationary" and the trade log shows the damage.
Honest limitations
The stationarity check is a simplified heuristic, not a formal ADF test (no lag selection, no MacKinnon p-values).
The backtest assumes you can always trade at the simulated close, with one flat cost per side — real fills have slippage, borrow fees, and corporate actions. Positions are sized to $10,000 notional per leg, the way a real pairs book would size them.
β is estimated once on the formation window and frozen — in live trading it drifts and must be re-estimated, which is itself a source of blow-ups.
Everything here is synthetic. This page teaches the mechanics; it is not investment advice and is not a recommendation to trade any security.