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

第五章 盘口不平衡与排队:订单流不平衡、挂单量不平衡与排队位置

限价订单簿的基本事件

在一个限价订单簿中,最优买价与最优卖价上排着若干挂单,按「价格优先、时间优先」的规则成交。改变盘口的事件只有三类:新的限价单加入队列,已有的限价单被撤销,市价单从队首吃掉挂单。康特(Cont)、斯托伊科夫与塔利贾把这三类事件写成一个连续时间的马尔可夫模型,用来计算价格变动、队列耗尽等事件的条件概率 (Cont et al. 2010);布绍等人的专著系统地讨论了这类模型与实证规律 (Bouchaud et al. 2018)。本章讨论两个容易混淆的量:订单流不平衡(一段时间内盘口各类事件的净效果)与挂单量不平衡(某一时刻两边队列的相对大小)。

订单流不平衡与同期价格变化

证据

康特、库卡诺夫与斯托伊科夫定义了每个事件 nn 对最优价位的贡献 (Cont et al. 2014):

en=𝟙{PnB≥Pn−1B}qnB−𝟙{PnB≤Pn−1B}qn−1B−𝟙{PnA≤Pn−1A}qnA+𝟙{PnA≥Pn−1A}qn−1A,e_n = \mathbb{1}\{P^B_n \ge P^B_{n-1}\}\,q^B_n – \mathbb{1}\{P^B_n \le P^B_{n-1}\}\,q^B_{n-1} – \mathbb{1}\{P^A_n \le P^A_{n-1}\}\,q^A_n + \mathbb{1}\{P^A_n \ge P^A_{n-1}\}\,q^A_{n-1},

其中 PB,qBP^B, q^B 与 PA,qAP^A, q^A 为最优买价、卖价及其挂单量。买方挂单增加或卖方挂单减少为正,反之为负;一段时间内的 ene_n 之和就是订单流不平衡(OFI)。他们用 2010 年 4 月纽约证券交易所 TAQ 数据中随机抽取的 50 只标普 500 成分股,在 10 秒的区间上回归 ΔPk=α+βOFIk+εk\Delta P_k = \alpha + \beta\,\mathrm{OFI}_k + \varepsilon_k(ΔP\Delta P 以最小报价单位计),平均 R2R^2 为 65%;只用成交不平衡(主动买量减主动卖量)时平均 R2R^2 为 32%,二者同时放入时成交不平衡的解释力基本消失。斜率可写成 βi=c/ADiλ\beta_i = c/AD_i^{\lambda},ADiAD_i 为平均深度,λ\lambda 的估计平均约 0.98,50 只股票中有 35 只不能拒绝 λ=1\lambda = 1,即价格冲击约与深度成反比。他们还指出,在一定的标度假设下,OFI 近似等于成交量平方根的带噪声倍数,因此价格与成交量之间的「平方根」关系可以作为聚合的统计结果出现,而且比基于 OFI 的关系噪声更大、更不稳健。

作者框架把这项研究写成「订单簿不平衡度与短期中间价变动的线性关系」。核对后需要分清两点。第一,CKS 研究的是订单流不平衡,是一段时间内的流量,不是挂单量的存量之比。第二,它描述的是同一时段内的价格变化,是一种同期的「解释」,不是对未来价格的预测。至于元订单的平方根冲击律,第 39 本已经讨论过它的实证与适用范围,这里只回顾。

挂单量不平衡与下一次价格变动

静态的挂单量不平衡 I=(qB−qA)/(qB+qA)I = (q^B – q^A)/(q^B + q^A) 与下一次中间价变动的方向有关:买方队列相对越厚,下一次变动越可能向上。

证据

康特与德拉拉尔(de Larrard)的模型把最优买卖价的两个队列看作两个独立的生灭过程:限价单以强度 λ\lambda 到达,撤单以强度 θ\theta 发生,市价单以强度 μ\mu 到达;价差恒为一个最小单位,某一队列耗尽时价格移动一格,两个队列按一个固定分布重新抽取 (Cont and Larrard 2013)。在这个模型中,下一次价格上涨的概率是卖方队列先于买方队列耗尽的概率,它取决于两个队列的绝对大小。古尔德与博纳特用 2014 年纳斯达克 10 只流动性好的股票(LOBSTER 数据,252 个交易日)发现,挂单量不平衡对下一次中间价变动的方向有显著的预测力,在大最小报价单位的股票(价差常常只有一格、队列很长)上尤其明显 (Gould and Bonart 2015)。

