5D Library › 高频限价订单簿微观结构、霍克斯自激点过程与逆向选择毒流 · English

第四章 度量毒性:知情交易概率、VPIN 与闪崩之争

从模型到度量

第一章的格罗斯滕—米尔格罗姆模型告诉我们,价差取决于知情交易者的比例 μ\mu;可是 μ\mu 看不见。本章讨论从成交数据中估计它的两种方法:伊斯利(Easley)、基弗(Kiefer)、奥哈拉(O’Hara)与佩珀曼(Paperman)1996 年的知情交易概率(PIN),以及伊斯利、洛佩斯·德普拉多(López de Prado)与奥哈拉 2012 年的交易量同步知情交易概率(VPIN),然后讨论围绕 VPIN 与 2010 年 5 月 6 日闪崩的争论,最后用一个价差分解模型说明「毒性」如何使流动性提供者亏损乃至退出。

PIN:一个关于每天买卖笔数的混合模型

证据

伊斯利等人的模型把每个交易日看成一次抽签 (Easley et al. 1996):以概率 α\alpha 当天有信息事件,事件中坏消息的概率为 δ\delta;不知情的买单与卖单分别以强度 εb\varepsilon_b、εs\varepsilon_s 按泊松过程到达;有好消息时知情者另以强度 μ\mu 买入,有坏消息时以强度 μ\mu 卖出。知情交易的概率定义为

PIN=αμαμ+εb+εs.\mathrm{PIN} = \frac{\alpha\mu}{\alpha\mu + \varepsilon_b + \varepsilon_s}.

参数用每天的买卖笔数 (B,S)(B, S) 通过极大似然估计,似然是三个泊松乘积的混合。他们用纽约证券交易所的股票发现,成交活跃的股票 PIN 较低,并且信息交易对价差有显著影响。伊斯利、赫维德恰尔与奥哈拉随后用 1983–1998 年纽约证券交易所的股票,把 PIN 加入法玛—弗伦奇模型,估计两只股票 PIN 相差 10 个百分点时,期望收益每年相差 2.5% (Easley et al. 2002)。杜阿尔特与扬把 PIN 分解为与信息不对称有关的部分和与流动性不足有关的部分,发现只有后者被定价,认为 PIN 与收益的联系来自与信息无关的流动性效应 (Duarte and Young 2009)。

所以「PIN 度量知情交易」本身是一个需要限定的说法:它度量的是买卖笔数在日与日之间不平衡的程度,模型把这种不平衡解释为信息事件。下面的程序先在一个参数明确的模拟中检验估计量的抽样误差,再演示一个已发表的计算问题。

推导

# PIN model of Easley, Kiefer, O'Hara & Paperman (1996). Each day an information event
# occurs with probability alpha; it is bad news with probability delta. Uninformed buys
# and sells are Poisson(eb), Poisson(es); informed traders add Poisson(mu) on one side.
# PIN = alpha mu / (alpha mu + eb + es). Daily buy and sell counts are simulated
# (60 days), the likelihood is maximised (Nelder-Mead on transformed parameters), and
# the sampling spread of the estimate is checked. Also: why the textbook form of the
# likelihood fails for heavily traded stocks (floating-point overflow; Lin & Ke 2011).
import math, random, statistics

def poisson(rng, m):
    if m > 50:                                         # normal approximation, large means
        return max(0, round(rng.gauss(m, math.sqrt(m))))
    k, p, L = 0, rng.random(), math.exp(-m)
    while p > L:
        k += 1; p *= rng.random()
    return k

def simulate(rng, a, d, mu, eb, es, days=60, flags=None):
    out = []
    for _ in range(days):
        ev = rng.random() < a
        bad = ev and rng.random() < d; good = ev and not bad
        out.append((poisson(rng, eb + mu * good), poisson(rng, es + mu * bad)))
        if flags is not None:
            flags.append(ev)
    return out

def naive_lik(th, data):                               # the textbook product of terms
    a, d, mu, eb, es = th; L = 1.0
    P = lambda k, m: math.exp(-m) * m ** k / math.factorial(k)
    for B, S in data:
        L *= ((1 - a) * P(B, eb) * P(S, es) + a * d * P(B, eb) * P(S, es + mu)
              + a * (1 - d) * P(B, eb + mu) * P(S, es))
    return L

def loglik(th, data, lg):
    a, d, mu, eb, es = th; ll = 0.0
    for (B, S), c in zip(data, lg):
        t = (math.log(1 - a) + B * math.log(eb) - eb + S * math.log(es) - es,
             math.log(a * d) + B * math.log(eb) - eb + S * math.log(es + mu) - es - mu,
             math.log(a * (1 - d)) + B * math.log(eb + mu) - eb - mu
             + S * math.log(es) - es)
        m = max(t); ll += m + math.log(sum(math.exp(x - m) for x in t)) - c
    return ll

