PORTFOLIO UPDATED — SEPTEMBER 23, 2026

§1.3 — Trading

Statistical Arbitrage Backtester

Pairs-trading backtester across S&P 500 constituents using cointegration and inverse-volatility sizing.

walk-forward 2020-01-03 to 2023-12-29: -19% (1x) vs. +57% SPY · Sharpe -0.78 · max drawdown -23%

This page originally led with +121% (Sharpe 0.73). That number did not survive out-of-sample validation — below is what changed and why.

backtest only — never traded live, not connected to any broker

TradingResearch

1. research process — same strategy, three versions

v1 originalin-sample, look-ahead, argument-order bug2018–2023+121%0.73-60%
v2 bugs fixedstill in-sample2018–2023+1822%3.42-7%
v3 walk-forward, 5xout-of-sample2020–2023-87%-1.38-88%
v3 walk-forward, 1xout-of-sample2020–2023-19%-0.78-23%
versionwindowreturnsharpemax dd

v1 picked pairs, hedge ratios and z-score parameters on the full sample, acted on a same-bar close (look-ahead), and a positional-argument bug fed the wrong stop-loss and cost settings into the pair ranking. Fixing the bugs (v2, top 10 pairs) made the in-sample result look better (Sharpe 3.4) — a sign the in-sample fit, not the strategy, was producing the return. v3 re-estimates everything on a 2-year formation window and trades the next 6 months with those estimates frozen (8 folds, 1,005 out-of-sample days).

2. walk-forward out-of-sample return, 2020-01-03 to 2023-12-29

+57%0%-88%2020-01-032023-12-29
walk-forward, 1x walk-forward, 5x SPY

Pairs chosen by cointegration p-value only (p<0.01, top 10 per fold), never by backtest Sharpe. Equal-weighted, 1x, no borrow costs on the short leg. 2 of 8 folds were profitable; the cointegrating relationships found in each formation window did not persist into the next.

3. what leverage does to a negative edge

1x-19.4%7%-0.78-23%
2x-47.7%13%-1.15-50%
3x-66.7%20%-1.28-69%
5x-87.3%33%-1.38-88%
8x-97.4%53%-1.43-98%
10x-99.2%67%-1.45-99%
lev.returnann. volsharpemax dd

Same out-of-sample returns scaled by L, minus 5%/yr financing on the borrowed part. Leverage multiplies the loss and adds volatility drag; at 10x the worst day (-38%) is enough to nearly wipe the account.

honest limitations

One parameter set and a short window that includes March 2020. The universe is 50 current mega-caps (survivorship bias), with no borrow or market-impact costs beyond a linear slippage term. A nested search over entry/exit z-score and p-value cutoff, chosen only on formation data, did not help (1x Sharpe −1.04). Next: sector-matched pairs, log prices and a rolling hedge ratio.

v1 as originally published — in-sample, kept for comparison

Not predictive: pairs, hedge ratios and the slippage grid were all fit on the data they were scored on. The slippage sensitivity grid shown here before was also an artifact — a units error meant the volatility term had no effect on cost.

top 10 cointegrated pairs — S&P 500, 2018–2023 (in-sample)

PM–UNHp=0.0016-12.3%0.54+30.1%
ABT–QCOMp=7.0e-4-15.3%0.52+29.0%
ABT–TXNp=0.0071-11.0%0.49+22.9%
MA–WMTp=4.3e-6-14.7%0.33+15.8%
JNJ–TMOp=0.0089-13.7%0.33+13.6%
CRM–METAp=0.0069-29.3%0.30+17.3%
TSLA–UPSp=0.0075-25.5%0.28+19.1%
ACN–HDp=1.2e-4-12.2%0.28+9.6%
IBM–LLYp=4.4e-4-21.3%0.19+10.2%
V–WMTp=8.4e-5-18.9%0.18+7.3%
paircointegrationmax ddsharpe2018–23

v1 portfolio — top 5 pairs, 5x, in-sample

122%0%2018-01-022023-12-29
portfolio (5x, risk-parity) SPY

drawdown

0%-52%

the signal — one pair's z-score (in-sample fit)

z=+2 full shortz=-2 full long2018-01-022023-12-29

The single best pair by Sharpe (PM–UNH): real hedge-ratio-adjusted spread z-score, 2018–2023. Crossing ±2 opens a full position, ±0.5 a half position, back toward 0 exits.

view source on github ↗
← back to Trading