Statistical & computational methods behind every research diagnostic.
How to read this page. Everything below describes the statistical and computational methods this tool uses to characterize the historical behavior of a pair of instruments. The outputs are descriptive research diagnostics — measures of mean reversion, cointegration, regime stability, and forecast structure computed from historical data. They are not investment advice, recommendations, signals to act, or predictions of future results. See the important notice at the end.
1 — Data & the price ratio
For two instruments A and B, the tool forms the daily price ratio rt = PAt / PBt from adjusted historical closes. The ratio is the primary object analyzed throughout. Where a scale-free representation is needed (notably the Kalman filter), the natural log log(rt) is used so that filter parameters behave consistently across pairs at very different price levels; latent quantities are exponentiated back to ratio space for display so charts, z-scores, and residuals remain in ratio units.
Correlation is computed on returns over the full available history (default candidate screen threshold 0.60). Correlation measures co-movement only; it does not by itself imply a stable long-run relationship — that is what the cointegration suite in section 4 examines.
2 — Spread filters: MA, rolling regression, Kalman
A "spread" is a centered, standardized version of the ratio used to measure how far the current level sits from an estimated equilibrium. Three independent estimators are available; they can disagree, and each is a different modeling assumption rather than a "correct" answer.
Moving-average z-score
The equilibrium is a trailing moving average of the ratio; the spread is the deviation divided by the trailing standard deviation:
Simple and assumption-light, but treats the mean as locally constant.
Rolling OLS regression
A rolling ordinary-least-squares regression of A on B estimates a hedge ratio (slope) β and the residual spread. This allows the equilibrium relationship to drift over time as the regression window rolls forward.
Kalman filter (state-space)
The Kalman filter treats the equilibrium mean (and, in the dynamic-hedge variant, the hedge ratio) as an unobserved state that evolves over time, updated each day from new data. It is governed by two noise parameters:
- Q — process noise: how quickly the latent mean is allowed to move. Larger Q → a more adaptive mean.
- R — observation noise: how much day-to-day price variation is treated as noise around the state. Larger R → a smoother, slower state.
The residual (ratio minus the Kalman mean) is the deviation actually examined for reversion, and it typically reverts much faster than the raw ratio. Because of this, the mean-reversion component of the score is re-evaluated on the Kalman residual when the Kalman filter is the active estimator (section 7).
Only the ratio q = Q/R drives the filter gain, so the adaptation speed can be expressed as a single mean half-life (half-life = ln(0.5) / ln(1 − α), where α is the steady-state gain implied by q). You can supply Q and R directly, derive them from a target half-life, or let the tool estimate them by maximum likelihood (MLE): a local-level state-space model is MLE-fit to the log-ratio (statsmodels UnobservedComponents), and the fitted Q/R imply an "auto" half-life. Because near-random-walk ratios drive the unconstrained fit toward a degenerate "track-everything" solution (R → 0), the implied half-life is clamped to a floor and ceiling (default 30–365 trading days) and the fit is cached once per pair for reproducibility.
Because auto/MLE mode fits Q and R separately for each pair, summary pages report the parameterization mode and the effective mean-adaptation half-life rather than a single Q/R value — a single number would misrepresent a per-pair fit.
3 — Mean-reversion diagnostics
Augmented Dickey–Fuller (ADF) test
The ADF test evaluates the null hypothesis that the series has a unit root (non-stationary). A low p-value is statistical evidence against a unit root, i.e. consistent with stationarity / mean reversion over the sample. The tool reports the p-value and uses banded thresholds (configurable; defaults 0.01 / 0.05 / 0.10) to grade the strength of that evidence.
The series tested depends on the active filter mode. In Kalman mode, the ADF/KPSS tests (and the ARIMA fit of section 6) run on the Kalman residual — the ratio minus the adaptive mean line, i.e. the series actually traded — because on cointegrated-but-drifting pairs the raw ratio trends and reports a spurious unit root. In MA and regression modes they run on the raw price ratio. Because the adaptive mean effectively detrends the series, a residual-based p-value describes stationarity of the traded series and is not an independent cointegration test — section 4 covers those.
Ornstein–Uhlenbeck half-life
Fitting a discrete OU / AR(1) process gives a mean-reversion speed θ (estimated as the slope of Δyt on the demeaned lag yt−1). For a mean-reverting series θ ∈ (−1, 0), from which the half-life — the expected time for a deviation to decay by half — is:
A shorter half-life describes faster historical reversion. Half-life is a descriptive statistic of the sample, not a guarantee of future reversion timing.
OU first-passage analysis
For a deviation currently at |z| = x₀, the tool additionally models the normalized residual as a stationary OU process and computes descriptive first-passage quantities: the probability the residual reaches a nearby exit level before a distant stop level (analytic, via the OU scale function), and the expected number of trading days for that passage (Monte Carlo, with barriers evaluated at daily frequency to match how the data is actually observed). Under a mean-reverting OU model the informative quantity is time — how long a reversion is expected to take — rather than whether it is expected at all. These quantities feed forward into the eligibility gate and the Kelly calculation: the expected passage time contributes to eligibility, and the exit-before-stop probability — evaluated at the current z-score for positions at or beyond the entry threshold, or prospectively at the entry threshold for setups that haven't reached it — is blended 50/50 with the empirical hit rate to form the win probability used in the Kelly calculation (section 8). If OU parameters cannot be estimated, the blend falls back to the hit rate alone. Like the half-life itself, these figures are descriptive of the fitted sample.
4 — Cointegration test suite
Cointegration asks whether a linear combination of two non-stationary price series is itself stationary — evidence of a long-run equilibrium relationship. The tool applies an escalating hierarchy of tests so that a single test's limitations do not dominate:
| Test | What it adds |
|---|---|
| Johansen trace test | Primary multivariate test; the trace statistic is compared to 95% and 99% critical values to grade strength. |
| Gregory–Hansen | Allows a single structural break in the cointegrating relationship (level / trend / regime shift) — useful when a relationship changed once but is otherwise intact. |
| Phillips–Ouliaris / Engle–Granger | Residual-based confirmation tests used as fallbacks in the cascade. |
| Hurst exponent | On the results page (before the heavier tests run), a Hurst exponent on first differences acts as a fast proxy: H < 0.5 indicates anti-persistence / mean reversion. |
| Rolling cointegration | Re-runs the test in a rolling window to measure how persistent the relationship has been. A composite stability score combines hedge-ratio drift across windows with variance-ratio evidence of mean reversion (full-sample VR, the share of windows with VR(20) < 0.8, and the most recent window), clamped to [−6, +4] and labeled Stable / Moderate / Unstable; the score adjusts the cointegration component. |
All critical-value thresholds and the points assigned to each tier are configurable on the Score Settings page. These tests describe historical statistical relationships and are subject to estimation error and structural change.
5 — Regime & change-point detection (PELT)
The PELT (Pruned Exact Linear Time) change-point algorithm partitions the history into statistically distinct regimes. Two properties of the segmentation are used: how many structural breaks occurred over the sample, and the length and stationarity of the current regime. A long, stationary current regime is treated as evidence that the relationship has been intact recently; a heavily fragmented history is treated as less stable. The current divergence episode is excluded from the break analysis so that the very deviation that surfaced the pair is not double-counted as instability.
6 — ARIMA
On drill-in, an ARIMA model order is selected automatically (auto-ARIMA) for the analysis series — the Kalman residual in Kalman mode, the raw ratio otherwise (see section 3); residual-space forecasts are mapped back to ratio space for display. The tool distinguishes a fitted model with predictive structure from a pure random walk (0,1,0), which by construction has no mean-reverting forecast and earns minimal credit. Where a backtest hit-rate is available, the directional 1-step accuracy and whether the next-step point forecast moves the ratio toward its historical mean inform the forecast-alignment component. A VECM is used to express forecasts in price/dollar terms for display.
Forecasts are model outputs conditioned on historical data. They are illustrative of the fitted model's structure and are not predictions that any particular outcome will occur.
7 — The composite score
The five diagnostics above are each summarized on a fixed 0–20 internal scale, then combined into a single 0–100 figure. The score is a weighted, normalized summary of statistical properties — a research convenience for ranking and filtering, not a buy/sell signal.
| Component | Measures | Current weight |
|---|---|---|
| C1 — Mean reversion | ADF p-value + OU half-life | 20.0 |
| C2 — Regime stability | PELT current-regime length & stationarity | 20.0 |
| C3 — Cointegration | Johansen / GH / PO–EG / Hurst | 20.0 |
| C4 — ARIMA alignment | Non-random-walk structure + hit-rate | 20.0 |
| C5 — Correlation stability | Return correlation + vol-ratio penalty | 20.0 |
The components are combined as a weighted average over the active components, rescaled to 100. Component 4 is excluded until the ARIMA stage has run, so a results-page score is preliminary and is rescaled over the four available components:
At the default weights of 20 each, this reproduces a simple sum of the components. The result is graded into tiers using configurable cutoffs (current: A ≥ 80.0, B ≥ 60.0, C ≥ 40.0, otherwise D). Every threshold, point value, weight, and cutoff is user-adjustable on the Score Settings page; changing them changes how the diagnostic is summarized, not the underlying market data.
8 — Hedge ratio & sizing calculations (calculation, not a recommendation)
The hedge ratio β (from regression or the Kalman state) defines the relative quantity of B per unit of A that holds the modeled spread; when crossing between elasticity and share terms the tool converts explicitly using price levels (shares = β × PA / PB).
A Kelly criterion calculation is provided as one of several sizing references. It is presented strictly as a mathematical calculation derived from the input statistics — it is not a recommendation to deploy any particular amount of capital. Position-size inputs and limits are user-specified parameters. All sizing figures are arithmetic consequences of the inputs you provide and the historical statistics; they do not account for your individual circumstances, constraints, or risk tolerance.
The win probability entering the Kelly calculation is a blended probability: a 50/50 average of a model-based first-passage probability from the fitted Ornstein–Uhlenbeck process — the chance the spread reaches the exit band before hitting the stop level (section 3), evaluated from the current z-score or prospectively at the entry threshold — and the empirical hit rate from the backtest. Blending guards against either source being over-optimistic on its own; when the OU fit is unavailable the hit rate is used alone. It is a descriptive calculation, not a forecast.
9 — Transaction-cost model
Backtested profitability figures net out an explicit cost model so that results are not flattered by frictionless assumptions:
- Commission — per-share (or percentage) trading cost.
- Bid–ask spread — modeled in basis points of notional.
- Market impact — a square-root-style impact term scaled by an η parameter and trade size relative to average daily volume (ADV).
These are modeling assumptions; realized costs depend on venue, liquidity, timing, and execution, and may differ materially.
10 — Candidate filtering & ongoing monitoring
Beyond the composite score, a rules-based eligibility layer filters which pairs surface as candidates. Filters are computed from the statistics described above — backtest quality (hit rate, risk-adjusted return, completed-trade count), cointegration stability over time, mean-reversion speed relative to the pair's own history, the prevailing market-volatility regime, and scheduled-event risk (a pair is excluded when either leg has an earnings report imminent, since event risk swamps the mean-reversion statistics; instruments without earnings pass automatically). Signals may also be downgraded — shown but flagged rather than hidden — when secondary checks disagree, for example when a deviation that is extreme against its long-run history is unremarkable in the current local-volatility regime, or when the expected reversion is statistically present but slow.
Relationships are also monitored after a divergence is identified: the stationarity testing of section 4 is periodically re-applied to the trailing window, so that a relationship that has stopped behaving as it did historically is flagged rather than silently assumed intact. All filter thresholds are user-configurable, any filter can be bypassed, and a bypassed filter is still computed and displayed. These are screening conveniences over historical statistics — not recommendations, and not assurances that a filtered (or surfaced) pair will behave in any particular way.
11 — Assumptions & limitations
- All statistics are estimated from historical data over a finite sample and are subject to estimation error, look-back sensitivity, and structural change.
- Statistical relationships such as cointegration and mean reversion can weaken or break without warning; past stationarity does not guarantee future stationarity. Ongoing re-testing (section 10) monitors for this but inherits the same false-positive and false-negative limitations as any statistical test.
- Tests can produce false positives and false negatives; the multi-test cascade reduces but does not eliminate this.
- First-passage figures assume the residual follows a stationary OU process with parameters fixed at their current estimates; if the true process deviates from OU, those probabilities and expected times inherit that model error, and Monte Carlo estimates additionally carry finite-sample simulation error.
- The composite score compresses many distinct statistical properties into one number and necessarily loses information; it should be read alongside the underlying diagnostics.
- Forecasts and sizing calculations are conditional model outputs, not assurances of any outcome.
12 — References
The methods above are standard, published techniques. RINS's contribution is running them consistently and at scale with the assumptions shown — not inventing new statistics. The primary sources are listed so you can check the methods against the literature directly.
- CointegrationEngle, R. F., & Granger, C. W. J. (1987). Co-integration and error correction: Representation, estimation, and testing. Econometrica, 55(2), 251–276.
- CointegrationJohansen, S. (1988). Statistical analysis of cointegration vectors. Journal of Economic Dynamics and Control, 12(2–3), 231–254.
- CointegrationPhillips, P. C. B., & Ouliaris, S. (1990). Asymptotic properties of residual based tests for cointegration. Econometrica, 58(1), 165–193.
- Structural breaksGregory, A. W., & Hansen, B. E. (1996). Residual-based tests for cointegration in models with regime shifts. Journal of Econometrics, 70(1), 99–126.
- StationarityDickey, D. A., & Fuller, W. A. (1979). Distribution of the estimators for autoregressive time series with a unit root. Journal of the American Statistical Association, 74(366), 427–431.
- StationarityKwiatkowski, D., Phillips, P. C. B., Schmidt, P., & Shin, Y. (1992). Testing the null hypothesis of stationarity against the alternative of a unit root. Journal of Econometrics, 54(1–3), 159–178.
- Mean reversionUhlenbeck, G. E., & Ornstein, L. S. (1930). On the theory of the Brownian motion. Physical Review, 36(5), 823–841.
- Long memoryHurst, H. E. (1951). Long-term storage capacity of reservoirs. Transactions of the American Society of Civil Engineers, 116, 770–799.
- Change pointsKillick, R., Fearnhead, P., & Eckley, I. A. (2012). Optimal detection of changepoints with a linear computational cost. Journal of the American Statistical Association, 107(500), 1590–1598.
- State-space filteringKalman, R. E. (1960). A new approach to linear filtering and prediction problems. Transactions of the ASME — Journal of Basic Engineering, 82(1), 35–45.
- Pairs tradingGatev, E., Goetzmann, W. N., & Rouwenhorst, K. G. (2006). Pairs trading: Performance of a relative-value arbitrage rule. The Review of Financial Studies, 19(3), 797–827.
Citation of a paper indicates the method RINS implements, not endorsement by its authors.
Important notice — not investment advice
This application and every figure it produces — including the composite score, component scores, statistical test results, forecasts, hedge ratios, Kelly and other sizing calculations, eligibility filters, signal flags, and backtested figures — are provided for informational and educational purposes only. They are statistical calculations and quantitative research diagnostics derived from historical data.
Nothing in this application constitutes investment, financial, legal, tax, or other advice, nor a recommendation, endorsement, signal, offer, or solicitation to buy, sell, or hold any security, derivative, or other financial instrument, or to pursue any trading or investment strategy. No fiduciary or advisory relationship is created by your use of this tool.
Quantitative models rely on assumptions and historical data and are inherently limited. Past performance and historical statistical relationships are not indicative of future results. Trading involves substantial risk, including the possible loss of principal. You are solely responsible for your own decisions and should conduct your own due diligence and consult qualified, licensed professionals before making any financial decision. The authors and operators of this tool accept no liability for any loss arising from its use.