def unpack(z):
    s = lambda x: 1 / (1 + math.exp(-max(-30, min(30, x))))
    return s(z[0]), s(z[1]), math.exp(z[2]), math.exp(z[3]), math.exp(z[4])

def nelder_mead(f, x0, it=300, step=0.5):
    n = len(x0)
    pts = [list(x0)] + [[x + (step if i == j else 0) for j, x in enumerate(x0)]
                        for i in range(n)]
    vals = [f(p) for p in pts]
    for _ in range(it):
        o = sorted(range(n + 1), key=lambda i: vals[i]); pts = [pts[i] for i in o]
        vals = [vals[i] for i in o]
        c = [sum(p[i] for p in pts[:-1]) / n for i in range(n)]
        r = [2 * c[i] - pts[-1][i] for i in range(n)]; fr = f(r)
        if fr < vals[0]:
            e = [3 * c[i] - 2 * pts[-1][i] for i in range(n)]; fe = f(e)
            pts[-1], vals[-1] = (e, fe) if fe < fr else (r, fr)
        elif fr < vals[-2]:
            pts[-1], vals[-1] = r, fr
        else:
            k = [(c[i] + pts[-1][i]) / 2 for i in range(n)]; fk = f(k)
            if fk < vals[-1]:
                pts[-1], vals[-1] = k, fk
            else:
                pts = [pts[0]] + [[(pts[0][i] + p[i]) / 2 for i in range(n)]
                                  for p in pts[1:]]
                vals = [vals[0]] + [f(p) for p in pts[1:]]
    return pts[vals.index(min(vals))]

def fit(data):
    lg = [math.lgamma(B + 1) + math.lgamma(S + 1) for B, S in data]
    mb = statistics.fmean(B for B, _ in data); ms = statistics.fmean(S for _, S in data)
    best = None
    for a0 in (0.2, 0.6):                                   # two starting points
        z0 = [math.log(a0 / (1 - a0)), 0.0, math.log(0.5 * (mb + ms) / 2 + 1),
              math.log(0.8 * mb + 1), math.log(0.8 * ms + 1)]
        z = nelder_mead(lambda z: -loglik(unpack(z), data, lg), z0)
        v = loglik(unpack(z), data, lg)
        if best is None or v > best[0]:
            best = (v, unpack(z))
    return best[1]

pin = lambda a, d, mu, eb, es: a * mu / (a * mu + eb + es)

if __name__ == "__main__":
    rng = random.Random(1996)
    true = (0.4, 0.5, 40.0, 30.0, 30.0)
    print(f"truth: alpha 0.4, delta 0.5, mu 40, eps_b = eps_s = 30: PIN {pin(*true):.4f}")
    est = [fit(simulate(rng, *true)) for _ in range(100)]
    p = sorted(pin(*e) for e in est)
    print(f"100 samples of 60 days: PIN median {p[50]:.4f}, 5-95 % range"
          f" {p[5]:.4f} to {p[94]:.4f}")
    a = [e[0] for e in est]
    print(f"   alpha median {statistics.median(a):.3f}; estimates with alpha < 0.05 or"
          f" > 0.95: {sum(x < 0.05 or x > 0.95 for x in a)}")
    busy = (0.4, 0.5, 4000.0, 3000.0, 3000.0)
    fl = []; data = simulate(rng, *busy, flags=fl)
    print("60 days with about 6,000 trades a day (mu 4,000, eps 3,000 each side):")
    try:
        print("   textbook likelihood:", naive_lik(busy, data))
    except OverflowError as e:
        print(f"   textbook likelihood: OverflowError {e}")
    e = fit(data)
    print(f"   log-sum-exp form: alpha {e[0]:.3f}, mu {e[2]:,.0f}, PIN {pin(*e):.4f}"
          f" (truth {pin(*busy):.4f})")
    k = sum(fl)
    print(f"   event days actually drawn in this sample: {k} of 60 = {k / 60:.3f};"
          f" PIN at that alpha {pin(k / 60, *busy[1:]):.4f}")
# truth: alpha 0.4, delta 0.5, mu 40, eps_b = eps_s = 30: PIN 0.2105
# 100 samples of 60 days: PIN median 0.2084, 5-95 % range 0.1692 to 0.2523
#    alpha median 0.400; estimates with alpha < 0.05 or > 0.95: 0
# 60 days with about 6,000 trades a day (mu 4,000, eps 3,000 each side):
#    textbook likelihood: OverflowError (34, 'Numerical result out of range')
#    log-sum-exp form: alpha 0.466, mu 4,011, PIN 0.2380 (truth 0.2105)
#    event days actually drawn in this sample: 28 of 60 = 0.467; PIN at that alpha 0.2373

