5D Library › Liquidation Cascades, Order-Book Depth Depletion and Cointegrated Statistical Arbitrage · 中文
Chapter 4 The Ornstein–Uhlenbeck Process: Mean Reversion and Its Estimation
A random walk on a leash
A random walk has no “home”: today’s price is the best forecast of tomorrow’s, and deviations are never corrected. A mean-reverting variable has a centre it is pulled back towards. The simplest continuous-time model is the Ornstein–Uhlenbeck (OU) process, first proposed by Uhlenbeck and Ornstein in 1930 to describe the velocity of a Brownian particle (Uhlenbeck and Ornstein 1930):
is the long-run mean, the speed of reversion, the noise intensity. The expected deviation decays as , so the time for the expected deviation to halve, the half-life, is
The stationary distribution is normal with variance . In finance the OU process is used for interest rates (the Vasicek model), for volatility, and, in this book, for the spreads of pairs trades. Book 28 used it to illustrate critical slowing down: as approaches zero, autocorrelation rises and variance grows. This chapter is about something else: from finite data, how precisely can and the half-life be estimated?
Exact discretisation
Data are always observed at fixed intervals (each day, say). A useful property of the OU process is that it can be discretised exactly, with no approximation error:
This is a first-order autoregression, AR(1). The exact Gaussian likelihood conditional on is therefore maximised by an ordinary least-squares regression of on : , , .
A common shortcut writes the equation in its Euler approximation , regresses differences on levels and takes minus the slope as , that is . This is harmless when is small; when it is not, it systematically underestimates .
Simulate an OU process with a 10-day half-life by exact discretisation, about 200,000 days long (only to check the formulas; real data are never this long), observe it every 1 day and every 5 days and estimate; the last row reads the same 5-day data with the Euler shortcut.
Calculation
# OU dX = theta (mu - X) dt + sigma dW, exact AR(1) step b = exp(-theta h); the exact
# likelihood is maximised by OLS of X[t+h] on X[t]. Last row: Euler theta = (1 - b)/h.
import math, random
def exact_path(theta, mu, sigma, h, n, x0, rng):
b = math.exp(-theta * h); sd = sigma * math.sqrt((1 - b * b) / (2 * theta))
xs = [x0]
for _ in range(n): xs.append(mu + (xs[-1] - mu) * b + sd * rng.gauss(0, 1))
return xs
def fit_ou(xs, h, euler=False):
x, y = xs[:-1], xs[1:]; n = len(x)
mx, my = sum(x) / n, sum(y) / n
b = sum((p - mx) * (q - my) for p, q in zip(x, y)) / sum((p - mx) ** 2 for p in x)
a = my - b * mx
se2 = sum((q - a - b * p) ** 2 for p, q in zip(x, y)) / n
th = (1 - b) / h if euler else -math.log(b) / h # Euler reading: dX = -theta X h
return th, a / (1 - b), math.sqrt(se2 * 2 * th / (1 - b * b))
rng = random.Random(1930)
theta, mu, sigma = math.log(2) / 10, 0.0, 1.0 # half-life 10 days; sigma per sqrt(day)
print(f"true: theta {theta:.4f}/day, half-life 10.0 days, sigma {sigma:.2f},"
f" stationary sd {sigma / math.sqrt(2 * theta):.3f}")
for name, h, eu in (("h = 1 day", 1.0, False), ("h = 5 days", 5.0, False),
("h = 5 days, Euler", 5.0, True)):
xs = exact_path(theta, mu, sigma, h, int(200000 / h), 0.0, rng)
th, m_, s_ = fit_ou(xs, h, eu)
mean = sum(xs) / len(xs)
sd = math.sqrt(sum((v - mean) ** 2 for v in xs) / len(xs))
print(f"{name:17s}: theta {th:.4f}, half-life {math.log(2) / th:5.2f} d,"
f" sigma {s_:.3f}, sample sd {sd:.3f}")
# true: theta 0.0693/day, half-life 10.0 days, sigma 1.00, stationary sd 2.686
# h = 1 day : theta 0.0677, half-life 10.25 d, sigma 0.997, sample sd 2.710
# h = 5 days : theta 0.0701, half-life 9.90 d, sigma 0.999, sample sd 2.668
# h = 5 days, Euler: theta 0.0590, half-life 11.74 d, sigma 0.924, sample sd 2.690With enough data the exact-likelihood estimate is nearly unbiased: the half-life is estimated at 10.25 days from daily data and 9.90 days from 5-day data, and the sample standard deviation matches the theoretical 2.686. Read with the Euler shortcut, the same 5-day data give a half-life of 11.74 days: is no longer small, and differs from 0.35 by about a sixth.
Small-sample bias
With short data the problem is far worse. Marriott and Pope, and Kendall, derived the bias of the AR(1) coefficient estimate in 1954 (Marriott and Pope 1954; Kendall 1954): when the mean has to be estimated, approximately
is underestimated, which means is overestimated and the half-life underestimated: mean reversion looks faster than it is. With near 1, the bias in is about , roughly 4 divided by the total time span of the sample. Tang and Chen derived bias and variance expansions for the drift parameters of diffusion models such as Vasicek’s and proposed a parametric bootstrap correction (Tang and Chen 2009).
True half-lives of 10 and 40 days, samples of 120, 250 and 1,000 trading days, 2,000 simulations of each case. Finally, a more awkward case: data that are in fact a random walk with no mean reversion.
Calculation
# Small-sample bias of the AR(1)/OU estimate, mean estimated:
# E[b_hat] - b ~ -(1 + 3 b) / n (Marriott & Pope 1954; Kendall 1954).
import math, random
rng = random.Random(1954)
def ar1_hat(xs):
x, y = xs[:-1], xs[1:]; n = len(x)
mx, my = sum(x) / n, sum(y) / n
sxy = sum((p - mx) * (q - my) for p, q in zip(x, y))
return sxy / sum((p - mx) ** 2 for p in x)
def path(b, n):
xs = [rng.gauss(0, 1 / math.sqrt(1 - b * b)) if b < 1 else 0.0]
for _ in range(n): xs.append(b * xs[-1] + rng.gauss(0, 1))
return xs
print("HL | days | b | mean b_hat (theory) | median HL | HL < 0.7 x true"
" | middle 95 %")
for hl in (10, 40):
b = 0.5 ** (1 / hl)
for n in (120, 250, 1000):
bs = sorted(ar1_hat(path(b, n)) for _ in range(2000))
hls = sorted(math.log(2) / -math.log(x) if 0 < x < 1 else 1e9 for x in bs)
short = sum(h < 0.7 * hl for h in hls) / len(hls)
mb, th = sum(bs) / len(bs), b - (1 + 3 * b) / n
print(f"{hl:2d} | {n:4d} | {b:.3f} | {mb:.4f} ({th:.4f}) |"
f" {hls[1000]:6.1f} | {short:5.1%} |"
f" {hls[50]:5.1f}-{min(hls[1949], 999):5.1f}")
# A random walk (b = 1): how often does one year show a "half-life" under 30 days?
fake = [ar1_hat(path(1.0, 250)) for _ in range(2000)]
hl_fake = [math.log(2) / -math.log(x) for x in fake if 0 < x < 1]
print(f"random walk, 250 days: {sum(h < 30 for h in hl_fake) / len(fake):.1%} of samples"
f" show a half-life under 30 days")
# HL | days | b | mean b_hat (theory) | median HL | HL < 0.7 x true | middle 95 %
# 10 | 120 | 0.933 | 0.8997 (0.9014) | 7.1 | 48.6% | 3.0- 18.4
# 10 | 250 | 0.933 | 0.9181 (0.9178) | 8.4 | 28.6% | 4.6- 16.8
# 10 | 1000 | 0.933 | 0.9291 (0.9292) | 9.5 | 3.9% | 6.8- 13.2
# 40 | 120 | 0.983 | 0.9429 (0.9499) | 14.0 | 81.1% | 4.0-120.1
# 40 | 250 | 0.983 | 0.9650 (0.9670) | 22.0 | 65.5% | 7.7- 89.0
# 40 | 1000 | 0.983 | 0.9787 (0.9789) | 34.0 | 28.7% | 18.5- 65.4
# random walk, 250 days: 37.9% of samples show a half-life under 30 daysThe bias formula broadly matches the simulations (for example, with a 10-day half-life and 250 days of data the mean of is 0.9181 against 0.9178 from the formula); only when is close to 1 and the sample is just 120 days long is the actual bias larger than this first-order approximation (0.9429 against 0.9499). For a trader the half-life is more telling. With a true half-life of 10 days and one year (250 days) of data, the median estimate is only 8.4 days, 28.6 % of samples come in below seven-tenths of the true value, and the middle 95 % of estimates run from 4.6 to 16.8 days. With a true half-life of 40 days it is worse: the median from one year of data is only 22 days, 65.5 % of samples fall below seven-tenths, and the middle 95 % runs from 7.7 to 89 days. And a random walk that does not revert at all gives a “half-life” of under 30 days in 37.9 % of one-year samples.
Note
What this means for pairs trading. The half-life is often used to set holding periods and time stops (close after 3 half-lives, say). A short-sample half-life is not only noisy but biased in one direction: it systematically makes the spread look as if it reverts faster, and so makes the strategy look better. More fundamentally, estimating a half-life does not show that the spread really reverts; that needs the unit-root and cointegration tests of the next chapter, which also have little power on one year of data.
Hypothesis · not established
Half-life bias and over-optimistic backtests (not established). The author’s hypothesis is that in published or public pairs-trading backtests, half-lives estimated on formation-period data are systematically shorter than the reversion times actually observed in the trading period, and the ratio between them falls as the formation period lengthens. Falsifiable prediction: if, across a large sample of pairs, the median ratio of formation-period half-life to trading-period reversion time is close to 1 and does not vary with the formation length, the hypothesis is wrong.
Chapter summary
The OU process discretises exactly into an AR(1); its half-life is and its maximum-likelihood estimate is the AR(1) regression. The Euler shortcut underestimates the speed of reversion when is not small. In short samples the AR(1) coefficient is underestimated by about , and the half-life is systematically underestimated: with a true half-life of 40 days, the median estimate from one year of data is only 22 days, and a pure random walk shows a half-life of under 30 days nearly four times in ten. The next chapter asks how to test whether two prices have a mean-reverting combination: cointegration.
References
Fan, Y. (2026). Liquidation Cascades, Order-Book Depth Depletion and Cointegrated Statistical Arbitrage: Ornstein-Uhlenbeck Processes and Kalman-Filter Dynamic Hedging [高杠杆衍生品清算瀑布、订单簿深度衰竭与协整统计套利] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.23796776 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).