What does Order Books, Hawkes Processes and Toxic Flow conclude, in numbers, about “Book Imbalance and Queues: Order Flow Imbalance, Queue Imbalance and Queue Position”?

Answer: Order flow imbalance (OFI) is the net effect of events at the best quotes over an interval; it is close to linear in contemporaneous mid-price changes, with an average \(R^2\) of 65 % in CKS and a slope roughly inversely proportional to depth; it is not queue imbalance. Queue imbalance is related to the direction of the next price move, but non-linearly, and the relation depends on the absolute sizes of the two queues. Queue position determines how adversely selected a fill is: in the author's model a buy order at the back of the queue sees the price fall after its fill with probability 0.551, and earns about 20 % less on average than one at the front.

Scope of the numbers: Why does a market maker quote a spread? Why do orders arrive in clusters? Can "toxic" order flow be measured from trade data? This book presents mathematical models for teaching and research and is not investment or trading advice. Marked boxes separate published evidence, runnable Python calculations (16 programs), classical sources and the author's models and hypotheses; all data in the book are fictional or simulated.

中文版

Data table

The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 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
519,819 0.0779 0.711 0.0901 0.114 0.389
205,217 0.0254 0.644 0.0187 0.028 0.508
implied exponent in beta ~ D^-lambda: lambda0.81
exact P(next move up | bid queue x, ask queue y):
x3, y 1: imbalance +0.50 P(up) 0.802
x6, y 2: imbalance +0.50 P(up) 0.818
x 30, y 10: imbalance +0.50 P(up) 0.885
x1, y 1: imbalance +0.00 P(up) 0.500
x 10, y 10: imbalance +0.00 P(up) 0.500
x1, y 3: imbalance -0.50 P(up) 0.198
x 10, y 30: imbalance -0.50 P(up) 0.115
simulated (D5): 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)

Key formula

\[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},\]
Show the full program
# 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)")

Single source and citation

Fan, Y. (2026). High-Frequency Limit Order Book Microstructure, Hawkes Self-Exciting Point Processes and Adverse-Selection Flow Toxicity (Version 1.0.0), Chapter 5: Book Imbalance and Queues: Order Flow Imbalance, Queue Imbalance and Queue Position. 5D Library. https://doi.org/10.5281/zenodo.23828065

DOI: 10.5281/zenodo.23828065 · Read the monograph · 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}
}

Other chapter answers in this book