Skip to main content
aifinhub

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 →

Education · Not investment advice. BaFin/EU framework. Past performance does not indicate future results. Editorial standards Sponsor disclosure Corrections

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

Full calculator guide →
  1. 1

    Upload two price series for the pair. The tester runs the Engle-Granger cointegration test first; failure → no test.

  2. 2

    Set entry threshold (z-score for opening), exit threshold (z-score for closing), and stop-loss (z-score for kill-switch).

  3. 3

    Set lookback window for the rolling z-score computation (default 60 days).

  4. 4

    Run the backtest. Read realized Sharpe, max drawdown, trade count, and win rate.

  5. 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

All glossary →

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.

Complementary tools

Planning estimates only — not financial, tax, or investment advice.