真实 PIN 为 0.2105 时,100 个各含 60 个交易日的样本给出的中位估计为 0.2084,5% 到 95% 的范围为 0.1692 到 0.2523:即使模型完全正确,两个半月的数据也只能把 PIN 估计到正负约 0.04。在这组参数下估计没有落到边界上(α\alpha 小于 0.05 或大于 0.95 的估计为 0 个)。

第二部分换成每天约 6,000 笔交易。教科书形式的似然函数直接计算 e−εεB/B!e^{-\varepsilon}\varepsilon^B/B! 的乘积,在 Python 中立即溢出(OverflowError);在其他语言中则可能悄悄变成零或无穷,使优化器找不到真正的解。林与柯指出,这种浮点溢出或下溢可能使对应真实参数的可行解消失,他们估计近期股票数据中约 44% 的 PIN 估计可能因此向下偏倚,活跃股票的偏倚更大,并提出了修正的写法 (Lin and Ke 2011)。程序改用对数并以「对数—求和—指数」的方式合并三个分量,得到 PIN 0.2380;它高于真实值 0.2105,原因不是计算,而是这个样本中恰好有 28 个事件日(比例 0.467),按这个比例算的 PIN 为 0.2373。每天成交很多时,事件日几乎可以被准确识别,剩下的误差主要来自「60 天里有几天出事」这一抽样本身。

VPIN:在成交量时间中度量订单流毒性

证据

伊斯利、洛佩斯·德普拉多与奥哈拉把「订单流有毒」定义为订单流对做市商造成逆向选择、而做市商可能并未意识到自己在亏本提供流动性 (Easley et al. 2012)。VPIN 在成交量时间中计算:把成交按顺序装进容量为 VV 的「成交量桶」(他们取日均成交量的 1/50),对每个桶估计买量 VτBV^B_\tau 与卖量 VτSV^S_\tau,再对最近 n=50n = 50 个桶取平均:

VPIN=∑τ=1n|VτS−VτB|nV.\mathrm{VPIN} = \frac{\sum_{\tau=1}^{n} |V^S_\tau – V^B_\tau|}{nV}.

买卖量用「批量成交量分类」估计:把一分钟(或其他时间单位)的成交量 ViV_i 按价格变化的标准化值分配,VB=∑iViΦ((Pi−Pi−1)/σΔP)V^B = \sum_i V_i\,\Phi\big((P_i – P_{i-1})/\sigma_{\Delta P}\big),Φ\Phi 为标准正态分布函数。它不需要估计不可观测的参数,也不需要数值优化。他们报告 VPIN 与随后的短期波动率正相关,并称之为「毒性引起的波动」。伊斯利等人 2016 年进一步比较了批量分类与逐笔分类(如李—雷迪算法,它结合报价规则与价格变动规则 (Lee and Ready 1991))在提取信息方面的表现 (Easley et al. 2016)。

奥哈拉认为,高频市场中交易者按成交量而非钟表时间行动,微观结构研究需要相应地改用「成交量时钟」等概念 (O’Hara 2015)。这是 VPIN 设计背后的理由。

闪崩之争

证据

2010 年 5 月 6 日下午,美国股指与股指期货在几分钟内急跌又迅速回升。美国商品期货交易委员会与证券交易委员会的联合报告认为,起点是一位基本面交易者在 E-mini 标普 500 期货上执行的约 75,000 张合约的卖出程序:该算法把执行速度设为前一分钟成交量的 9%,不考虑价格与时间,约 20 分钟内完成;E-mini 在下午 2:41 至 2:44 的约四分钟内下跌约 3%;报告描述了股指期货与个股两个层面的流动性危机 (U.S. Commodity Futures Trading Commission and U.S. Securities and Exchange Commission 2010)。基里连科、凯尔、萨马迪与图尊用当天与前三天的审计数据发现,最活跃的日内中介(高频交易者)在价格下跌时没有改变其交易方式 (Kirilenko et al. 2017)。

证据

伊斯利、洛佩斯·德普拉多与奥哈拉 2011 年认为,闪崩是当前市场结构的产物:订单流毒性在崩盘前的几小时乃至几天里不断上升,VPIN 随之升高,最终迫使流动性提供者退出 (Easley et al. 2011)。安德森与邦达连科重新计算后认为,VPIN 是短期波动率的很差的预测指标,它的最高值出现在闪崩之后而不是之前,其预测能力主要来自与交易强度的机械关系;对 2012 年的 VPIN 版本也得出类似结论 (Andersen and Bondarenko 2014b)。原作者回应说,批评针对的是他们并不主张的方法与他们没有做过的分析 (Easley et al. 2014)。安德森与邦达连科再回应:VPIN 按构造与成交量和收益波动相关,控制当前成交量与波动之后对未来波动没有增量预测力,闪崩前也没有达到异常的极值,而且结论强烈依赖成交分类方法 (Andersen and Bondarenko 2014a)。

