BTC/ETH Pair Trade · stat-arb with a Kalman filter
Classic cointegration trading on the crypto majors, with a dynamic hedge ratio and funding-aware position sizing. Demonstrates why static OLS hedging fails.
Pair trading looks simple in papers and is deceptively hard in practice. This template is the minimum viable implementation that actually handles the regime shifts in the hedge ratio.
Kalman-filtered stat-arb on ETH/BTC ratio, perp execution
Why this works
ETH and BTC share a dominant common factor (crypto beta) but diverge on narrative cycles (L1 flows, ETF events). The Kalman filter captures the drift in their hedge ratio — a static OLS regression breaks within weeks because the cointegration relationship is time-varying. Pair trading is the first strategy where you really have to take funding and basis seriously.
Common pitfalls
- Using OLS hedge ratio refit monthly. The ratio drifts intra-month enough to matter; Kalman is not optional here.
- Ignoring funding rate. On Binance perps, funding can flip your expected edge sign within hours during regime breaks.
- Over-leveraging. 3x is the teaching ceiling — above that, liquidation during basis shocks eats tail risk.
Try it yourself
Fork the template into your workspace. The entire configuration — code, parameters, backtest window, cost model — lands in a new private session. Tweak it, break it, and see how robust the edge actually is.
Backtest result
Equity curve
Hedge ratio updated daily via Kalman state. Enter when spread z-score > ±2, exit at 0. Funding rate subtracted from expected edge. No leverage above 3x.
Fork it into your workspace.
The whole template — code, parameters, backtest config — lands in a new private session. Tweak it, run it, break it, learn.