Back to Projects
🟒 LIVE

Pairs Trading Backtest Dashboard

A cointegration-based pairs trading dashboard β€” Engle-Granger and Johansen tests gate a walk-forward mean-reversion backtest across a configurable 1-to-20-year lookback, with a live risk-free rate and a price chart showing the actual long/short/flat position state.

Open Live App View on GitHub

TECH STACK

PythonNext.jsTypeScriptstatsmodelsCointegrationTime SeriesVercel

Deep Dive

Enter any two tickers and the dashboard tests them for cointegration β€” Engle-Granger (via statsmodels' coint(), the actual significance gate) and Johansen (reported alongside as corroborating evidence) β€” before running a walk-forward mean-reversion backtest on the spread: a rolling 252-day formation window, refit every ~21 trading days, with new entries gated on that specific window's own significance rather than a single full-sample check. A pair whose cointegrating relationship breaks down partway through the lookback simply stops trading, rather than continuing on a stale relationship. Entry/exit thresholds default to Β±2Οƒ with an exit at parity, in line with the classic Gatev-Goetzmann-Rouwenhorst methodology.

The lookback window is configurable from 1 to 20 years, fetched via an explicit start date rather than yfinance's built-in period enum (which only covers a handful of fixed values like 1y/2y/5y/10y) β€” a 1-year lookback reliably comes back as insufficient history, since the formation window alone needs ~273 trading days, so 2 years is the practical minimum. The risk-free rate defaults to a live 13-week T-bill yield, editable to override.

Full P&L (Sharpe, Sortino, max drawdown, Calmar, win rate) net of a configurable slippage cost, and a price chart showing both tickers normalized to a common start with the actual long/short/flat position state shaded in, not just an abstract spread chart.

Live Preview

Live app β€” if it doesn't load, open it directly β†—