作者框架把「闪崩前夕流动性提供者的逆向选择撤单机制」写成了 VPIN 的一部分。核对后应当把三件事分开:VPIN 的定义与计算是清楚的;VPIN 是否在闪崩之前发出了异常信号,是有争议的实证问题;「流动性提供者因逆向选择而撤单导致崩盘」是一种机制解释,官方报告与基里连科等人的数据分析描述的是一个大卖单、市场间的传导与高频中介的行为,并没有确立这一因果链条。本书把它写成假说。

下面的程序在模拟的一分钟数据上(40 个交易日,每天 390 根)检验 VPIN 的一个机械性质。第 20 天植入一段 90 分钟的知情买入(成交量的 62% 为买单,价格因此上涨);第 30 天植入一段 90 分钟的波动率冲击(噪声标准差放大四倍,但买卖各半,没有任何知情交易)。批量分类用过去五天一分钟价格变化的标准差标准化。作为对照,程序还用模拟中「真实」的买卖量计算 VPIN,这在真实数据中是不可能得到的。

推导

# VPIN (Easley, Lopez de Prado & O'Hara 2012) on SIMULATED one-minute bars: 40 days of
# 390 bars. Bulk volume classification: V_B = V Phi(dP / s), s = trailing five-day
# standard deviation of one-minute price changes; buckets of 1/50 of average daily
# volume; VPIN = mean of |V_S - V_B| / V over the last 50 buckets. Two 90-minute
# episodes are planted:
#   day 20  informed flow: 62 % of volume is buying (true imbalance), price drifts up
#   day 30  volatility burst: noise sd x 4, buying and selling balanced (no informed flow)
# "true VPIN" uses the simulated buy and sell volumes, which no real data set contains.
# A last block repeats the episode checks for 20 further seeds (rank among ~40 days).
import math, random, statistics

ND = statistics.NormalDist()
BARS, DAYS = 390, 40

def simulate(rng):
    bars = []
    for d in range(DAYS):
        for m in range(BARS):
            inf = d == 20 and 150 <= m < 240; burst = d == 30 and 150 <= m < 240
            v = 1000 * math.exp(rng.gauss(0, 0.3))
            b = 0.62 if inf else min(0.9, max(0.1, rng.gauss(0.5, 0.05)))
            B = v * b; S = v - B
            dp = 0.02 * (B - S) / 100 + rng.gauss(0, 0.05 * (4 if burst else 1))
            bars.append((d, m, v, B, S, dp))
    return bars

def vpin(bars, true=False, nb=50):
    adv = sum(b[2] for b in bars) / DAYS; V = adv / nb
    hist, out, cur, vb, vs = [], [], 0.0, 0.0, 0.0
    s1 = s2 = 0.0; W = 5 * BARS                    # rolling sums for the trailing sd
    for i, (d, m, v, B, S, dp) in enumerate(bars):
        n = min(i, W)
        s = math.sqrt(max(s2 / n - (s1 / n) ** 2, 1e-12)) if n > 30 else 0.054
        fb = B / v if true else ND.cdf(dp / s)
        s1 += dp; s2 += dp * dp
        if i >= W:
            s1 -= bars[i - W][5]; s2 -= bars[i - W][5] ** 2
        left = v
        while left > 0:                                  # fill buckets of size V
            take = min(left, V - cur); cur += take; left -= take
            vb += take * fb; vs += take * (1 - fb)
            if cur >= V - 1e-9:
                hist.append(abs(vs - vb) / V); cur = vb = vs = 0.0
                if len(hist) >= nb:
                    out.append((d, m, statistics.fmean(hist[-nb:])))
    return out

def summary(series, name):
    vals = sorted(x[2] for x in series)
    cdf = lambda x: sum(v <= x for v in vals) / len(vals)
    q90 = vals[int(0.9 * len(vals))]
    days = {}
    for x in series:
        days[x[0]] = max(days.get(x[0], 0), x[2])
    ordin = [v for k, v in days.items() if k not in (20, 21, 30, 31)]
    print(f"{name}: median {vals[len(vals) // 2]:.3f}, 90th pct {q90:.3f}")
    print(f"   ordinary days whose maximum exceeds the 90th pct:"
          f" {sum(v > q90 for v in ordin)} of {len(ordin)}")
    mx = sorted(days.values(), reverse=True)
    for day, lab in ((20, "informed"), (30, "vol burst")):
        win = [x for x in series if x[0] == day or (x[0] == day + 1 and x[1] < 60)]
        top = max(win, key=lambda x: x[2])
        first = next((x for x in win if x[2] > q90), None)
        when = (f"d{first[0]} m{first[1]}" if first else "never")
        r = 1 + sum(v > top[2] for k, v in days.items() if k not in (day, day + 1))
        print(f"   {lab:9s} max {top[2]:.3f} (CDF {cdf(top[2]):.3f}, rank {r}/{len(mx)})"
              f" at d{top[0]} m{top[1]}; > 90th pct from {when}")

