QTQuant Terminal
D1-04D1·intermediate·~22 min

AR models — the math under mean reversion

time-seriesar-modelsmean-reversionhalf-lifepairs-trading

▸ Pretest — guess, even if you don't know

A spread between two ETFs follows an AR(1) with phi = 0.9 at daily frequency. A shock knocks it 10 points above its long-run mean. Roughly how long until the expected deviation is back down to 5 points?

AR(1): a series with memory

The autoregressive model of order one:

xt=c+ϕxt1+εtx_t = c + \phi\, x_{t-1} + \varepsilon_t

Tomorrow's value is a constant, plus a fraction ϕ\phi of today's value, plus fresh white noise. The parameter ϕ\phi is the memory dial — how much of today persists into tomorrow. The trading question it answers: if the spread I trade is stretched today, what do I expect it to do next? White noise says "nothing carries over" (ϕ=0\phi = 0); a random walk says "everything carries over" (ϕ=1\phi = 1); AR(1) covers the whole spectrum in between.

The phi dial

For the stationary case, the long-run mean comes from setting xt=xt1=μx_t = x_{t-1} = \mu in the noiseless equation: μ=c+ϕμ\mu = c + \phi\mu, so

μ=c1ϕ\mu = \frac{c}{1 - \phi}

and deviations from it decay geometrically in expectation: E[xt+h]μ=ϕh(xtμ)E[x_{t+h}] - \mu = \phi^h\,(x_t - \mu).

Half-life: turning phi into a holding period

How long until half of a deviation is expected to be gone? Solve ϕh=12\phi^h = \tfrac{1}{2}:

h1/2=ln(0.5)ln(ϕ)(0<ϕ<1)h_{1/2} = \frac{\ln(0.5)}{\ln(\phi)} \qquad (0 < \phi < 1)

Worked example: ϕ=0.9\phi = 0.9 gives h1/2=ln(0.5)/ln(0.9)=0.6931/0.10546.58h_{1/2} = \ln(0.5)/\ln(0.9) = 0.6931/0.1054 \approx 6.58 periods. A feel for the dial:

ϕ\phihalf-life (periods)
0.50.51.01.0
0.70.71.9\approx 1.9
0.90.96.6\approx 6.6
0.990.9969\approx 69

Why traders compute this before anything else: the half-life is roughly your expected holding period for a mean-reversion trade, which drives capital efficiency, cost drag, and how long you must survive being wrong. And notice how violently the half-life explodes as ϕ1\phi \to 1: the difference between ϕ=0.9\phi = 0.9 and ϕ=0.99\phi = 0.99 is a week versus a quarter. Combine that with D1-03's warning that the ADF test can barely distinguish ϕ=0.99\phi = 0.99 from ϕ=1\phi = 1, and you get the central risk of the strategy: your "mean-reverting" spread may be a random walk wearing a good backtest.

Fitting AR(1) is a regression you already know

No new machinery needed: estimating AR(1) is OLS of xtx_t on xt1x_{t-1} — regress the series on its own lag, exactly the A2-06 setup with x[1:] as the response and x[:-1] as the predictor. The closed form is the familiar slope and intercept:

phi = np.cov(x[:-1], x[1:])[0, 1] / np.var(x[:-1], ddof=1)   # OLS slope
c   = np.mean(x[1:]) - phi * np.mean(x[:-1])                 # OLS intercept

Two honest caveats. In small samples the OLS estimate of ϕ\phi is biased downward (the Kendall bias — on 100 points a true ϕ=0.98\phi = 0.98 fits as roughly 0.940.94, flattering the half-life). And as always, a ϕ\phi fitted on history describes history: persistence itself drifts across regimes.

The pairs-trading connection

Here is where the track's threads knot together. A pairs trade shorts one asset and buys a related one; the portfolio's value is a spread. If that spread is stationary — the cointegration exception flagged in D1-03 — then AR(1) with ϕ<1\phi < 1 is its natural model, and the trade writes itself: enter when the spread is stretched multiple standard deviations from μ=c/(1ϕ)\mu = c/(1-\phi), exit near μ\mu, expect to wait about one half-life. This is the simplest honest description of statistical arbitrage. The failure mode is equally clean: the economic link between the pair breaks, ϕ\phi drifts to 1, and the spread stops reverting — a model-risk loss, not bad luck, and no stop-loss inside the model can see it coming.

Try it

▮ EXERCISE · d1-04-ex1

Implement fit_ar1(x) returning the tuple (c, phi) from the OLS regression of x[1:] on x[:-1]. phi is the covariance of the lagged pairs divided by the variance of x[:-1] — np.cov and np.var with ddof=1 — and c is the mean of x[1:] minus phi times the mean of x[:-1].

The first test sequence is worth staring at: with no noise, 0,2,3,3.5,3.75,0, 2, 3, 3.5, 3.75, \ldots climbs toward the long-run mean c/(1ϕ)=2/0.5=4c/(1-\phi) = 2/0.5 = 4, halving the remaining gap each step — a half-life of exactly one period, matching ϕ=0.5\phi = 0.5 in the table.

⧉ Review card
Write the AR(1) model and describe what each phi regime means.
x_t = c + phi times x_prev + noise. With absolute phi below 1: stationary and mean-reverting, shocks decay geometrically. phi = 1: random walk, the unit root, no mean to revert to. phi above 1: explosive. Negative phi: reverts with overshoot, flip-flopping around the mean.
⧉ Review card
What are the long-run mean and the expected decay of a deviation for a stationary AR(1)?
Long-run mean mu = c divided by (1 minus phi). A deviation decays geometrically in expectation: after h periods it is phi to the power h times the original deviation.
⧉ Review card
Define the half-life of mean reversion and give the phi = 0.9 example.
The time for a deviation to halve in expectation: ln of 0.5 divided by ln of phi. For phi = 0.9 that is about 6.6 periods; for phi = 0.99 about 69. It approximates the expected holding period of a mean-reversion trade and explodes as phi approaches 1.
⧉ Review card
How do you fit an AR(1), and what small-sample caveat applies?
Plain OLS of x_t on its own lag: slope phi = cov of the lagged pairs over the variance of the lag, intercept c = mean of x[1:] minus phi times mean of x[:-1]. In small samples the phi estimate is biased downward (Kendall bias), which flatters the fitted half-life.
⧉ Review card
How does AR(1) connect to pairs trading, and what is the characteristic failure mode?
A stationary spread between two related assets is modeled as AR(1) with phi below 1: enter stretched, exit near the long-run mean, hold about one half-life. Failure mode: the economic link breaks, phi drifts to 1, and the spread stops reverting — model risk, not noise.

Map it

On paper, draw a concept map connecting: phi, random walk, unit root, ADF test, long-run mean, half-life, OLS slope, and pairs trading. Label each arrow with the relationship (which phi value is a unit root? what does ADF test about phi? which formula turns phi into a holding period? which regression estimates phi?).

Predict before the next lesson

Last stop: MA and ARMA models (D1-05). AR remembers its own past values. Predict: what would a series look like that instead remembers only its most recent past shock — and how would its ACF differ from the geometric decay of an AR?

◈ Calibration check

Could you fit an AR(1) by hand with the OLS formulas, compute the half-life for phi = 0.9, and explain why the phi near 1 boundary is where pairs trades die?

1 = guessing · 5 = could teach it

⏻ End of lesson

Mark it read to book its 5 review cards into your deck.

Sources & further reading