5D Library › 高杠杆衍生品清算瀑布、订单簿深度衰竭与协整统计套利 · English

第四章 奥恩斯坦—乌伦贝克过程:均值回复与它的估计

被拉回的随机游走

随机游走没有「家」:今天的价格是明天价格的最好预测,偏离不会被纠正。均值回复的变量则有一个被拉回的中心。最简单的连续时间模型是奥恩斯坦—乌伦贝克(OU)过程,最初是乌伦贝克与奥恩斯坦 1930 年为描述布朗粒子的速度而提出的 (Uhlenbeck and Ornstein 1930):

dXt=θ(μ−Xt)dt+σdWt.\mathrm{d}X_t = \theta(\mu – X_t)\,\mathrm{d}t + \sigma\,\mathrm{d}W_t.

μ\mu 是长期均值,θ>0\theta > 0 是回复速率,σ\sigma 是噪声强度。偏离 X−μX – \mu 的期望值按 e−θte^{-\theta t} 衰减,所以期望偏离减半所需的时间——半衰期——是

t1/2=ln⁡2θ.t_{1/2} = \frac{\ln 2}{\theta}.

平稳分布是正态分布,方差为 σ2/(2θ)\sigma^2/(2\theta)。在金融中,OU 过程被用于利率(瓦西切克模型)、波动率,以及本书关心的配对交易价差。第 28 本曾用它说明临界慢化:回复速率 θ\theta 趋于零时,自相关上升、方差变大。本章关心的是另一件事:从有限的数据中,能把 θ\theta 和半衰期估得多准?

精确离散化

数据总是按固定间隔 hh(比如每天)观测的。OU 过程的一个好性质是可以精确离散化,没有近似误差:

Xt+h=μ+(Xt−μ)b+εt,b=e−θh,εt∼N(0,σ21−b22θ).X_{t+h} = \mu + (X_t – \mu)\,b + \varepsilon_t, \qquad b = e^{-\theta h}, \qquad \varepsilon_t \sim N\!\left(0,\ \sigma^2\,\frac{1-b^2}{2\theta}\right).

这正是一个一阶自回归 AR(1)。因此,以 XtX_t 为条件的精确高斯似然,由 Xt+hX_{t+h} 对 XtX_t 的普通最小二乘回归最大化:θ̂=−ln⁡b̂/h\hat\theta = -\ln \hat b / h,μ̂=â/(1−b̂)\hat\mu = \hat a/(1-\hat b),σ̂2=ŝε2⋅2θ̂/(1−b̂2)\hat\sigma^2 = \hat s_\varepsilon^2 \cdot 2\hat\theta/(1-\hat b^2)。

一个常见的捷径是把方程写成欧拉近似 ΔX≈θ(μ−X)h\Delta X \approx \theta(\mu – X)h,用差分对水平回归,把斜率的相反数当作 θh\theta h,即 θ̂=(1−b̂)/h\hat\theta = (1-\hat b)/h。当 θh\theta h 很小时这没有问题;当 θh\theta h 不小时,它会系统地低估 θ\theta。

用精确离散化模拟半衰期 10 天的 OU 过程,长度约 20 万天(只为核对公式,现实中没有这么长的数据),分别以 1 天与 5 天的间隔观测并估计;最后一行用欧拉捷径读同一份 5 天间隔的数据。

推导

# 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.690

数据足够长时,精确似然估计几乎没有偏差:1 天间隔的半衰期估计为 10.25 天,5 天间隔为 9.90 天,样本标准差与理论值 2.686 相符。同一份 5 天间隔的数据用欧拉捷径读,半衰期变成 11.74 天:θh=0.35\theta h = 0.35 已经不算小,1−e−0.35=0.291 – e^{-0.35} = 0.29 与 0.35 相差约六分之一。

短样本的偏差

数据短时,问题严重得多。马里奥特与波普、肯德尔在 1954 年推导了 AR(1) 系数估计的偏差 (Marriott and Pope 1954; Kendall 1954):在均值需要估计时,近似有

