Playground
Pair Trading Cointegration Tester
Engle-Granger cointegration test: OLS hedge ratio, ADF on residuals, OU half-life, rolling z-score with entry/exit bands. Runs in your browser. Free.
- Inputs
- Paste + configure
- Runtime
- 1–15 s
- Privacy
- Client-side · no upload
- API key
- Not required
- Methodology
- Open →
1 · Upload two price series
Format: date,asset_a,asset_b. The first numeric column is treated as A, the second as B. Prices are log-transformed internally; the regression is log A = α + β · log B + ε. Needs ≥ 60 aligned observations.
2 · Parameters
What this tool computes
Full Engle-Granger cointegration test on a price pair, plus Ornstein-Uhlenbeck mean-reversion half-life and rolling z-score of the spread for entry/exit simulation. Load the cointegrated synthetic demo or upload your own two-column price CSV.
How to use
Step-by-step
- 1
Upload two price series for the pair. The tester runs the Engle-Granger cointegration test first; failure → no test.
- 2
Set entry threshold (z-score for opening), exit threshold (z-score for closing), and stop-loss (z-score for kill-switch).
- 3
Set lookback window for the rolling z-score computation (default 60 days).
- 4
Run the backtest. Read realized Sharpe, max drawdown, trade count, and win rate.
- 5
Sweep entry threshold to see the trade-frequency-vs-Sharpe surface. Tighter thresholds = more trades, lower per-trade quality; looser = fewer trades, higher quality.
For agents
Use in an agent
Same math, same result shape as the UI above — as a static ES module. No HTTP request, no auth, no rate limit.
import { compute } from "https://aifinhub.io/engines/pair-trading-tester.js"; Contract: /contracts/pair-trading-tester.json Full agent guide →
Glossary references
Terms used by this tool
Questions people ask next
FAQ
What does the tester actually test?
Z-score-based mean-reversion entry/exit on a candidate pair, with parameterized lookback, entry threshold, exit threshold, and stop-loss. Outputs include realized Sharpe, max drawdown, trade count, and win rate. The methodology page documents every parameter.
Why isn't the cointegration test built in?
It is — the tester requires the pair to pass an Engle-Granger test before running. If the pair fails cointegration, the test refuses to run rather than producing misleading numbers. Use the Cointegration Half-Life Solver to identify cointegrated pairs first.
What's the difference between this and the order-book replayer?
The pair tester operates on bar data (1m/5m/daily) and assumes mid-quote fills. The order-book replayer is tick-level with realistic fill simulation. Use the pair tester for strategy ideation; use the order-book replayer to validate execution feasibility before sizing.
How do I set the entry threshold?
Higher threshold = fewer trades but higher conviction. Common starting points: enter at z=2 (about 5% tail), exit at z=0 (mean), stop at z=4. The tool reports trade count and Sharpe per threshold, so you can sweep and see the surface.
Why is pair trading notoriously hard to make work?
Three reasons covered in the methodology page references: (1) cointegration breaks during regime changes, leaving you with a divergent pair, (2) execution costs eat the alpha on tight pairs, (3) the strategy is well-known and crowded, so edges have compressed since the early 2000s. The tester is for studying the strategy, not for guaranteeing profit.
Related deep dive
All articles →Read further
Long-form context behind the tool output.
- Methodology · Opinion·11 min
Execution Simulation: Slippage and Impact
The math of market impact — why it scales as the square root of trade size, when linear impact dominates, and the fix that keeps backtests honest.
Read - Methodology · Opinion·11 min
Multi-Timeframe Signal Integration With LLMs
LLMs belong on weekly fundamentals, not intraday microstructure. A two-layer architecture: weekly LLM thesis plus rule-based intraday invalidation gates.
Read - Pillar · Guide·10 min
Retail PnL vs Backtest
The eleven-point gap between a 14% backtest and 3.2% live PnL, decomposed across eight mechanisms with dollar examples — slippage, latency, fees, fills.
Read
Used in
Decision workflows that use this tool
Goal-driven flows that bundle this tool with adjacent ones.
Complementary tools
Users of this tool often explore
Correlation Matrix Visualizer
Paste a multi-asset returns CSV. See the Pearson correlation heatmap, condition number, average absolute correlation, and eigenvalue concentration.
Walk-Forward Validator
Upload a returns CSV. Rolling or expanding IS/OOS windows, per-window Sharpe, walk-forward efficiency, and a concatenated OOS equity curve. Catches regime.
Risk-Adjusted Returns Calculator
Paste a returns CSV. Sharpe, Sortino, Calmar, Omega, alpha, beta, tracking error, information ratio, max drawdown, and tail moments — plus.