pairs-trading-lab
backtest studio

Backtest Studio — every lever, in one place.

Sliders for entry/exit, costs, slippage, exposure caps, drawdown limits, time-stops. Runs entirely in your browser. Costs are baked into daily returns so Sharpe and the equity curve agree.

Parameters

Pair
Hedge model
Sizing
Hedge window60 bars
Z-score window60 bars
Z entry2.00
enter long-spread when z ≤ −entry, short-spread when z ≥ +entry
Z exit0.50
close when |z| crosses back through this level
Z stop-loss4.00
Time stop30 bars
One-way cost2.0 bps
commissions per leg per fill
Slippage1.0 bps
Drawdown stop0.25
strategy halts if equity drawdown exceeds this fraction
Capital at risk1.00

Performance

17 trades
Total return-19.8%
CAGR-4.32%
Sharpe-0.30
Sortino-0.17
Max DD23.3%
Calmar-0.19
Hit rate52.9%
Avg holding21.8bars
Vol (annualised) 12.3%Costs paid 2.04%CVaR 95% -2.07%Total trades 17
bootstrap (300 resamples · stationary · block ≈ 21)
Median Sharpe -0.3090% CI [-0.71, 0.13]95% CI [-0.75, 0.18]Median total -20%

Equity curve vs benchmarks

starting capital = 1.0

Pairs trading is a market-neutral strategy; the right benchmarks are 0% and the equal-weight long-only basket — not the S&P. Most pair Sharpes look small until you compare to the blue line, which carries full market β.

Drawdown

stop @ 25%

Z-score with positions

solid orange — z-scorecyan step — position (−1 short / 0 flat / +1 long)orange dashed — entry bands ±2green dashed — exit bands ±0.5red — stop-loss bands ±4

Trade P&L distribution

Trade ledger

17 trades
SideEntryExitBarsZ entryZ exitP&LReason
short2024-08-222024-10-03302.050.36+0.41%z-exit
long2024-07-052024-08-1226-2.03-0.47-4.40%z-exit
short2024-01-242024-02-15162.490.37-4.47%z-exit
long2024-01-012024-01-1712-2.140.22-5.03%z-exit
long2023-10-032023-11-1430-2.01-1.27+1.60%time-stop
short2023-06-122023-07-21292.010.48-5.50%z-exit
long2023-02-142023-03-2830-2.27-0.64+1.44%time-stop
short2022-12-232023-01-13152.030.24-5.42%z-exit
short2022-11-232022-12-14152.110.41+2.35%z-exit
short2022-07-122022-07-2592.120.45+1.76%z-exit
long2022-04-292022-06-1030-2.07-0.81+1.19%time-stop
short2021-12-152022-01-12202.520.05+2.97%z-exit
long2021-09-232021-11-0430-2.05-0.97+1.16%time-stop
short2021-07-052021-07-1692.034.04-3.51%stop-loss
long2021-02-222021-04-0530-2.20-1.02-2.07%time-stop
short2020-12-162021-01-12192.550.42+4.27%z-exit
short2020-07-022020-07-31212.180.45-5.01%z-exit

Trade P&L heatmap — entry-z × holding period

cell = avg fractional P&L · count
entry-z \ bars≤56–1011–2021–4041+
≤−3·····
−3..−2.5·····
−2.5..−2··
-5.03%
n=1
-0.18%
n=6
·
−2..0·····
0..2·
-0.88%
n=2
-2.52%
n=3
-3.37%
n=3
·
2..2.5··
3.62%
n=2
··
2.5..3·····
≥3·····

Tells you which entry-z and holding-period buckets are profitable on this pair. Negative diagonal cells (deep z, long holding) typically expose stop-loss leakage; shallow-z + short-holding cells should look the strongest if mean reversion is working.