Trading Dev AcademyFree quant education

Free lesson · Statistical arbitrage

Cointegration, reversion speed and structural breaks

Open interactive lessonPractice calculationsExplore labs

Start with the idea

Cointegration means a combination of nonstationary series is stationary under a specified model. This can support a relative-value hypothesis, but a sample test is evidence about that model, not a guarantee that a trade will converge.

Symbols, units & horizon
  • s_t: residual at current time
  • μ: assumed stable long-run residual mean
  • φ: AR(1) persistence per bar
  • k: number of future bars
  • E[·|s_t]: conditional mean
  • h_1/2: mean-deviation half-life in bars
  • ln: natural logarithm
  • innovation: unpredicted zero-conditional-mean residual change

When and why to use this

Use estimated reversion speed to propose holding horizons and stress the financing burden. Compare its confidence range with the useful life of the relationship.

In Engle–Granger, first estimate the long-run relation and then test the residual for a unit root using residual-based critical values. Standard Dickey–Fuller tables for an observed series are not interchangeable with residual-test tables. Lag length and deterministic terms change the test. Johansen extends the framework to multiple series and cointegrating vectors.

A simple residual model is AR(1): the next deviation retains a fraction φ of the current deviation plus an unpredictable innovation. Positive φ below one describes gradual mean reversion. Negative φ implies alternating deviations; φ near one makes half-life estimates extremely unstable.

Use formation-only stationarity checks, rolling parameter stability and an economic break rule. Test results after searching thousands of pairs need selection correction. A failed short-horizon trade may reflect noise; persistent parameter drift, event changes or loss of borrow can invalidate the strategy itself.

E[st+k−μ|st]=ϕk(st−μ),h12=ln⁡(12)ln⁡ϕ(0<ϕ<1)
Model assumptions, derivation and arithmetic

Cointegration, reversion speed and structural breaks

  1. Apply the AR(1) conditional expectation repeatedly: the mean deviation becomes φ times itself at each step, giving φ^k after k steps.
  2. Set φ^h=1/2 for the half-life. Take logarithms to obtain h lnφ=ln(1/2).
  3. Divide by lnφ, which is negative for 0<φ<1. Both logarithms are negative so h is positive.
Work it by hand

At φ=.9, h=ln(.5)/ln(.9)≈6.58 bars. A residual 2 units above its mean has expected deviation 2×.9^7≈.957 after seven bars; the realised deviation need not follow that path.

Apply it in a strategy

  • Run stationarity diagnostics inside the formation window, retaining the exact specification and selection universe.
  • Estimate persistence and uncertainty; compare its implied holding horizon with costs and data frequency.
  • Predefine event and parameter-break exits, then assess them on future chronological windows.

Research deliverable

Keep a formation report with test specification, all candidates searched, persistence sensitivity and a documented relationship-break rule.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

from math import log

def residual_decay(current,mean,phi,bars):
    if not 0<phi<1 or bars<0: raise ValueError("This half-life formula needs 0<phi<1")
    return mean+phi**bars*(current-mean),log(.5)/log(phi)

print(residual_decay(2,0,.9,7))

Continue learning

Statistical Arbitrage: Relative Value to Tradable Portfolios — all lessons
  1. What statistical arbitrage is—and where it applies
  2. Construct the spread: price ratios, log ratios and executable units
  3. Cointegration, reversion speed and structural breaks
  4. Causal z-scores and a complete entry–exit state machine
  5. From pairs to residual baskets and factor neutrality
  6. Two-leg backtesting, borrow, capacity and ML extensions

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations