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

第五章 协整、配对交易与关系断裂

伪回归

把两条毫不相干的随机游走放在一起做回归,常常会得到很「显著」的斜率和很高的拟合优度。格兰杰与纽博尔德 1974 年用模拟展示了这种伪回归 (Granger and Newbold 1974):普通回归的 tt 检验假设残差是平稳的,而两条随机游走的线性组合一般仍是随机游走,检验的名义水平因此完全失效。两种价格「走势很像」,在统计上什么也说明不了。

协整与两步法

恩格尔与格兰杰 1987 年给出了正面的定义 (Engle and Granger 1987):两个序列各自是一阶单整的(像随机游走一样非平稳),但存在一个线性组合 yt−a−bxty_t – a – b x_t 是平稳的,就称它们协整,bb 是协整系数(在配对交易中就是对冲比率)。他们提出的两步法是:

  1. 用普通最小二乘回归 yt=a+bxt+ety_t = a + b x_t + e_t,得到残差 êt\hat e_t;
  2. 对残差做单位根检验:Δêt=γêt−1+∑jcjΔêt−j+ut\Delta \hat e_t = \gamma \hat e_{t-1} + \sum_j c_j \Delta \hat e_{t-j} + u_t,用 γ\gamma 的 tt 统计量检验「残差有单位根(不协整)」。

第二步就是迪基与富勒 1979 年的检验 (Dickey and Fuller 1979),加入差分滞后项后称为增广迪基—富勒(ADF)检验 (Said and Dickey 1984)。但这里有一个陷阱:第一步的最小二乘恰好挑出了使残差方差最小、因而看上去最平稳的组合,所以残差的 tt 统计量比普通单位根检验更偏向负值,不能用普通迪基—富勒的临界值。菲利普斯与乌里亚里斯 1990 年推导了这类残差检验的渐近分布 (Phillips and Ouliaris 1990),麦金农给出了按样本量修正的临界值表 (MacKinnon 1991, 2010)。

证据

临界值(麦金农 2010 年表二,带常数、不带趋势)。 一个变量(普通单位根检验):1% 为 −3.430,5% 为 −2.862,10% 为 −2.567(渐近值)。两个变量(恩格尔—格兰杰残差检验):1% 为 −3.896,5% 为 −3.336,10% 为 −3.044。有限样本的修正为 β∞+β1/T+β2/T2\beta_\infty + \beta_1/T + \beta_2/T^2;两个变量、5% 水平时 β1=−6.1101\beta_1 = -6.1101,β2=−6.823\beta_2 = -6.823,所以 T=250T = 250 时临界值约为 −3.361 (MacKinnon 2010)。

两条独立的随机游走(各 250 个观测)做恩格尔—格兰杰检验,重复 2 万次,比较三个临界值下「拒绝不协整」的比例;再看在 100 个毫不相干的序列中两两筛选(4,950 对)会找出多少「协整对」;最后看真正协整、价差半衰期为 10 天与 40 天的配对,一年数据能被检出的比例。

推导

# Engle-Granger: OLS of y on x, then ADF (one lag) on the residuals. Residual critical
# values (MacKinnon 2010, N = 2, constant): 5 % -3.336; T = 250: -3.361.
import math, random
rng = random.Random(1987)
T = 250

def ols(ys, xs):                          # y = a + b x
    n = len(xs); mx, my = sum(xs) / n, sum(ys) / n
    sxy = sum((x - mx) * (y - my) for x, y in zip(xs, ys))
    b = sxy / sum((x - mx) ** 2 for x in xs)
    return my - b * mx, b

def adf_t(e):                             # regression without constant, one lag of de
    d = [e[i] - e[i - 1] for i in range(1, len(e))]
    Y, X1, X2 = d[1:], e[1:-1], d[:-1]
    s11 = sum(a * a for a in X1); s22 = sum(a * a for a in X2)
    s12 = sum(a * b for a, b in zip(X1, X2))
    s1y = sum(a * y for a, y in zip(X1, Y)); s2y = sum(a * y for a, y in zip(X2, Y))
    det = s11 * s22 - s12 * s12
    g = (s22 * s1y - s12 * s2y) / det; c = (s11 * s2y - s12 * s1y) / det
    rss = sum((y - g * a - c * b) ** 2 for y, a, b in zip(Y, X1, X2))
    return g / math.sqrt(rss / (len(Y) - 2) * s22 / det)

def eg(y, x):
    a, b = ols(y, x)
    return adf_t([v - a - b * u for v, u in zip(y, x)])

def walk(n):
    w = [0.0]
    for _ in range(n - 1): w.append(w[-1] + rng.gauss(0, 1))
    return w

R = 20000
null = sorted(eg(walk(T), walk(T)) for _ in range(R))
print(f"two independent random walks, T = {T}, {R:,} replications")
for name, cv in (("Dickey-Fuller -2.86 (wrong table)", -2.86),
                 ("MacKinnon asymptotic -3.336", -3.336),
                 ("MacKinnon T = 250 -3.361", -3.361)):
    rate = sum(t < cv for t in null) / R
    print(f"   reject 'no cointegration' at {name:34s}: {rate:5.1%}")
print(f"   simulated 5 % critical value: {null[R // 20]:.3f}")
counts = []
for _ in range(4):                        # four universes of 100 unrelated series
    w = [walk(T) for _ in range(100)]
    counts.append(sum(eg(w[i], w[j]) < -3.361
                      for i in range(100) for j in range(i + 1, 100)))
print(f"screening 100 unrelated series (4,950 pairs), four universes:")
print(f"   {counts} pairs 'cointegrated' at 5 %")
for hl in (10, 40):
    b = 0.5 ** (1 / hl); power = 0
    for _ in range(1000):
        x = walk(T); s = [rng.gauss(0, 1 / math.sqrt(1 - b * b))]
        for _ in range(T - 1): s.append(b * s[-1] + rng.gauss(0, 1))
        power += eg([u + v for u, v in zip(x, s)], x) < -3.361
    print(f"truly cointegrated, spread half-life {hl} days: detected in"
          f" {power / 1000:.1%}")
# two independent random walks, T = 250, 20,000 replications
#    reject 'no cointegration' at Dickey-Fuller -2.86 (wrong table) : 14.8%
#    reject 'no cointegration' at MacKinnon asymptotic -3.336       :  5.0%
#    reject 'no cointegration' at MacKinnon T = 250 -3.361          :  4.7%
#    simulated 5 % critical value: -3.339
# screening 100 unrelated series (4,950 pairs), four universes:
#    [356, 224, 323, 351] pairs 'cointegrated' at 5 %
# truly cointegrated, spread half-life 10 days: detected in 49.5%
# truly cointegrated, spread half-life 40 days: detected in 8.7%
两条无关随机游走的恩格尔—格兰杰残差 ADF 统计量的分布(250 个观测,2 万次重复)。用普通迪基—富勒的临界值 −2.86,有 14.8% 被错判为协整;用麦金农残差检验的临界值 −3.36,错判率为 4.7%。

用错表的后果很具体:在 −2.86 处,两条毫不相干的随机游走有 14.8% 被判为协整,是名义水平的约三倍。用麦金农的临界值,错判率回到 5% 左右(模拟得到的 5% 分位数为 −3.339,与渐近值 −3.336 非常接近)。

但即使临界值用对了,筛选本身仍会制造大量假配对:在 100 个毫不相干的序列中两两检验,四次模拟分别找出 356、224、323、351 对「协整」配对,平均约占 6%(按 4.7% 的错判率,期望值约为 233 对)。这些配对共享序列,彼此相关,所以每次筛选出的数目波动很大,四次的平均也不一定接近期望值。反过来,检验的把握度又很低:真正协整、价差半衰期 10 天的配对,一年的数据只有 49.5% 的机会被检出;半衰期 40 天时只有 8.7%。在一年的日度数据上,「通过协整检验」与「真正协整」之间的关系非常松散。

配对交易的实证

证据

配对交易的收益及其衰减。 加特夫、戈茨曼与鲁文霍斯特用 1962—2002 年的美国日度股票数据,按标准化价格的最小距离配对(距离法,不是协整检验),发现一个简单的交易规则对自融资的配对组合带来最高约 11% 的年化超额收益,通常超过保守估计的交易成本 (Gatev et al. 2006)。多与法夫把样本延长到 2009 年 6 月,发现收益持续下降:前 20 对的月均超额收益从 1962—1988 年的 0.86% 降到 1989—2002 年的 0.37%,再到 2003—2009 年的 0.24%;但在 2000—2002 年熊市与 2007—2009 年金融危机等长期动荡期间表现强劲;他们认为下降主要来自套利风险上升(最多解释约 70% 的收益下降),而不是对冲基金竞争 (Do and Faff 2010)。他们的后续研究计入佣金、市场冲击与卖空费用后发现,在细分行业内精选的配对仍有每月约 30 个基点的风险调整收益,只在市值最大的 30% 股票中交易为 24 个基点,而 2002 年以后,配对交易与行业内短期反转策略都基本不再盈利 (Do and Faff 2012)。

证据

统计套利与拥挤。 阿韦利亚内达与李用主成分或行业交易所交易基金的回归残差构造均值回复信号(残差被建模为 OU 过程),扣除交易成本后,主成分策略在 1997—2007 年的年均夏普比率为 1.44,2003—2007 年降到 0.9;基于行业基金的策略在 1997—2007 年为 1.1,加入成交量信号后在 2003—2007 年为 1.51 (Avellaneda and Lee 2010)。坎达尼与罗分析了 2007 年 8 月的「量化崩盘」:一个简单的模拟做市策略在 8 月 6 日那一周出现显著亏损,此前与此后都盈利;他们把这次错位归因于 7 月至 8 月第一周的投资组合去杠杆,以及 8 月 8 日起做市风险资本的暂时撤出 (Khandani and Lo 2011)。拥挤的同类策略同时平仓,本身就会打破价差的均值回复。

当关系断裂

协整是对过去的描述。并购、监管变化、业务重组或单纯的资金流,都可能让一个过去平稳的价差改变均值,甚至变成随机游走。

用一个合成价差(半衰期 10 天、平稳标准差 1%)比较三种交易年:A 关系稳定;B 交易期第 60 天价差的均值跳升 3%(重新定价);C 交易期第 60 天起价差变成随机游走(协整消失)。规则:用形成期 250 天估计均值与标准差,|z|>2|z| > 2 开仓,zz 回到 0 平仓;可选止损为 |z|>4|z| > 4 时平仓并在当年停止交易该配对。每种情形 1,000 次模拟,成本为每条腿每次交易 0、10、20 个基点。

推导

# Pairs rule on a synthetic OU spread (half-life 10 d, sd 1 %); scenarios A stable,
# B mean +3 % on day 60, C random walk from day 60. Costs in bp per leg per trade.
import math, random
rng = random.Random(2006)
HL, SD = 10, 1.0
B = 0.5 ** (1 / HL); E = SD * math.sqrt(1 - B * B)

def year(scen):
    s = [rng.gauss(0, SD)]
    for t in range(499):
        if scen == "C" and t >= 309: s.append(s[-1] + rng.gauss(0, E))
        else:
            mu = 3.0 if scen == "B" and t >= 309 else 0.0
            s.append(mu + B * (s[-1] - mu) + rng.gauss(0, E))
    return s

def trade(s, stop):
    f = s[:250]; m = sum(f) / 250; sd = math.sqrt(sum((v - m) ** 2 for v in f) / 249)
    pos, pnl, legs = 0, 0.0, 0
    for t in range(250, 499):
        z = (s[t] - m) / sd
        if pos and stop and abs(z) > 4:
            legs += 2; pos = 0; break
        if pos == 0 and abs(z) > 2: pos = -1 if z > 0 else 1; legs += 2
        elif pos and (z * pos >= 0): pos = 0; legs += 2
        pnl += pos * (s[t + 1] - s[t])
    if pos: legs += 2                      # close at year end
    return pnl, legs

print("scenario, stop | mean P&L (%) at cost 0 / 10 / 20 bp | P(loss) at 10 bp | 5th pct")
for scen in "ABC":
    for stop in (False, True):
        res = [trade(year(scen), stop) for _ in range(1000)]
        nets = {c: sorted(p - l * c / 100 for p, l in res) for c in (0, 10, 20)}
        mean = "  ".join(f"{sum(v) / 1000:5.2f}" for v in nets.values())
        loss = sum(v < 0 for v in nets[10]) / 1000
        print(f"   {scen}, {'stop 4' if stop else 'none  '}  |       {mean}"
              f"         |      {loss:5.1%}      | {nets[10][50]:6.2f}")
# scenario, stop | mean P&L (%) at cost 0 / 10 / 20 bp | P(loss) at 10 bp | 5th pct
#    A, none    |        5.63   4.50   3.37         |       0.5%      |   0.00
#    A, stop 4  |        5.08   4.02   2.96         |       4.5%      |   0.00
#    B, none    |        0.73   0.03  -0.67         |      52.4%      |  -2.82
#    B, stop 4  |       -0.19  -0.85  -1.51         |      76.8%      |  -2.65
#    C, none    |        1.22   0.25  -0.73         |      44.7%      |  -7.26
#    C, stop 4  |        1.12   0.26  -0.59         |      57.5%      |  -2.71

