1. Data
Every instrument comes from the source that publishes or licenses it. The data-status line above each result names the provider of each leg, the last available timestamp, the historical coverage and whether prices are adjusted. All results are labelled REAL DATA. The product serves no demonstration or synthetic data; if it ever did, the result would be labelled DEMO DATA — illustrative only.
- Stocks, ETFs and indices: Marketstack, whose US prices are licensed from Tiingo. Daily closes are adjusted for splits and dividends. Intraday bars are not adjusted. Indices are tracked through their most liquid ETF (for example the S&P 500 through SPY), because index levels need a separate licence; the ETF price includes fund fees and dividends, so it differs slightly from the published index.
- Forex: European Central Bank reference rates, set once a day around 14:10 CET. Daily only.
- Crypto: Binance daily closes (UTC calendar day), with Coinbase as a fallback. Crypto history starts in 2017 at the earliest, so crypto pairs cannot cover ten years.
- Brent, WTI and Henry Hub natural gas: daily spot price assessments from the U.S. Energy Information Administration, retrieved through FRED. These are spot prices, not futures contracts, so there are no contract rolls and no back-adjustment. Days without a published price are left out.
- Futures-based funds (USO, BNO, UNG, DBA, CPER): exchange-traded funds that hold futures and roll them on their own published schedule. Their prices already include roll gains and losses. Spread Trading Lab does not stitch or roll futures contracts itself.
- Gold, silver and platinum: the physically backed ETFs GLD, SLV and PPLT.
Missing observations. The two legs are matched on common timestamps. A bar is used only when both legs have a price on it; gaps are never filled, interpolated or replaced with synthetic observations. Everything downstream uses natural-log prices.
2. Correlation
Pearson correlation of the two legs' log returns, over the whole sample and over the last lookback bars (252 by default). Correlation measures day-to-day co-movement. It says nothing about whether the gap between the two comes back, so it carries a small weight in the score and can never on its own make a pair look strong. A pair with correlation of 0.7 or more but no cointegration evidence is described as "correlated, but not cointegrated".
3. Cointegration
Two tests are run on log prices.
- Engle-Granger (statsmodels
coint: an augmented Dickey-Fuller test on the residual of a regression with a constant). It is run in both orderings, log A on log B and log B on log A, because the result depends on which leg is the dependent variable. Both p-values are shown; the smaller one is used. - Johansen trace test (statsmodels
coint_johansen, no deterministic trend, one lagged difference), comparing the trace statistic for rank zero with its 95% critical value.
The relationship is Confirmed when Engle-Granger p ≤ 0.05 and Johansen passes. It is Partial when only one of the two passes, or when Engle-Granger p ≤ 0.10. Otherwise it is Not confirmed. The screener's "Cointegration" column shows the same label.
4. Hedge ratio, spread and half-life
For the statistics, the hedge ratio β is the slope of an ordinary least squares regression of log A on log B over the whole sample. The spread is log A − β·log B. Its half-life is −ln 2 / λ from the regression Δst = α + λ·st−1 + ε; it is infinite when λ ≥ 0.
5. Z-score
The z-score is the spread's distance from its rolling mean, divided by its rolling standard deviation. Both use bars t−lookback to t−1, so the current bar is never part of its own window. The default lookback is 252 Daily bars. This rolling statistical lookback is a separate parameter from the backtest history (ten years).
6. Stability and the current regime
Every 10 bars, the Engle-Granger test, the OLS β and the half-life are recomputed on a trailing window of 250 bars (or a third of the sample, at least 60 bars, when the history is shorter). Short windows have little statistical power: even for pairs that are clearly cointegrated over ten years, most one-year windows fail the test. So the relationship weakening flag is set only when the whole sample passes Engle-Granger, the three most recent windows all have p > 0.10, and at least 30% of the earlier windows passed at p ≤ 0.10, meaning the relationship used to show up and has stopped. It is also set when the recent half-life is more than twice the whole-sample value. Hedge-ratio instability is the standard deviation of a rolling β (window = lookback) divided by the whole-sample β; above 0.75 the hedge ratio counts as unstable.
7. Three separate assessments
A good statistical result never hides a weak trading result. Every pair gets three labels:
- Relationship quality: Confirmed, Partial or Not confirmed, as in section 3.
- Trading evidence: Insufficient evidence — too few completed trades when the backtest has fewer than 10 completed trades, whatever its profit; Negative after costs when the whole-period net P&L is zero or below; Mixed when it is profitable overall but not in the out-of-sample period; Supportive when it is profitable in both and the whole-period Sharpe ratio is at least 0.5; Weak otherwise.
- Current regime: Weakening when the weakening flag is set; Stretched past the stop when today's |z| is beyond the stop level; Stable when the latest rolling window has Engle-Granger p ≤ 0.05; Softening when it is between 0.05 and 0.10; No recent change when it is above 0.10 but fewer than 30% of earlier windows ever passed (short windows rarely confirm this pair, so a failing latest window is not news); Not holding recently when it is above 0.10 and earlier windows used to pass.
8. Score out of 10
One function scores every pair, on the analysis page and in the screener, so both always agree. The score is shown with one decimal place, for example 8.6/10. It is a measure of statistical evidence, never a trading recommendation.
Components (each from 0 to 1):
- Relationship, 40%: 55% cointegration (Engle-Granger p ≤ 0.01 scores 1, ≤ 0.05 scores 0.8, ≤ 0.10 scores 0.35, otherwise 0; this counts 70% and a Johansen pass 30%), 15% correlation (|r| from 0.30 to 0.85 mapped linearly onto 0 to 1), 30% half-life (3 to 60 bars scores 1, under 3 bars 0.6, up to 126 bars 0.6, up to 252 bars 0.3, longer or infinite 0).
- Stability, 15%: 1 minus the hedge-ratio instability mapped linearly from 0.20 to 1.00 (0.5 when it cannot be measured), plus 0.15 when the latest rolling window passes Engle-Granger at 5%, multiplied by 0.3 when the relationship is weakening.
- Trading evidence, 35%: 30% whole-period Sharpe (0 to 1.5 mapped onto 0 to 1), 30% out-of-sample Sharpe (same mapping, 0 without a completed out-of-sample trade), 20% completed trades (5 to 25 mapped onto 0 to 1), 20% maximum drawdown (5% to 40% of notional mapped onto 1 to 0). Multiplied by 0.25 when the whole-period net P&L is zero or below.
- Data, 10%: Daily coverage from 3 to 10 years mapped onto 0 to 1 (intraday: 500 to 3,000 bars).
Caps. Whatever the components say, the score cannot exceed:
- 5.9 when cointegration is not confirmed;
- 5.9 when the backtest has fewer than 10 completed trades;
- 5.9 when the backtest loses money after costs;
- 6.4 when the relationship is unstable (weakening, or hedge-ratio instability above 0.75);
- 6.9 when the out-of-sample period is not profitable;
- 7.4 when the trading evidence is only "Weak" (profitable, but a whole-period Sharpe ratio below 0.5), so good statistics cannot carry thin trading results into the strong bands;
- 6.9 when a Daily backtest has less than ten years of usable history (intraday: fewer than 500 bars).
Interpretation: 9.0–10.0 exceptional statistical evidence · 8.0–8.9 strong · 7.0–7.9 promising · 6.0–6.9 mixed evidence · below 6.0 weak evidence.
9. Backtesting method
- Testing period: ten years of Daily bars. When an instrument has less than ten years of valid data, the result says so ("Available history: 6.4 years"), shows an "Insufficient history" warning and caps the score; the ten-year label appears only when ten years of matched bars exist. Intraday timeframes use whatever history the vendor provides, and the actual tested period is shown.
- Rolling statistical lookback: 252 bars for the z-score, separate from the testing period.
- Warm-up: the trailing hedge ratio needs 252 bars and the z-score a further 252, so with the defaults the first signal can come about two years into the ten-year history. The result shows the date signals start. Nothing from the warm-up is discarded or replaced; it simply produces no trades.
- Hedge ratio: by default a trailing 252-bar OLS regression, re-estimated every bar and frozen while a trade is open. Account holders can instead choose a Kalman filter (two-state filter after Chan 2013, δ = 10⁻⁴, measurement variance 10⁻³, filtered only, never smoothed), a simple ratio with legs sized to equal risk by trailing volatility, or a fixed ratio.
- Rules: enter short-spread (short A, long B) when z ≥ 1.6; enter long-spread when z ≤ −1.6; exit when |z| ≤ 0.8; stop when |z| ≥ 3.2 on the adverse side; no time stop by default.
- Execution: a signal at the close of bar t fills at the close of bar t+1, a one-bar execution delay.
- Sizing: a notional of 10,000 per trade, split 1 : |β| between the legs (ratio mode: inverse volatility).
- Trading costs: 2 bps commission and 1 bp slippage on each leg's traded value at every fill, entry and exit: the guide's 12 bps round trip, counted as 3 bps × 2 legs × 2 fills; a borrow fee of 1% a year on the short leg while open; financing 0% by default. Net cumulative P&L is after all of them, and gross P&L is shown beside it.
- Out of sample: the last 30% of bars. Every estimate is trailing, so this segment is a true walk-forward: nothing in it influenced the estimates behind its signals.
- Completed trades are trades closed by the exit, the stop or a time limit. A trade still open at the last bar is marked to market, labelled "still open" and not counted as completed.
- Deflated Sharpe ratio: each distinct set of rules an account holder tries on a pair counts as a trial. Following Bailey and López de Prado (2014), the out-of-sample per-bar Sharpe is compared with the expected maximum from that many trials, adjusted for skew and kurtosis, and shown as a probability.
- Accounting checks run on every result: net equals gross minus costs, the final equity equals the sum of net P&L, and every entry has an exit or is marked open.
10. Screener
The screener runs every Monday on Daily data. Inside each market every pair is tested, except single stocks, which are paired only inside their industry group. Cross-asset combinations cross a liquid subset of each market. Inverse duplicates are removed (XLE/XOP and XOP/XLE are one pair). A pair is excluded when the legs share fewer than three years of matched bars or fewer than 90% of the sparser leg's bars line up. Every remaining pair gets exactly the evaluation in sections 2 to 9 with the default rules, and the list is sorted by score. Flags mark too few completed trades, unstable relationships and insufficient history. Visitors see the top five pairs of each market; the full ranking needs a free account.
What is not modelled
- Survivorship: the universe is whatever trades today.
- Borrow availability and hard-to-borrow rates beyond the flat fee.
- Intrabar stops; stops trigger at the close.
- Non-synchronous closes for cross-market pairs (for example ECB rates set around 14:10 CET against US closes at 16:00 New York time).
- Taxes.
References
- Engle & Granger (1987), Co-integration and error correction.
- Johansen (1991), Estimation and hypothesis testing of cointegration vectors.
- Gatev, Goetzmann & Rouwenhorst (2006), Pairs trading: performance of a relative-value arbitrage rule.
- Chan (2013), Algorithmic Trading, chapter 3 (Kalman hedge ratio).
- Bailey & López de Prado (2014), The deflated Sharpe ratio.
Change log
- 2026-11-21 Score out of 10 replaces the four-point score. Relationship quality, trading evidence and current regime are judged separately. Daily backtests use ten years of history with a 252-bar rolling lookback; defaults follow the guide (entry 1.6, exit 0.8, stop 3.2, 12 bps round trip). The screener covers stocks, ETFs, indices, forex, crypto, commodities and cross-asset pairs and ranks by score. Hurst exponent, mean crossings, total-least-squares β and the separate spread ADF test were removed from the product. Brent, WTI and natural gas added as EIA spot prices.
- 2026-11-03 Aligned wording with the guide Spread Trading Across Asset Classes; added the accounting checks line.
- 2026-10-22 Added Johansen, both-direction Engle-Granger, rolling diagnostics, in/out-of-sample split and deflated Sharpe. Z-score windows no longer include the current bar.
- 2026-10-14 First public version.