下面的程序实现一个康特—德拉拉尔式的一档订单簿:每个队列上限价单、撤单与市价单的强度分别为 1.2、0.6 与 0.8(每秒),队列耗尽时价格移动一格、两个队列从 1 到 2D−12D-1 均匀重抽(平均深度 DD)。第一部分计算 10 秒区间的 OFI 与成交不平衡(TI)回归;第二部分用高斯—赛德尔迭代精确计算「在买队列 xx、卖队列 yy 时下一次变动向上」的概率,并与模拟中按不平衡分组的频率对照。

推导

# A level-1 order book in the spirit of Cont & de Larrard (2013): unit orders; at each
# best queue, limit orders arrive at rate LAM, cancellations at rate TH (while the queue
# is non-empty) and market orders at rate MU. When a queue empties, the price moves one
# tick (spread stays one tick); both queues are then redrawn uniformly from 1..2D-1.
# Part 1: order flow imbalance (OFI) of Cont, Kukanov & Stoikov (2014) per 10-second
# interval, regression of mid-price changes (ticks) on OFI and on trade imbalance (TI),
# for two depths D. Part 2: probability that the next price move is up, given the two
# queue sizes, computed exactly (two competing birth-death queues) and compared with the
# queue imbalance I = (qb - qa) / (qb + qa).
import math, random, statistics

LAM, TH, MU = 1.2, 0.6, 0.8

def simulate(rng, D, T):
    t, pb, qb, qa = 0.0, 0, D, D; rate = 2 * (LAM + TH + MU); out = []
    while t < T:
        t += rng.expovariate(rate); u = rng.random() * rate
        side, kind = ("b", "a")[u >= rate / 2], u % (rate / 2)
        kind = "L" if kind < LAM else ("C" if kind < LAM + TH else "M")
        old = (pb, qb, pb + 1, qa)
        if side == "b":
            if kind == "L":
                qb += 1
            elif qb > 0 and (kind == "M" or kind == "C"):
                qb -= 1
        else:
            if kind == "L":
                qa += 1
            elif qa > 0 and (kind == "M" or kind == "C"):
                qa -= 1
        tr = (1 if side == "a" else -1) if kind == "M" else 0  # market buy hits the ask
        if qb == 0:
            pb -= 1; qb, qa = rng.randint(1, 2 * D - 1), rng.randint(1, 2 * D - 1)
        elif qa == 0:
            pb += 1; qb, qa = rng.randint(1, 2 * D - 1), rng.randint(1, 2 * D - 1)
        new = (pb, qb, pb + 1, qa)
        e = ((new[0] >= old[0]) * new[1] - (new[0] <= old[0]) * old[1]
             - (new[2] <= old[2]) * new[3] + (new[2] >= old[2]) * old[3])
        out.append((t, e, tr, pb, qb, qa))
    return out

def regress(x, y):
    mx, my = statistics.fmean(x), statistics.fmean(y)
    sxy = sum((a - mx) * (b - my) for a, b in zip(x, y))
    sxx = sum((a - mx) ** 2 for a in x)
    b = sxy / sxx; r2 = sxy * sxy / sxx / sum((v - my) ** 2 for v in y)
    return b, r2

def intervals(ev, h=10.0):
    ofi, ti, dp, k, cur, pb_last = [], [], [], 0, [0, 0, 0], 0
    for t, e, tr, pb, qb, qa in ev:
        while t > (k + 1) * h:
            ofi.append(cur[0]); ti.append(cur[1]); dp.append(pb_last - cur[2])
            cur = [0, 0, pb_last]; k += 1
        cur[0] += e; cur[1] += tr; pb_last = pb
    return ofi, ti, dp