if __name__ == "__main__":
    rng = random.Random(2010); bars = simulate(rng)
    bvc, tru = vpin(bars), vpin(bars, true=True)
    summary(bvc, "VPIN, bulk classification"); summary(tru, "true-imbalance VPIN")
    d20 = [b for b in bars if b[0] == 20 and 150 <= b[1] < 240]
    d30 = [b for b in bars if b[0] == 30 and 150 <= b[1] < 240]
    print(f"episode price moves: informed {sum(b[5] for b in d20):+.2f},"
          f" burst {sum(b[5] for b in d30):+.2f} (daily sd of price about"
          f" {0.054 * math.sqrt(BARS):.2f})")
    for name, ep in (("informed", d20), ("burst", d30)):
        fb = statistics.fmean(ND.cdf(b[5] / 0.054) for b in ep)
        tb = sum(b[3] for b in ep) / sum(b[2] for b in ep)
        ab = statistics.fmean(abs(2 * ND.cdf(b[5] / 0.054) - 1) for b in ep)
        print(f"   {name:8s}: true buy share {tb:.3f}; bulk-classified {fb:.3f};"
              f" mean |2 Phi - 1| per bar {ab:.3f}")
    print("robustness, 20 further seeds (1-20): episode window (its day and the next"
          " hour)")
    print("   series      episode    above 90th pct   median rank   ranked first")
    rob = {}
    for sd in range(1, 21):
        b2 = simulate(random.Random(sd))
        for tr in (False, True):
            s = vpin(b2, true=tr); q = sorted(x[2] for x in s)[int(0.9 * len(s))]
            dmax = {}
            for x in s:
                dmax[x[0]] = max(dmax.get(x[0], 0), x[2])
            for day in (20, 30):
                top = max(x[2] for x in s if x[0] == day or (x[0] == day + 1
                                                            and x[1] < 60))
                r = 1 + sum(v > top for k, v in dmax.items() if k not in (day, day + 1))
                rob.setdefault((tr, day), []).append((top > q, r))
    for (tr, day), v in sorted(rob.items()):
        lab = ("true" if tr else "bulk", "informed" if day == 20 else "burst")
        med = statistics.median(r for _, r in v)
        print(f"   {lab[0]:4s}        {lab[1]:8s}   {sum(a for a, _ in v):2d} of 20"
              f"         {med:4.1f}         {sum(r == 1 for _, r in v):2d} of 20")
# VPIN, bulk classification: median 0.165, 90th pct 0.193
#    ordinary days whose maximum exceeds the 90th pct: 9 of 36
#    informed  max 0.265 (CDF 0.999, rank 1/40) at d21 m11; > 90th pct from d20 m187
#    vol burst max 0.209 (CDF 0.966, rank 4/40) at d30 m388; > 90th pct from d30 m222
# true-imbalance VPIN: median 0.029, 90th pct 0.033
#    ordinary days whose maximum exceeds the 90th pct: 12 of 36
#    informed  max 0.074 (CDF 0.993, rank 1/40) at d21 m43; > 90th pct from d20 m171
#    vol burst max 0.034 (CDF 0.934, rank 8/40) at d30 m294; > 90th pct from d30 m237
# episode price moves: informed +5.02, burst +0.90 (daily sd of price about 1.07)
#    informed: true buy share 0.620; bulk-classified 0.777; mean |2 Phi - 1| per bar 0.618
#    burst   : true buy share 0.505; bulk-classified 0.584; mean |2 Phi - 1| per bar 0.806
# robustness, 20 further seeds (1-20): episode window (its day and the next hour)
#    series      episode    above 90th pct   median rank   ranked first
#    bulk        informed   20 of 20          1.0         20 of 20
#    bulk        burst      14 of 20         11.5          0 of 20
#    true        informed   20 of 20          1.0         20 of 20
#    true        burst       4 of 20         20.5          0 of 20