关系稳定时,规则在每条腿 10 个基点的成本下平均每年获得 4.50%(以一条腿的名义价值计),亏损的年份只有 0.5%。均值跳升时,平均收益降到几乎为零,超过一半的年份亏损;止损反而让情况更糟(平均 −0.85%,76.8% 的年份亏损),因为价差在新的均值附近波动时会反复触发止损。价差变成随机游走时,平均收益也接近于零,44.7% 的年份亏损,最差 5% 的年份亏损超过 7.26%;止损把最差 5% 的亏损截到约 2.71%,但没有提高平均收益。成本同样要紧:即使关系稳定,成本从 0 增加到 20 个基点,平均收益就从 5.63% 降到 3.37%。

注

止损截尾,不改善均值。 在这个合成例子里,止损的作用是限制最坏情况,而不是提高期望收益;在价差只是换了一个均值时,它甚至有害。一条止损规则好不好,取决于断裂的形态,而断裂的形态在事前是不知道的。这是第八章核查表要求事先写下止损规则、并检验协整稳定性的原因。

本章小结

两条随机游走之间的回归会产生伪关系;协整要求存在平稳的线性组合,用恩格尔—格兰杰两步法检验时必须使用残差检验的临界值(两变量、带常数,5% 约 −3.34,250 个观测约 −3.36),用普通迪基—富勒的 −2.86 会使错判率接近 15%。即使临界值正确,大规模筛选也会制造数以百计的假配对,而一年数据检出真协整的把握度很低。配对交易的历史收益确实存在,但持续衰减,计入成本后大幅缩小。协整关系断裂时,规则的收益趋于零或为负,止损只能截尾。下一章讨论另一种思路:不假设对冲比率固定,而让它随时间变化。

参考文献

Avellaneda, Marco, and Jeong-Hyun Lee. 2010. “Statistical Arbitrage in the US Equities Market.” Quantitative Finance 10 (7): 761–82. https://doi.org/10.1080/14697680903124632.
Dickey, David A., and Wayne A. Fuller. 1979. “Distribution of the Estimators for Autoregressive Time Series with a Unit Root.” Journal of the American Statistical Association 74 (366): 427–31. https://doi.org/10.1080/01621459.1979.10482531.
Do, Binh, and Robert Faff. 2010. “Does Simple Pairs Trading Still Work?” Financial Analysts Journal 66 (4): 83–95. https://doi.org/10.2469/faj.v66.n4.1.
Do, Binh, and Robert Faff. 2012. “Are Pairs Trading Profits Robust to Trading Costs?” Journal of Financial Research 35 (2): 261–87. https://doi.org/10.1111/j.1475-6803.2012.01317.x.
Engle, Robert F., and C. W. J. Granger. 1987. “Co-Integration and Error Correction: Representation, Estimation, and Testing.” Econometrica 55 (2): 251–76. https://doi.org/10.2307/1913236.
Gatev, Evan, William N. Goetzmann, and K. Geert Rouwenhorst. 2006. “Pairs Trading: Performance of a Relative-Value Arbitrage Rule.” Review of Financial Studies 19 (3): 797–827. https://doi.org/10.1093/rfs/hhj020.
Granger, C. W. J., and P. Newbold. 1974. “Spurious Regressions in Econometrics.” Journal of Econometrics 2 (2): 111–20. https://doi.org/10.1016/0304-4076(74)90034-7.
Khandani, Amir E., and Andrew W. Lo. 2011. “What Happened to the Quants in August 2007? Evidence from Factors and Transactions Data.” Journal of Financial Markets 14 (1): 1–46. https://doi.org/10.1016/j.finmar.2010.07.005.
MacKinnon, James G. 1991. “Critical Values for Cointegration Tests.” Chap. 13 in Long-Run Economic Relationships: Readings in Cointegration, edited by R. F. Engle and C. W. J. Granger. Oxford University Press.
MacKinnon, James G. 2010. Critical Values for Cointegration Tests. Queen’s Economics Department Working Paper No. 1227. Queen’s University, Department of Economics.
Phillips, P. C. B., and S. Ouliaris. 1990. “Asymptotic Properties of Residual Based Tests for Cointegration.” Econometrica 58 (1): 165–93.
Said, Said E., and David A. Dickey. 1984. “Testing for Unit Roots in Autoregressive-Moving Average Models of Unknown Order.” Biometrika 71 (3): 599–607. https://doi.org/10.1093/biomet/71.3.599.

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