25 May 2025 · Andreas Mitillos
We implement a statistical arbitrage strategy using cointegration-based pairs trading. This project demonstrates the identification of cointegrated pairs, statistical testing, and backtesting through an interactive trading tool.
Pairs trading is a statistical arbitrage strategy that exploits temporary deviations from the long-run equilibrium relationship between two cointegrated securities. The strategy involves:
Two time series and are cointegrated if there exists a linear combination that is stationary:
where is stationary. We use the Engle-Granger two-step method:
The ADF test examines the null hypothesis : unit root (non-stationary) vs. : stationary. Low p-values (< 0.05) suggest cointegration.
The trading strategy uses rolling statistics to adapt to changing market conditions:
Over a rolling window of length , we estimate:
The spread at time is:
We normalize the spread using rolling statistics:
Trading signals are generated based on Z-score thresholds:
Use the interactive tool below to analyse cointegrated pairs or run backtests with your chosen parameters. You can select between analysis mode to test for cointegration or backtest mode to simulate the trading strategy.
Simulation Mode