def p_up(N=80):
    """P(ask queue empties before bid queue) for queue sizes (x, y), x, y < N."""
    up, dn = LAM, TH + MU; u = [[0.0] * (N + 1) for _ in range(N + 1)]
    for y in range(1, N + 1):
        u[0][y] = 0.0
    for x in range(1, N + 1):
        u[x][0] = 1.0
    for _ in range(3000):                              # Gauss-Seidel sweeps
        for x in range(1, N + 1):
            for y in range(1, N + 1):
                xp, yp = min(x + 1, N), min(y + 1, N)
                u[x][y] = (up * u[xp][y] + dn * u[x - 1][y] + up * u[x][yp]
                           + dn * u[x][y - 1]) / (2 * (up + dn))
    return u

if __name__ == "__main__":
    rng = random.Random(2014)
    print(f"rates per queue: limit {LAM}, cancel {TH}, market {MU}; 10-second intervals")
    print("   D    price moves   OFI: beta    R^2     TI: beta    R^2    beta x D")
    betas = []
    for D in (5, 20):
        ev = simulate(rng, D, 300_000.0)
        ofi, ti, dp = intervals(ev)
        b, r2 = regress(ofi, dp); bt, r2t = regress(ti, dp)
        moves = sum(abs(a) for a in dp); betas.append(b)
        print(f"  {D:3d}    {moves:9,d}      {b:.4f}   {r2:.3f}      {bt:.4f}   {r2t:.3f}"
              f"     {b * D:.3f}")
    print(f"   implied exponent in beta ~ D^-lambda: lambda ="
          f" {math.log(betas[0] / betas[1]) / math.log(4):.2f}")
    u = p_up()
    print("exact P(next move up | bid queue x, ask queue y):")
    for x, y in ((3, 1), (6, 2), (30, 10), (1, 1), (10, 10), (1, 3), (10, 30)):
        I = (x - y) / (x + y)
        print(f"   x {x:2d}, y {y:2d}: imbalance {I:+.2f}  P(up) {u[x][y]:.3f}")
    ev = simulate(rng, 5, 300_000.0)
    bins, pend, nxt, prev = {}, None, 10.0, ev[0]
    for t, e, tr, pb, qb, qa in ev:                       # sample the book every 10 s,
        if pend is not None and pb != pend[1]:            # then wait for the next move
            bins.setdefault(pend[0], []).append(pb > pend[1]); pend = None
        if t >= nxt and pend is None:
            I = (prev[4] - prev[5]) / (prev[4] + prev[5])
            pend = (min(4, int((I + 1) / 0.4)), prev[3]); nxt = t + 10.0
        prev = (t, e, tr, pb, qb, qa)
    print("simulated (D = 5): share of up-moves by queue imbalance sampled every 10 s")
    for k in sorted(bins):
        v = bins[k]
        lo = -1 + 0.4 * k
        print(f"   I in [{lo:+.1f}, {lo + 0.4:+.1f}):  {statistics.fmean(v):.3f}"
              f"  ({len(v):,} moves)")
# rates per queue: limit 1.2, cancel 0.6, market 0.8; 10-second intervals
#    D    price moves   OFI: beta    R^2     TI: beta    R^2    beta x D
#     5       19,819      0.0779   0.711      0.0901   0.114     0.389
#    20        5,217      0.0254   0.644      0.0187   0.028     0.508
#    implied exponent in beta ~ D^-lambda: lambda = 0.81
# exact P(next move up | bid queue x, ask queue y):
#    x  3, y  1: imbalance +0.50  P(up) 0.802
#    x  6, y  2: imbalance +0.50  P(up) 0.818
#    x 30, y 10: imbalance +0.50  P(up) 0.885
#    x  1, y  1: imbalance +0.00  P(up) 0.500
#    x 10, y 10: imbalance +0.00  P(up) 0.500
#    x  1, y  3: imbalance -0.50  P(up) 0.198
#    x 10, y 30: imbalance -0.50  P(up) 0.115
# simulated (D = 5): share of up-moves by queue imbalance sampled every 10 s
#    I in [-1.0, -0.6):  0.034  (3,000 moves)
#    I in [-0.6, -0.2):  0.212  (4,307 moves)
#    I in [-0.2, +0.2):  0.509  (6,621 moves)
#    I in [+0.2, +0.6):  0.775  (3,774 moves)
#    I in [+0.6, +1.0):  0.958  (3,464 moves)

在这个模型中,OFI 对同期价格变化的 R2R^2 为 0.711(D=5D = 5)与 0.644(D=20D = 20),成交不平衡只有 0.114 与 0.028,定性上与 CKS 的实证结果一致。深度从 5 增加到 20,OFI 的斜率从 0.0779 降到 0.0254;隐含的指数 λ=0.81\lambda = 0.81,小于 CKS 估计的约 1,说明「斜率与深度成反比」在这个简化模型中只是近似成立。

第二部分说明不平衡本身不是充分统计量。不平衡同为 +0.50 时,队列为 (3, 1) 的上涨概率是 0.802,(6, 2) 是 0.818,(30, 10) 是 0.885;不平衡同为 −0.50 时,(1, 3) 是 0.198,(10, 30) 是 0.115。两边都更厚时,「多出来」的那部分挂单需要更长时间才能被吃掉,方向的信号反而更强。模拟中按不平衡分组的上涨比例从 0.034(I<−0.6I < -0.6)单调上升到 0.958(I≥0.6I \ge 0.6),中间一组为 0.509。这个关系是非线性的(S 形),作者框架中「线性关系」的说法只适用于 OFI 与同期价格变化。

排队位置与逆向选择

挂单的位置也有信息含义。排在队首的买单很快成交;排在队尾的买单只有当前面的挂单都被吃掉之后才成交,而这往往发生在卖压很大、队列即将耗尽、价格即将下跌的时候。下面的程序是作者的模型:在上述一档订单簿中,我们的买单排在 10 个挂单的第 kk 位;新挂单排在我们后面,撤单随机撤掉其他挂单,市价卖单从队首吃起。如果卖方队列先耗尽,价格上涨一格,我们的买单没有成交;如果我们成交了,就等到下一次中间价变动:上涨时相对买入价盈利 1.5 格,下跌时亏损 0.5 格。

推导

# Queue position and adverse selection of a resting buy order (author's toy model on the
# level-1 dynamics of p10: limit orders 1.2, cancellations 0.6, market orders 0.8 per
# second per side, unit orders, one-tick spread). Our order sits at position k in a bid
# queue of 10; new orders join behind it; a cancellation removes a random other order;
# market sells consume the queue from the front. Outcomes: the ask queue empties first
# (price ticks up, our order is left behind) or our order is filled. After a fill we wait
# for the next mid change: up -> +1.5 ticks against our price, down -> -0.5 ticks.
import random, statistics

LAM, TH, MU = 1.2, 0.6, 0.8

def one(rng, k, Q=10, qa0=10):
    ahead, behind, qa = k - 1, Q - k, qa0; filled = False
    R = 2 * (LAM + TH + MU)
    while True:
        u = rng.random() * R
        if u < LAM:                                    # bid side: a new limit order
            behind += 1
        elif u < LAM + TH:                             # a cancellation (not ours)
            n = ahead + behind
            if n > 0:
                if rng.random() * n < ahead:
                    ahead -= 1
                else:
                    behind -= 1
        elif u < LAM + TH + MU:                        # market sell hits the bid
            if not filled:
                if ahead > 0:
                    ahead -= 1
                else:
                    filled = True
            elif behind > 0:
                behind -= 1
        else:                                          # ask side
            v = u - (LAM + TH + MU)
            if v < LAM:
                qa += 1
            elif qa > 0:
                qa -= 1
        if qa == 0:
            return ("up", filled)                      # price ticks up
        if filled and ahead + behind == 0:
            return ("down", True)                      # bid queue gone after our fill

if __name__ == "__main__":
    rng = random.Random(2016)
    print("bid queue 10, ask queue 10; 40,000 orders per row")
    print("  position  P(filled)  P(next move down | filled)  P&L: per fill  per order")
    for k in (1, 3, 5, 8, 10):
        res = [one(rng, k) for _ in range(40_000)]
        fills = [r for r in res if r[1]]
        pdn = statistics.fmean(r[0] == "down" for r in fills)
        pnl = 1.5 * (1 - pdn) - 0.5 * pdn
        print(f"     {k:2d}       {len(fills) / len(res):.3f}              {pdn:.3f}"
              f"                 {pnl:+.3f}       {pnl * len(fills) / len(res):+.3f}")
    print("(no adverse selection: P(down | filled) = 0.5 and +0.5 tick per fill)")
