This research repository implements a statistical arbitrage framework combining Empirical Mean Reversion Time (EMRT) theory with Tabular Reinforcement Learning. The system handles the lifecycle of pair trading: from cointegration discovery (including Johansen tests) to spread construction and execution using a Q-learning agent. It includes benchmarks against traditional Distance and Ornstein-Uhlenbeck (OU) methods.
flowchart TD
A[Market Data Provider] --> B(Cointegration Discovery)
B --> C{Spread Construction}
C --> D[EMRT Estimation]
C --> E[OU Parameter Optimization]
D --> F[RL Entry/Exit Policy]
E --> G[Distance/OU Benchmark]
F --> H[Backtest Engine]
G --> H
H --> I[WFA Report & Metrics]
H --> J[Streamlit UI Dashboard]
- Multi-Stage Discovery: Johansen tests and Engle-Granger tests for pair and group cointegration.
- EMRT Optimizer: Dynamic coefficient selection to minimize mean reversion time.
- RL Execution: Tabular Q-learning agent trained on spread states.
- Comprehensive Backtesting: Support for Walk-Forward Analysis (WFA) and transaction cost modeling.
- GPU Acceleration: CUDA-accelerated cointegration scanning (via CuPy).
- Interactive UI: Streamlit dashboard for real-time visualization of spreads and agent behavior.
git clone https://github.com/AmeerJ97/stat-arb-emrt-rl.git
cd stat-arb-emrt-rl
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev,ui]"# Run discovery and backtest
emrt-rl backtest --pair MSFT:GOOGL
# Launch the Streamlit dashboard
emrt-rl streamlit
# Execute Walk-Forward Analysis
emrt-rl wfa- Ning, B., & Lee, K. (2024). Advanced Statistical Arbitrage with Reinforcement Learning. arXiv preprint arXiv:2403.12180.