批量分类的 VPIN 对知情买入有反应:最高值 0.265,是 40 天中的最高,在经验分布中的位置(CDF)为 0.999;它在第 20 天第 187 分钟(事件开始 37 分钟后)超过 90% 分位,最高值出现在次日开盘后(第 21 天第 11 分钟),因为 50 个桶约等于一天的成交量,VPIN 是一个滞后的滑动平均。对没有任何知情交易的波动率冲击,它也会上升,但幅度较小:本样本中升到 0.209(CDF 0.966,40 天中排第 4)。原因在两个事件摘要之后的两行:波动率冲击期间,每根一分钟线的 |2Φ−1||2\Phi – 1| 平均为 0.806,比知情事件期间的 0.618 还高;价格变化一旦相对于历史标准差变大,批量分类就会把一根线的大部分成交量分到一边。但分到哪一边逐根随机变化,在一个桶内大多相互抵消,所以 VPIN 的升幅小于知情事件。用真实买卖量计算的 VPIN 对波动率冲击几乎没有反应(最高 0.034,与 90% 分位 0.033 相当,40 天中排第 8)。最后一段用另外 20 个种子重复检查:两种 VPIN 在 20 次中都把知情事件排在第一;对波动率冲击,批量分类的 VPIN 在 20 次中有 14 次超过其 90% 分位(排名中位数为约 40 天中的第 11.5),用真实买卖量的 VPIN 只有 4 次(排名中位数 20.5),两者都从未把它排在第一。所以这种机械效应是系统性的,但幅度有限:本样本的第 4 名偏高,在单个样本中波动率冲击可能显眼,也可能不显眼。另一个细节是:「超过 90% 分位」本身并不罕见,在 36 个普通交易日中有 9 天的最高值超过它。图 4 画出了两种 VPIN 的全程。

模拟的 40 个交易日中的 VPIN。上:批量分类;下:真实买卖量(真实数据中不可得)。金色阴影为知情买入时段,紫色阴影为不含知情交易的波动率冲击,虚线为各自的 90% 分位(示意)。

这个程序不能判定闪崩之争的是非:它的数据是模拟的,参数是示意的。它只说明安德森与邦达连科所指出的机械关系确实可以出现:用价格变化来分类成交,会让「价格波动大」看起来像「订单流一边倒」。

价差分解与流动性撤出

度量毒性的另一种更直接的办法,是看每笔成交之后价格往哪里走。对一笔方向为 dd(买为 +1)、价格为 pp、成交时中间价为 mm 的交易,有效价差 2d(p−m)2d(p – m) 可以分解为已实现价差 2d(p−mt+h)2d(p – m_{t+h}) 与价格冲击 2d(mt+h−m)2d(m_{t+h} – m) 之和,hh 是一个事先选定的时间跨度。已实现价差是流动性提供者在 hh 之后实际留下的收益,价格冲击是成交中所含信息的大小。黄与斯托尔给出了把价差分解为订单处理、库存与逆向选择成分的一般方法 (Huang and Stoll 1997)。

下面的程序是作者的模型:每期价值变动 J=±1J = \pm 1(只有知情者事先知道)加公共噪声;做市商在价值上下各 ss 处报价;第二部分让噪声交易者对价差敏感,以概率 1−s/0.81 – s/0.8 参与交易,看做市商还能否找到保本的报价。

推导

# Effective spread = realized spread + price impact, in a model with toxic flow (author's
# toy model, in the spirit of Glosten-Milgrom). Each period the value moves by J = +-1
# (known in advance only to informed traders) plus public noise e ~ N(0, 1). A dealer
# quotes value +- s. A trade is informed with probability a (it buys iff J = +1);
# otherwise it is a noise trade (buy or sell with probability 1/2). Measures per trade,
# with d = +1 for a buy: effective 2 d (p - m), realized 2 d (p - m_next),
# price impact 2 d (m_next - m), where m_next is the value one period later.
# Part 2: noise traders are price-elastic, trading with probability 1 - s / 0.8, so
# the dealer must find a break-even half-spread; beyond some toxicity none exists.
import math, random, statistics

def measure(rng, a, s, n=200_000):
    eff, rs, pi = [], [], []
    for _ in range(n):
        J = 1 if rng.random() < 0.5 else -1
        d = J if rng.random() < a else (1 if rng.random() < 0.5 else -1)
        m_next = J + rng.gauss(0, 1)                  # value now normalised to 0
        p = d * s
        eff.append(2 * d * p); rs.append(2 * d * (p - m_next)); pi.append(2 * d * m_next)
    return statistics.fmean(eff), statistics.fmean(rs), statistics.fmean(pi), \
        statistics.stdev(rs)

def dealer_profit(s, a_rate, b_rate=1.0, smax=1.5):
    q = max(0.0, 1 - s / smax)                       # noise participation
    return b_rate * q * s + a_rate * (s - 1), b_rate * q + a_rate

if __name__ == "__main__":
    rng = random.Random(1997)
    print("half-spread s = 0.25 (effective spread 0.50), 200,000 simulated trades each")
    print("  informed share   effective   realized   impact    theory: realized  impact")
    for a in (0.0, 0.1, 0.25, 0.4):
        e, r, p, sd = measure(rng, a, 0.25)
        print(f"      {a:4.2f}          {e:6.3f}     {r:+7.3f}   {p:+6.3f}"
              f"            {0.5 - 2 * a:+6.3f}  {2 * a:+6.3f}")
    print(f"  sd of one trade's realized spread (share 0.40) {sd:.2f}; with 500 trades a"
          f" day,\n  the daily mean has s.e. {sd / math.sqrt(500):.3f}")
    print("break-even half-spread; noise traders trade with probability 1 - s / 0.8, so")
    print("they leave before the spread reaches 1 (where informed trading would stop):")
    print("   a      s*     noise participation   trades per period")
    for a in (0.05, 0.1, 0.2, 0.3, 0.35, 0.38, 0.4):
        root = next((i / 20000 * 0.8 for i in range(1, 20001)
                     if dealer_profit(i / 20000 * 0.8, a, smax=0.8)[0] >= 0), None)
        if root is None:
            print(f"  {a:4.2f}    none: no quote breaks even, the market shuts down")
        else:
            q = 1 - root / 0.8
            print(f"  {a:4.2f}   {root:.3f}        {q:.3f}                {q + a:.3f}")
    # max_s [(1 - s/0.8) s + a (s - 1)] >= 0  <=>  0.2 a^2 - 0.6 a + 0.2 >= 0
    a_star = (0.6 - 0.2 ** 0.5) / 0.4
    print(f"threshold (closed form): a* = (0.6 - sqrt(0.2)) / 0.4 = {a_star:.4f}")
# half-spread s = 0.25 (effective spread 0.50), 200,000 simulated trades each
#   informed share   effective   realized   impact    theory: realized  impact
#       0.00           0.500      +0.500   -0.000            +0.500  +0.000
#       0.10           0.500      +0.294   +0.206            +0.300  +0.200
#       0.25           0.500      +0.012   +0.488            +0.000  +0.500
#       0.40           0.500      -0.295   +0.795            -0.300  +0.800
#   sd of one trade's realized spread (share 0.40) 2.70; with 500 trades a day,
#   the daily mean has s.e. 0.121
# break-even half-spread; noise traders trade with probability 1 - s / 0.8, so
# they leave before the spread reaches 1 (where informed trading would stop):
#    a      s*     noise participation   trades per period
#   0.05   0.051        0.937                0.987
#   0.10   0.103        0.871                0.971
#   0.20   0.215        0.732                0.932
#   0.30   0.346        0.568                0.868
#   0.35   0.432        0.460                0.810
#   0.38   0.525        0.343                0.723
#   0.40    none: no quote breaks even, the market shuts down
# threshold (closed form): a* = (0.6 - sqrt(0.2)) / 0.4 = 0.3820

半价差固定为 0.25 时,有效价差恒为 0.50;知情比例从 0 升到 0.4,价格冲击从 0 升到 0.795(理论 2a2a),已实现价差从 +0.500 降到 −0.295(理论 0.5−2a0.5 – 2a),在知情比例 0.25 时归零。还要注意测量的噪声:单笔已实现价差的标准差为 2.70,一天 500 笔时日均值的标准误为 0.121,所以要可靠地分辨已实现价差的正负,需要的样本远多于一天。

第二部分重现了格罗斯滕与米尔格罗姆指出的市场关闭 (Glosten and Milgrom 1985)。知情到达率为 0.05 时,保本半价差为 0.051;为 0.35 时升到 0.432,噪声交易者的参与率降到 0.460;为 0.38 时保本半价差为 0.525。闭式解给出门槛 a*=(0.6−0.2)/0.4=0.3820a^* = (0.6 – \sqrt{0.2})/0.4 = 0.3820:知情到达率超过它时,任何报价都无法保本,做市商不再报价,市场关闭。在这个模型中,「流动性撤出」不需要做市商恐慌或违约,它是保本条件的数学结果;但这只是一个模型,不能据此断言某一次真实的闪崩就是这样发生的。

假说 · 尚未验证 · 撤单的毒性门槛

作者的假说(尚未确立): 在真实的限价订单簿中,最优价位上的挂单深度在已实现价差(用 60 秒跨度、在滚动窗口中计算)转为显著为负之后的几分钟内系统性下降,且下降幅度大于同等波动率上升而已实现价差未转负的时段。什么样的结果能证明它是错的: 在事先固定的股票、时段与匹配规则下,两类时段的深度变化之差的置信区间包含零。