# bid queue 10, ask queue 10; 40,000 orders per row
#   position  P(filled)  P(next move down | filled)  P&L: per fill  per order
#       1       0.999              0.500                 +0.500       +0.500
#       3       0.991              0.505                 +0.489       +0.485
#       5       0.972              0.515                 +0.469       +0.456
#       8       0.934              0.536                 +0.429       +0.401
#      10       0.905              0.551                 +0.398       +0.360
# (no adverse selection: P(down | filled) = 0.5 and +0.5 tick per fill)

排在第 1 位的买单几乎一定成交(0.999),成交后下一次变动向下的概率为 0.500,即没有逆向选择,每笔平均赚半个价差(+0.500 格)。排在第 10 位时,成交概率降到 0.905,成交后下跌的概率升到 0.551,每笔成交的平均收益降到 +0.398 格,按每张挂单计算为 +0.360 格。排得越靠后,成交越「有条件」:正是那些让我们成交的大卖压,也预示着价格下跌。这是第一章逆向选择在排队层面的表现,也说明了为什么在价格—时间优先的市场里,排队位置本身有价值。

注

关于冰山订单。 作者框架在第六章中提到「冰山订单拆分」。冰山订单是只显示一部分数量的限价单,显示部分成交后再补充显示;在价格—时间优先的规则下,补充的显示部分通常排到队尾,所以它以排队位置为代价换取较少的信息暴露。埃塞尔与门希给出了在成交概率与暴露成本之间权衡的最优显示量模型 (Esser and Mönch 2007)。这是限价单的显示策略问题,与第六章阿尔姆格伦—克里斯的拆单时间表是不同的问题。

假说 · 尚未验证 · 不平衡的绝对规模

作者的假说(尚未确立): 在大最小报价单位的股票中,用两边队列的绝对大小(而不只是不平衡比例)预测下一次中间价变动方向,样本外的对数损失比只用不平衡比例的模型低。什么样的结果能证明它是错的: 在事先固定的股票、时段与模型设定下,两种模型样本外对数损失之差的置信区间包含零。

本章小结

订单流不平衡(OFI)是一段时间内最优价位各类事件的净效果,与同期中间价变化近似线性,CKS 报告的平均 R2R^2 为 65%,斜率约与深度成反比;它不是挂单量不平衡。挂单量不平衡与下一次价格变动的方向有关,但关系是非线性的,并且依赖两边队列的绝对大小。排队位置决定了成交时的逆向选择程度:在作者的模型中,排在队尾的买单成交后价格下跌的概率为 0.551,平均收益比队首低约 20%。

参考文献

Bouchaud, Jean-Philippe, Julius Bonart, Jonathan Donier, and Martin Gould. 2018. Trades, Quotes and Prices: Financial Markets Under the Microscope. Cambridge University Press. https://doi.org/10.1017/9781316659335.
Cont, Rama, Arseniy Kukanov, and Sasha Stoikov. 2014. “The Price Impact of Order Book Events.” Journal of Financial Econometrics 12 (1): 47–88.
Cont, Rama, and Adrien de Larrard. 2013. “Price Dynamics in a Markovian Limit Order Market.” SIAM Journal on Financial Mathematics 4 (1): 1–25.
Cont, Rama, Sasha Stoikov, and Rishi Talreja. 2010. “A Stochastic Model for Order Book Dynamics.” Operations Research 58 (3): 549–63. https://doi.org/10.1287/opre.1090.0780.
Esser, Angelika, and Burkart Mönch. 2007. “The Navigation of an Iceberg: The Optimal Use of Hidden Orders.” Finance Research Letters 4 (2): 68–81.
Gould, Martin D., and Julius Bonart. 2015. Queue Imbalance as a One-Tick-Ahead Price Predictor in a Limit Order Book. arXiv preprint arXiv:1512.03492.

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