关于「盘口不平衡与排队:订单流不平衡、挂单量不平衡与排队位置」,《订单簿微观结构与毒流》给出的定量结论是什么?
结论:订单流不平衡(OFI)是一段时间内最优价位各类事件的净效果,与同期中间价变化近似线性,CKS 报告的平均 \(R^2\) 为 65%,斜率约与深度成反比;它不是挂单量不平衡。挂单量不平衡与下一次价格变动的方向有关,但关系是非线性的,并且依赖两边队列的绝对大小。排队位置决定了成交时的逆向选择程度:在作者的模型中,排在队尾的买单成交后价格下跌的概率为 0.551,平均收益比队首低约 20%。
数据口径:做市商为什么要留出买卖价差?订单为什么成簇到来?能否从成交数据中度量「有毒」的订单流?本书是教学与研究用的数学模型,不是投资或交易建议。 第八章给出逆向选择、订单流、库存与执行四步核查表,以及一项预注册的模拟撮合实验方案:在独立第三方冻结的模拟器中,比较库存偏置的阿韦拉内达—斯托伊科夫报价与固定对称报价在毒性脉冲下的跨会话夏普比率(唯一主要结局为二者之差,最小关注效应 0.31,8,600 个配对会话,双盲运行,判定规则写成代码)。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 20
| 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) |
核心公式
\[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},\]
查看完整验算程序
# 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)")唯一数据源与引用
范雅福(Fan, Y.). (2026). 《高频限价订单簿微观结构、霍克斯自激点过程与逆向选择毒流》第 5 章「盘口不平衡与排队:订单流不平衡、挂单量不平衡与排队位置」(版本 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.23828065
DOI: 10.5281/zenodo.23828065 · 阅读本章所在专著 · 5DL-B-045 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026045,
author = {Fan, Yafu},
title = {High-Frequency Limit Order Book Microstructure, Hawkes Self-Exciting Point Processes and Adverse-Selection Flow Toxicity},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
doi = {10.5281/zenodo.23828065},
url = {https://doi.org/10.5281/zenodo.23828065}
}