本章小结

PIN 用每日买卖笔数的混合模型估计知情交易的概率;即使模型正确,60 天数据的估计也有约 ±0.04 的抽样误差,而教科书形式的似然在活跃股票上会溢出,林与柯估计近期约 44% 的估计可能因此向下偏倚。PIN 是否以信息不对称的身份被定价,有相反的证据。VPIN 在成交量时间中计算订单不平衡,计算简单,但批量分类可能把波动率的上升误读为订单流的一边倒,这与安德森与邦达连科的批评一致。闪崩前「逆向选择撤单」是一种有争议的机制解释,不是已确立的因果。价差分解显示,毒性上升时已实现价差转负,在价格弹性的噪声交易下,超过一个门槛后市场会关闭。

参考文献

Andersen, Torben G., and Oleg Bondarenko. 2014a. “Reflecting on the VPIN Dispute.” Journal of Financial Markets 17: 53–64. https://doi.org/10.1016/j.finmar.2013.08.002.
Andersen, Torben G., and Oleg Bondarenko. 2014b. “VPIN and the Flash Crash.” Journal of Financial Markets 17: 1–46. https://doi.org/10.1016/j.finmar.2013.05.005.
Duarte, Jefferson, and Lance Young. 2009. “Why Is PIN Priced?” Journal of Financial Economics 91 (2): 119–38.
Easley, David, Soeren Hvidkjaer, and Maureen O’Hara. 2002. “Is Information Risk a Determinant of Asset Returns?” Journal of Finance 57 (5): 2185–221. https://doi.org/10.1111/1540-6261.00493.
Easley, David, Nicholas M. Kiefer, Maureen O’Hara, and Joseph B. Paperman. 1996. “Liquidity, Information, and Infrequently Traded Stocks.” Journal of Finance 51 (4): 1405–36.
Easley, David, Marcos M. López de Prado, and Maureen O’Hara. 2011. “The Microstructure of the ‘Flash Crash’: Flow Toxicity, Liquidity Crashes, and the Probability of Informed Trading.” Journal of Portfolio Management 37 (2): 118–28.
Easley, David, Marcos M. López de Prado, and Maureen O’Hara. 2012. “Flow Toxicity and Liquidity in a High-Frequency World.” Review of Financial Studies 25 (5): 1457–93.
Easley, David, Marcos M. López de Prado, and Maureen O’Hara. 2014. “VPIN and the Flash Crash: A Rejoinder.” Journal of Financial Markets 17: 47–52. https://doi.org/10.1016/j.finmar.2013.06.007.
Easley, David, Marcos M. López de Prado, and Maureen O’Hara. 2016. “Discerning Information from Trade Data.” Journal of Financial Economics 120 (2): 269–85.
Glosten, Lawrence R., and Paul R. Milgrom. 1985. “Bid, Ask and Transaction Prices in a Specialist Market with Heterogeneously Informed Traders.” Journal of Financial Economics 14 (1): 71–100. https://doi.org/10.1016/0304-405X(85)90044-3.
Huang, Roger D., and Hans R. Stoll. 1997. “The Components of the Bid-Ask Spread: A General Approach.” Review of Financial Studies 10 (4): 995–1034.
Kirilenko, Andrei, Albert S. Kyle, Mehrdad Samadi, and Tugkan Tuzun. 2017. “The Flash Crash: High-Frequency Trading in an Electronic Market.” Journal of Finance 72 (3): 967–98.
Lee, Charles M. C., and Mark J. Ready. 1991. “Inferring Trade Direction from Intraday Data.” Journal of Finance 46 (2): 733–46.
Lin, Hsiou-Wei William, and Wen-Chyan Ke. 2011. “A Computing Bias in Estimating the Probability of Informed Trading.” Journal of Financial Markets 14 (4): 625–40.
O’Hara, Maureen. 2015. “High Frequency Market Microstructure.” Journal of Financial Economics 116 (2): 257–70.
U.S. Commodity Futures Trading Commission and U.S. Securities and Exchange Commission. 2010. Findings Regarding the Market Events of May 6, 2010: Report of the Staffs of the CFTC and SEC to the Joint Advisory Committee on Emerging Regulatory Issues. CFTC; SEC.

Fan, Y. (2026). High-Frequency Limit Order Book Microstructure, Hawkes Self-Exciting Point Processes and Adverse-Selection Flow Toxicity: From the Avellaneda–Stoikov Market-Making Equations to VPIN, Read Beside Classical Chinese Thought on Market Equilibrium [高频限价订单簿微观结构、霍克斯自激点过程与逆向选择毒流] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.23828065 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).