5D Library › Liquidation Cascades, Order-Book Depth Depletion and Cointegrated Statistical Arbitrage · 中文
Chapter 3 Liquidation Cascades, Branching Processes and Hawkes Self-Exciting Point Processes
Events that trigger events
Earthquakes have aftershocks, and aftershocks have aftershocks of their own. The self-exciting point process Hawkes introduced in 1971 (Hawkes 1971) was designed for exactly this kind of “events triggering events”. Let be the event intensity at time (the expected number of events per unit time):
is the exogenous baseline intensity: events unrelated to the past, brought by outside news. Each event makes the intensity jump by , after which the jump decays at rate .
Hawkes and Oakes gave its branching representation in 1974 (Hawkes and Oakes 1974): exogenous events arrive like “immigrants” at rate , and every event, exogenous or triggered, independently produces on average “offspring”, which produce offspring in turn. is the branching ratio. When , each immigrant’s family has on average events, the long-run average intensity is , and a fraction of all events is triggered, “endogenous”. is the critical point: every family still dies out with certainty, but its mean size diverges (); only when (supercritical) does a family have a positive probability of never dying out.
Simulate a Hawkes process with Ogata’s 1981 thinning algorithm (Ogata 1981): between events the intensity can only decay, so its current value is an upper bound until the next accepted event; draw a candidate time from it and accept with probability . For four branching ratios, is set so that the theoretical mean intensity is 1; the branching tree is also simulated directly to count family sizes.
Calculation
# Exponential-kernel Hawkes process by Ogata (1981) thinning; branching n = alpha/beta.
# Theory (n < 1): rate mu/(1-n), cluster mean 1/(1-n), long-window Fano 1/(1-n)^2.
import math, random
def ogata(mu, alpha, beta, T, rng):
t, excite, ts = 0.0, 0.0, [] # excite = sum of alpha exp(-beta (t - t_i))
while True:
lam_bar = mu + excite
w = rng.expovariate(lam_bar)
t += w
if t > T: return ts
excite *= math.exp(-beta * w)
if rng.random() * lam_bar <= mu + excite:
ts.append(t); excite += alpha
def fano(ts, T, width): # variance / mean of counts in windows
k = int(T // width); c = [0] * k
for t in ts:
j = int(t // width)
if j < k: c[j] += 1
m = sum(c) / k
return sum((x - m) ** 2 for x in c) / k / m
def cluster_sizes(n, reps, rng): # Galton-Watson tree, Poisson(n) children
out = []
for _ in range(reps):
size, todo = 1, 1
while todo and size < 10 ** 6:
todo -= 1
k, p, u = 0, math.exp(-n), rng.random()
c = p
while u > c:
k += 1; p *= n / k; c += p
size += k; todo += k
out.append(size)
return out
rng = random.Random(1971)
T, beta = 20000.0, 1.0
print(" n | events rate | Fano(100) sim / limit | cluster mean sim / theory"
" | P(size>=100)")
for n in (0.0, 0.5, 0.8, 0.95):
mu = 1.0 - n # keeps the theoretical mean rate at 1 per unit
ts = ogata(mu, n * beta, beta, T, rng)
cs = cluster_sizes(n, 20000, rng)
big = sum(c >= 100 for c in cs) / len(cs)
print(f" {n:4.2f} | {len(ts):6d} {len(ts) / T:5.3f} |"
f" {fano(ts, T, 100.0):6.1f} / {1 / (1 - n) ** 2:5.0f} |"
f" {sum(cs) / len(cs):6.2f} / {1 / (1 - n):6.2f} | {big:6.2%}")
# n | events rate | Fano(100) sim / limit | cluster mean sim / theory | P(size>=100)
# 0.00 | 19986 0.999 | 0.9 / 1 | 1.00 / 1.00 | 0.00%
# 0.50 | 20107 1.005 | 4.3 / 4 | 2.00 / 2.00 | 0.00%
# 0.80 | 19776 0.989 | 28.3 / 25 | 4.96 / 5.00 | 0.14%
# 0.95 | 20173 1.009 | 306.2 / 400 | 20.23 / 20.00 | 4.08%For all four branching ratios the mean intensity matches the theoretical value of 1, and the mean family size matches (theory 20 at , simulation 20.2). Beyond the averages, however, much changes. In windows of length 100, the variance-to-mean ratio of counts (the Fano factor) rises from about 1 for the Poisson process to about 28 at and over 300 at (the long-window limit is ): events cluster more and more. The tail of family sizes thickens as well: at only 0.14 % of families reach 100 events, at , 4 %. With the same mean intensity, a system near criticality occasionally erupts in enormous chains.
Note
Relation to Books 20 and 28. Book 20 used the sandpile model to discuss self-organised criticality and power laws; Book 28 discussed critical slowing down, early-warning signals and their limits. This chapter does not repeat them; it discusses only how the branching ratio of a point process is estimated and why it is hard to estimate well.
Estimating the branching ratio
The log-likelihood of an exponential-kernel Hawkes process can be computed recursively (Ozaki 1979 (Ozaki 1979)):
Maximise the likelihood with a home-made simplex (Nelder–Mead) search from the standard library. First fit genuine Hawkes data (), then two kinds of Poisson data with no self-excitation at all: one with constant intensity, the other with intensity switching between 0.5 and 2.0.
Calculation
# Hawkes maximum likelihood (Ozaki 1979 recursion), Nelder-Mead over
# (log mu, logit n, log beta). Fitted to Hawkes data and to Poisson data with no
# self-excitation, constant or switching between rates 0.5 and 2.0.
import math, random
def ogata(mu, alpha, beta, T, rng):
t, ex, ts = 0.0, 0.0, []
while True:
lb = mu + ex; w = rng.expovariate(lb); t += w
if t > T: return ts
ex *= math.exp(-beta * w)
if rng.random() * lb <= mu + ex: ts.append(t); ex += alpha
def switching_poisson(rates, seg, T, rng):
t, ts = 0.0, []
while t < T:
k = int(t // seg); end = (k + 1) * seg
w = rng.expovariate(rates[k % len(rates)])
if t + w >= end: t = end; continue # memoryless: restart at the regime boundary
t += w
if t < T: ts.append(t)
return ts
def loglik(p, ts, T):
mu, n, beta = math.exp(p[0]), 1 / (1 + math.exp(-p[1])), math.exp(p[2])
alpha, A, prev, s = n * beta, 0.0, None, 0.0
for t in ts:
if prev is not None: A = math.exp(-beta * (t - prev)) * (1 + A)
s += math.log(mu + alpha * A); prev = t
comp = mu * T + n * sum(1 - math.exp(-beta * (T - t)) for t in ts)
return s - comp
def nelder_mead(f, x0, step=0.5, iters=250):
pts = [list(x0)] + [[x + (step if i == j else 0) for j, x in enumerate(x0)]
for i in range(len(x0))]
vals = [f(p) for p in pts]
for _ in range(iters):
order = sorted(range(len(pts)), key=lambda i: vals[i])
pts = [pts[i] for i in order]; vals = [vals[i] for i in order]
c = [sum(p[j] for p in pts[:-1]) / (len(pts) - 1) for j in range(len(x0))]
def at(k): return [c[j] + k * (pts[-1][j] - c[j]) for j in range(len(x0))]
r = at(-1); fr = f(r)
if fr < vals[0]:
e = at(-2); 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 = at(0.5); fk = f(k)
if fk < vals[-1]: pts[-1], vals[-1] = k, fk
else:
pts = [pts[0]] + [[(a + b) / 2 for a, b in zip(pts[0], p)]
for p in pts[1:]]
vals = [vals[0]] + [f(p) for p in pts[1:]]
return pts[0]
def fit(ts, T):
p = nelder_mead(lambda q: -loglik(q, ts, T), [math.log(len(ts) / T / 2), 0.0, 0.0])
return math.exp(p[0]), 1 / (1 + math.exp(-p[1])), math.exp(p[2])
def row(label, ts, T):
mu, n, b = fit(ts, T)
print(f"{label:38s} | {len(ts):6d} | {mu:5.3f} {n:5.2f} {b:6.3f}")
rng = random.Random(1979)
T = 4000.0
print("data | events | fitted mu n beta")
for rep in range(3):
row(f"Hawkes, mu 0.3, n 0.70, beta 1.0 (#{rep + 1})", ogata(0.3, 0.7, 1.0, T, rng), T)
row("Poisson, constant rate 1.0", switching_poisson((1.0,), T, T, rng), T)
for seg in (400.0, 40.0):
for rep in range(2):
row(f"Poisson, 0.5/2.0, regimes of {seg:3.0f} (#{rep + 1})",
switching_poisson((0.5, 2.0), seg, T, rng), T)
# data | events | fitted mu n beta
# Hawkes, mu 0.3, n 0.70, beta 1.0 (#1) | 4104 | 0.298 0.71 0.946
# Hawkes, mu 0.3, n 0.70, beta 1.0 (#2) | 3803 | 0.284 0.70 0.997
# Hawkes, mu 0.3, n 0.70, beta 1.0 (#3) | 4290 | 0.325 0.70 1.052
# Poisson, constant rate 1.0 | 4102 | 1.011 0.02 0.001
# Poisson, 0.5/2.0, regimes of 400 (#1) | 5062 | 0.099 0.93 0.076
# Poisson, 0.5/2.0, regimes of 400 (#2) | 4877 | 0.103 0.92 0.074
# Poisson, 0.5/2.0, regimes of 40 (#1) | 5049 | 0.297 0.77 0.297
# Poisson, 0.5/2.0, regimes of 40 (#2) | 5006 | 0.308 0.75 0.298When the data really are a Hawkes process the estimates are good: three simulations give branching ratios of 0.70 to 0.71. Constant-intensity Poisson data give 0.02, close to the true 0. But when the baseline switches between two levels (segments of 400 time units), the fitted branching ratio is as high as 0.92 to 0.93, with a decay rate of only about 0.07, even though no event in the data triggers any other: the model imitates the regime switches with a slowly decaying “self-excitation”. With faster switching (segments of 40), the fitted ratio is still 0.75 to 0.77.
Evidence
How close are markets to criticality? Filimonov and Sornette in 2012 fitted an exponential-kernel Hawkes model to mid-price changes of the US E-mini S&P 500 futures from 1998 to 2010 and found that endogeneity rose markedly: in 1998 about 70 % of price changes could be explained by exogenous information, after 2007 less than 30 % (Filimonov and Sornette 2012), that is, a branching ratio rising from about 0.3 to above 0.7. Hardiman, Bercot and Bouchaud in 2013 used a power-law kernel on the same market and found that the integral of the kernel was close to 1 and nearly constant from 1998 to 2011, concluding that the market had stayed close to criticality throughout; they argued that fitting a short-memory exponential kernel to a critical power-law process yields a branching ratio that is too low and rises over time (Hardiman et al. 2013). Filimonov and Sornette replied in 2015 that outliers, intraday seasonality, overnight trading and non-stationary parameters systematically push estimates towards 1, and that calibrating on mixtures of Poisson processes with regime shifts produces spurious critical values, so the conclusion that markets are at criticality does not stand (Filimonov and Sornette 2015). For a review see Bacry, Mastromatteo and Muzy (Bacry et al. 2015).
The dispute is unresolved, but the program shows its crux: the estimated branching ratio is extremely sensitive to model specification; kernel shape, time window and a non-stationary baseline can each move the estimate for the same data from 0.3 to near 1. Any claim that “the branching ratio is X, so a crash is coming” should first be asked whether baseline changes have been mistaken for self-excitation.
Chapter summary
The Hawkes process describes how far events trigger events through the branching ratio : when the mean intensity is , and as approaches 1 events cluster strongly with occasional huge chains. The branching ratio can be estimated by recursive likelihood but is extremely sensitive to model specification: data without self-excitation, only with baseline switches, can be fitted with a branching ratio of 0.92, which is the heart of the dispute over whether markets are at criticality. The author writes liquidation cascades as an effective branching ratio in price, , set jointly by the leverage distribution and depth, and local in character. The next chapter turns to the other side of trading: mean reversion.
References
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).