E[b̂]−b≈−1+3bn.\mathrm{E}[\hat b] – b \approx -\frac{1 + 3b}{n}.

bb 被低估,等价于 θ\theta 被高估,半衰期被低估:均值回复看起来比真实的更快。bb 接近 1 时,θ\theta 的偏差约为 4/(nh)4/(nh),即约等于 4 除以样本覆盖的总时长。Tang 与 Chen 对瓦西切克等扩散模型的漂移参数给出了偏差与方差的展开,并提出用参数自助法校正 (Tang and Chen 2009)。

真实半衰期 10 天与 40 天,样本长度 120、250、1,000 个交易日,每种情形模拟 2,000 次。最后看一种更尴尬的情形:数据其实是没有均值回复的随机游走。

推导

# 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 days

偏差公式与模拟大体相符(例如半衰期 10 天、250 天数据时,b̂\hat b 的平均值为 0.9181,公式给出 0.9178);只有在 bb 接近 1、样本又只有 120 天时,实际偏差比这个一阶近似更大(0.9429 对 0.9499)。对交易者来说,更直观的是半衰期:真实 10 天、一年(250 天)数据时,估计的中位数只有 8.4 天,有 28.6% 的样本估计值低于真实值的七成,中间 95% 的估计在 4.6 到 16.8 天之间。真实 40 天时情况更糟:一年数据的中位数只有 22 天,65.5% 的样本低于七成,中间 95% 从 7.7 天到 89 天。而一条根本不回复的随机游走,用一年数据计算,有 37.9% 的样本会给出不到 30 天的「半衰期」。

注

这对配对交易意味着什么。 半衰期常被用来决定持仓时间与止损时间(例如持有超过 3 个半衰期就平仓)。短样本的半衰期估计不仅有噪声,而且有方向性的偏差:它系统性地让价差看起来回复得更快,从而让策略看起来更好。更根本的是,估计出一个半衰期并不能说明价差真的均值回复——这要靠下一章的单位根与协整检验,而那些检验在一年的数据上把握度也很低。

假说 · 尚未验证

半衰期偏差与回测过度乐观(尚未确立)。 作者的假说是:在已发表或公开的配对交易回测中,用形成期数据估计的半衰期系统性地短于交易期实际观察到的价差回复时间,二者之比与形成期长度负相关。可证伪的预测:如果在大样本的配对中,形成期半衰期与交易期回复时间之比的中位数接近 1,且不随形成期长度变化,假说就是错的。

本章小结

OU 过程 dX=θ(μ−X)dt+σdW\mathrm{d}X = \theta(\mu – X)\mathrm{d}t + \sigma\mathrm{d}W 可以精确离散化为 AR(1),半衰期为 ln⁡2/θ\ln 2/\theta,极大似然估计就是 AR(1) 回归。欧拉捷径在 θh\theta h 不小时会低估回复速率。短样本中,AR(1) 系数被低估约 (1+3b)/n(1+3b)/n,半衰期被系统地低估;真实半衰期 40 天时,一年数据的中位估计只有 22 天,而纯随机游走也有近四成的机会显示出不到 30 天的半衰期。下一章讨论如何检验「两个价格之间存在一个均值回复的组合」:协整。

参考文献

Kendall, M. G. 1954. “Note on Bias in the Estimation of Autocorrelation.” Biometrika 41 (3/4): 403–4. https://doi.org/10.1093/biomet/41.3-4.403.
Marriott, F. H. C., and J. A. Pope. 1954. “Bias in the Estimation of Autocorrelations.” Biometrika 41 (3/4): 390–402. https://doi.org/10.1093/biomet/41.3-4.390.
Tang, Cheng Yong, and Song Xi Chen. 2009. “Parameter Estimation and Bias Correction for Diffusion Processes.” Journal of Econometrics 149 (1): 65–81.
Uhlenbeck, George E., and Leonard S. Ornstein. 1930. “On the Theory of the Brownian Motion.” Physical Review 36 (5): 823–41. https://doi.org/10.1103/PhysRev.36.823.

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).