Software · Quant research
Desk Analysis Cases 分析
Fifteen forensic investigations of live market making in three months. Where a trading day needed explaining, Shuo rebuilt it order by order from raw engine logs and exchange ticks and matched it to the engine’s own books to the yuan before explaining anything. Two engine faults found, one predicted 2,328 times out of 2,328.
01System architecture
One pipeline behind the cases: rebuild the day, prove it exact, then explain it.
The engine belongs to another team and its logs rotate every day. So an investigation starts from three independent records of the same day and attributes nothing until they agree.
Trading machine
Engine logs
Every order, fill, quote decision and profit print the engine wrote, parsed as a stream.
Desk database
Exchange ticks
Five-level order-book snapshots, up to four a second, pulled with one-click SQL.
Terminal and settlement
Trade records
The desk’s own fills and the official settlement profit figure.
Step 1
Day reconstruction
Streaming parsers rebuild each order’s life, the position and the cash, second by second, across engine restarts.
Step 2 · the gate
Exact reconciliation
Cash + position × mid must equal the engine’s own profit print. No match, no conclusions.
Step 3
Attribution
Spread captured versus inventory carry, mark-outs from 1 second to 5 minutes, orders classified from the engine’s own record.
Step 4
Same-tape replays
Alternatives replayed on the recorded order book, calibrated on live fills, with crowd-out modeled.
When the engine misbehaves
Mechanism proof
The engine team’s C++ read line by line and matched to log lines, then tested as a per-tick prediction.
Step 5
Generated report
Every number written from JSON by the generator, never typed. 30 reports so far.
Outcome
Fix or decision
An engine patch for the engine team, a parameter change, or proof that the current way is best.
Simplified: not every case needs every step. The mechanism proof is used when the engine itself misbehaves; replays are used when the question is “would something else have done better?”
Why reconcile first?
An explanation built on a slightly wrong reconstruction is a story, not a finding. If Shuo’s rebuilt profit and loss differs from the engine’s by more than the rounding in its prints, an order is missing or misread somewhere, and anything he attributes could sit on that mistake. So nothing is explained until the two agree.
Why the engine’s own logs?
The log records what the engine saw and decided at each instant, including its view of the order book before every decision. That lets Shuo classify orders from the engine’s own record, never by guessing from prices.
Whose is what
The trading engine and its C++ source belong to the engine team, and the machine-learning price signal to the model team. The investigations, their methods, experiment designs and conclusions are Shuo’s.
02The story
Fifteen forensic investigations, trading days rebuilt to the yuan, and two engine faults found.
A market maker earns a little on thousands of trades, and a single fast minute can undo hours of it. When a session raised a question, or something on Shuo’s screen looked wrong, he rebuilt the day order by order from the trading engine’s raw logs, proved his reconstruction matched the engine’s own profit figure exactly,1 and only then explained what had happened. Fifteen cases in three months found two faults in the trading engine, settled how hedging orders should be sent, put a machine-learning signal through a live A/B test, and replaced “it felt like” with a measured answer every time.
01
The problem
A market maker quotes a buy and a sell price all day and earns the small gap between them, thousands of times. Now and then a single minute takes back a day of earnings, and the screen shows only the result.
The questions that follow cannot be answered from a screen: what exactly happened in that minute, did the strategy behave as designed, and would a different execution choice have done better? The evidence exists, but it sits in gigabytes of raw engine logs and millions of order-book snapshots.
- A fast minute leaves a result on the screen, not an explanation
- How a trading engine behaves under stress shows only in its logs, line by line
- Execution choices, such as which order type to hedge with or how to exit at the close, need live data to settle
02
What Shuo built
A method, designed and built by Shuo, and used fifteen times between August and November 2026. Each case gets its own folder, brief and journal. He pulls the exchange’s tick data, the desk’s trade records and the engine’s raw logs, and rebuilds the day order by order, like a flight recorder read after an incident.
Then comes the rule that makes it forensic: before explaining anything, his reconstruction has to match the engine’s own profit figure to the yuan. Only then does he split the result into what the quotes earned and what holding inventory cost, read the engine team’s source code where the engine itself looks wrong, and replay alternatives on the recorded order book.
Eleven of the fifteen began with something he noticed while trading:2 a price level flickering twice a second, a book that seemed to thin out during a fast move, a stop that did not behave as expected.
03
What changed
Guesses became measurements, and several first explanations were overturned. In the first case the working hypothesis, a market too thin to hedge in, was tested and rejected: the hedges did trade, within seconds, at the bottom of the move.3
- Two engine faults found and proved. An order loop that Shuo predicted on 2,328 of 2,328 occurrences with no false alarm,4 and a stop whose behavior he traced to its root cause.5 He specified the fix for both, and IT shipped the loop patch from his analysis.
- Execution questions settled with live data. Resting limit orders beat fill-and-kill for hedging,6 and no gentler end-of-day exit he tested beat the existing one, including one from optimal-execution theory and one he had argued for himself.7
- One number for a mystery. The same strategy, with the same parameters apart from quote size, had opposite results on consecutive days. The difference was what happened in the second after each fill: how often the market ran through the price of a filled quote, a property of the market he could measure.8
- A machine-learning signal put on trial. He designed and ran a live A/B test of the model team’s price signal, reported the result as it stood, inconclusive, and designed the follow-up crossover test, sized in advance by a power analysis.9
15
forensic investigations of live market making in three months, eleven of them started from Shuo’s own observation10
2,328/ 2,328
occurrences of an engine fault predicted tick by tick: every one caught, with zero false alarms on every other decision4
29min
from Shuo’s question to the log-proven root cause of that fault; IT shipped the patch from his analysis4
74min
for the first case, from a colleague’s question to a finished report that overturned the first hypothesis3
9.5M
order-book rows in a Level-2 archive rebuilt from engine prints, matching the exchange tick table with a 0.000% difference1
30
reports generated, every number in them written from data by code, never typed10
03The casebook
Ten investigations in eight stories, each a question, a method, a finding and what changed.
The remaining cases are listed in the table under the hood. Charts marked synthetic are drawn from generated data that shows each effect.11
A
The fast move that set the method
Question, from a colleague: after a violent move of a few minutes in one futures contract, was the market simply too thin to hedge in?
- Method. Three records of the same session cross-checked: the exchange’s order-book snapshots, the engine’s raw logs and the desk’s own fills, matched trade by trade.
- Finding. No. The hedges did fill, within seconds, at the bottom of the move, and the price rebounded almost at once. The cause lay in how a quoting strategy centers and hedges its quotes in a fast one-sided move, not in a thin market.3
- What changed. The first hypothesis was replaced by a diagnosis, and Shuo recommended additional protections. The whole case took 74 minutes from question to report, and every later case follows its standard.
A fast one-sided move and its rebound
The price falls 24 ticks in 48 seconds, and the hedges fill in the last 4 seconds before the low, just ahead of the rebound.
| Time from the start of the window (seconds) | Mid price |
|---|---|
| 0 | 0.0 |
| 1 | 0.0 |
| 2 | −0.5 |
| 3 | 0.0 |
| 4 | 0.5 |
| 5 | 0.0 |
| 6 | −0.5 |
| 7 | −0.5 |
| 8 | 0.5 |
| 9 | 0.5 |
| 10 | −0.5 |
| 11 | 0.0 |
| 12 | 0.5 |
| 13 | −0.5 |
| 14 | 0.0 |
| 15 | 0.0 |
| 16 | −0.5 |
| 17 | −0.5 |
| 18 | 0.5 |
| 19 | 0.0 |
| 20 | 0.0 |
| 21 | −0.5 |
| 22 | 0.0 |
| 23 | 0.0 |
| 24 | −1.0 |
| 25 | 0.5 |
| 26 | 0.0 |
| 27 | −0.5 |
| 28 | 0.0 |
| 29 | −0.5 |
| 30 | 0.0 |
| 31 | 0.0 |
| 32 | 0.0 |
| 33 | −0.5 |
| 34 | −0.5 |
| 35 | −0.5 |
| 36 | −0.5 |
| 37 | 0.0 |
| 38 | 0.0 |
| 39 | 0.5 |
| 40 | 0.0 |
| 41 | 0.5 |
| 42 | −0.5 |
| 43 | −0.5 |
| 44 | 0.0 |
| 45 | −1.0 |
| 46 | 0.0 |
| 47 | 0.0 |
| 48 | 0.5 |
| 49 | 0.5 |
| 50 | 0.5 |
| 51 | −0.5 |
| 52 | −0.5 |
| 53 | 0.0 |
| 54 | −0.5 |
| 55 | 1.5 |
| 56 | 0.0 |
| 57 | −0.5 |
| 58 | −1.0 |
| 59 | 0.0 |
| 60 | 0.0 |
| 61 | 0.0 |
| 62 | 0.5 |
| 63 | 0.0 |
| 64 | 0.5 |
| 65 | 0.0 |
| 66 | −0.5 |
| 67 | 0.0 |
| 68 | 0.0 |
| 69 | −0.5 |
| 70 | 0.5 |
| 71 | 0.0 |
| 72 | 0.0 |
| 73 | 0.0 |
| 74 | −0.5 |
| 75 | 0.0 |
| 76 | 0.5 |
| 77 | 0.0 |
| 78 | −0.5 |
| 79 | −0.5 |
| 80 | −1.0 |
| 81 | −1.5 |
| 82 | −1.0 |
| 83 | −1.0 |
| 84 | −1.5 |
| 85 | −2.0 |
| 86 | −2.5 |
| 87 | −3.0 |
| 88 | −3.0 |
| 89 | −3.0 |
| 90 | −4.0 |
| 91 | −4.0 |
| 92 | −4.0 |
| 93 | −4.5 |
| 94 | −5.5 |
| 95 | −5.5 |
| 96 | −5.5 |
| 97 | −6.5 |
| 98 | −7.5 |
| 99 | −8.5 |
| 100 | −8.5 |
| 101 | −9.5 |
| 102 | −10.0 |
| 103 | −10.5 |
| 104 | −10.5 |
| 105 | −12.0 |
| 106 | −12.5 |
| 107 | −13.5 |
| 108 | −14.5 |
| 109 | −15.5 |
| 110 | −16.0 |
| 111 | −17.0 |
| 112 | −17.5 |
| 113 | −19.0 |
| 114 | −20.0 |
| 115 | −21.0 |
| 116 | −22.5 |
| 117 | −23.0 |
| 118 | −24.0 |
| 119 | −23.0 |
| 120 | −23.0 |
| 121 | −22.5 |
| 122 | −21.5 |
| 123 | −22.0 |
| 124 | −21.0 |
| 125 | −20.0 |
| 126 | −20.0 |
| 127 | −20.5 |
| 128 | −20.0 |
| 129 | −19.5 |
| 130 | −18.5 |
| 131 | −19.0 |
| 132 | −18.0 |
| 133 | −18.0 |
| 134 | −18.0 |
| 135 | −18.0 |
| 136 | −16.5 |
| 137 | −16.5 |
| 138 | −17.0 |
| 139 | −16.0 |
| 140 | −16.5 |
| 141 | −15.5 |
| 142 | −16.5 |
| 143 | −15.5 |
| 144 | −15.5 |
| 145 | −15.0 |
| 146 | −15.0 |
| 147 | −14.5 |
| 148 | −15.0 |
| 149 | −14.5 |
| 150 | −14.5 |
| 151 | −14.5 |
| 152 | −14.5 |
| 153 | −14.0 |
| 154 | −13.5 |
| 155 | −14.5 |
| 156 | −14.0 |
| 157 | −13.0 |
| 158 | −14.0 |
| 159 | −13.5 |
| 160 | −13.5 |
| 161 | −13.5 |
| 162 | −13.0 |
| 163 | −13.0 |
| 164 | −13.0 |
| 165 | −12.5 |
| 166 | −13.0 |
| 167 | −12.5 |
| 168 | −13.0 |
| 169 | −13.0 |
| 170 | −12.5 |
| 171 | −12.5 |
| 172 | −12.5 |
| 173 | −12.0 |
| 174 | −13.0 |
| 175 | −12.5 |
| 176 | −12.5 |
| 177 | −12.5 |
| 178 | −12.5 |
| 179 | −12.5 |
| 180 | −12.0 |
| 181 | −12.5 |
| 182 | −12.5 |
| 183 | −12.5 |
| 184 | −12.5 |
| 185 | −12.0 |
| 186 | −12.0 |
| 187 | −12.0 |
| 188 | −12.5 |
| 189 | −11.5 |
| 190 | −12.0 |
| 191 | −11.5 |
| 192 | −12.0 |
| 193 | −12.0 |
| 194 | −12.5 |
| 195 | −11.5 |
| 196 | −11.0 |
| 197 | −11.5 |
| 198 | −12.0 |
| 199 | −11.5 |
| 200 | −11.5 |
| 201 | −12.0 |
| 202 | −12.0 |
| 203 | −11.0 |
| 204 | −12.0 |
| 205 | −11.5 |
| 206 | −11.5 |
| 207 | −12.0 |
| 208 | −11.5 |
| 209 | −12.0 |
| 210 | −11.5 |
| 211 | −11.5 |
| 212 | −11.5 |
| 213 | −12.0 |
| 214 | −12.5 |
| 215 | −11.5 |
| 216 | −11.5 |
| 217 | −11.5 |
| 218 | −12.0 |
| 219 | −11.5 |
| 220 | −11.5 |
| 221 | −11.5 |
| 222 | −11.5 |
| 223 | −11.5 |
| 224 | −11.5 |
| 225 | −11.5 |
| 226 | −11.5 |
| 227 | −11.5 |
| 228 | −11.5 |
| 229 | −11.5 |
| 230 | −12.0 |
| 231 | −11.5 |
| 232 | −12.0 |
| 233 | −11.5 |
| 234 | −10.5 |
| 235 | −11.5 |
| 236 | −11.5 |
| 237 | −11.5 |
| 238 | −11.0 |
| 239 | −11.5 |
| 240 | −11.5 |
B
An engine fault, predicted tick by tick
Question, from Shuo’s own screen: one price level seemed to be placed and canceled, over and over, at an extreme rate. Why?
- Method. Read the engine team’s C++ quoting logic, mapped its code paths to log lines, and built a predictor in Python that says, from each tick’s inputs alone, whether the loop must fire.
- Finding. An order-of-operations fault that exists under one engine setting only. The predictor caught 2,328 of 2,328 occurrences over ten trading days, with zero false alarms on every other decision: 100% precision and 100% recall.4 The loop orders never traded a single lot.
- What changed. Root cause in 29 minutes, and a ten-line patch specified for the engine team, which IT then shipped. An alternative fix was audited on the same data, decision by decision.
Orders and cancels per minute around one setting
The loop fires only while one engine setting is active, and stops the minute the setting changes back.
Show the dataHide the data
| Minutes into the window | Loop messages | All other messages | Total |
|---|---|---|---|
| 0 | 0 | 8 | 8 |
| 5 | 0 | 8 | 8 |
| 10 | 0 | 7 | 7 |
| 15 | 0 | 8 | 8 |
| 20 | 0 | 10 | 10 |
| 25 | 0 | 10 | 10 |
| 30 | 0 | 9 | 9 |
| 35 | 93 | 10 | 103 |
| 40 | 116 | 9 | 125 |
| 45 | 108 | 11 | 119 |
| 50 | 150 | 7 | 157 |
| 55 | 61 | 10 | 71 |
| 60 | 0 | 8 | 8 |
| 65 | 0 | 9 | 9 |
| 70 | 0 | 7 | 7 |
| 75 | 0 | 10 | 10 |
| 80 | 0 | 10 | 10 |
| 85 | 0 | 12 | 12 |
C
A stop, traced action by action
Question, Shuo’s, minutes after he saw it: a stop did not behave as expected. Why?
- Method. Rebuilt the account position from every fill, matched the position in the engine’s profit print on 99.98% of its prints, and traced each engine action to the record it used.
- Finding. The root cause, proved from the logs action by action and written up for the engine team.5
- What changed. An engine-side change was specified.
D
Limit order or fill-and-kill?
Question, Shuo’s: to cut inventory the engine sends hedging orders. Should they be fill-and-kill (take what is there, cancel the rest) or plain limit orders (leave the rest waiting in the book)?
- Method. A natural experiment. Both order types get the same instant fill and differ only in the leftover: one cancels it, the other leaves it resting. So on limit-order days the later fills are the difference, measured directly on the engine’s own hedges, with no model.6
- Finding. Limit orders win. A large share of the requested volume filled later, within seconds, every lot reducing inventory, and those later fills were profitable.
- What changed. The data favored resting limit orders; which order type the desk uses is its own decision and is not published. Shuo also threw out his own first method, a replay that matched the volume but overstated the value.
Enlarge
- Marker 1: Filled at once (gray-blue): the part both order types get in the same way, by taking whatever is at the price on arrival. Here 58% in period 1 under either policy.
- Marker 2: Filled later (amber, limit orders only): 22% of the requested volume trades after resting in the book, at a median wait of 2.9 seconds.
- Marker 3: Fill-and-kill, period 1: the same instant fill, and the remaining 42% is simply dropped.
- Marker 4: Limit orders, period 2: a shallower book fills less at once (47%), and 32% fills later.
- Marker 5: Fill-and-kill, period 2: 53% of the requested volume is never filled.
E
Can the end-of-day exit be made cheaper?
Question, from the desk and from Shuo: the engine makes an urgent exit at the close. Would a patient or a smooth exit cost less?
- Method. Measured the cost of the existing exits, then replayed the patient exit Shuo had argued for, a linear-target scheme and 17 execution schedules, the theory optimum among them, on the recorded order books, with other traders’ reactions modeled.
- Finding. No. Most of the cost is the half spread any urgent exit pays. Across the market, a best price that has been swept away comes back within ten seconds only 36% of the time, and only 7% after large sweeps. The patient exit Shuo had argued for did not come out ahead.7
- What changed. The verdict: keep the current exit, now with evidence. The report says “no better mechanism exists” in place of a fitted improvement. The same case produced a margin model that reproduces the broker’s margin calculation exactly.
Enlarge
- Marker 1: Dashed line: take the next price level now, exactly one tick worse than the price that was swept.
- Marker 2: Small sweeps (gray lines): after ten seconds the obtainable price is about 0.8 tick worse, a little better than acting at once.
- Marker 3: Medium sweeps (gold): waiting gains almost nothing.
- Marker 4: The largest sweeps (red): the price keeps running, to 1.5 ticks worse. Waiting loses to hitting the next level immediately.
- Marker 5: Time waited: from a quarter of a second (left) to ten seconds (right), measured on 2,184 market-wide sweeps in the last fifteen minutes of trading.
F
Same strategy, opposite days
Question, Shuo’s: one contract had opposite results on two consecutive days, with the same strategy. From the profit curve it did not even look like the same program. What differed?
- Method. Ruled out everything a trader would suspect, with data: every strategy parameter identical apart from quote size, the same trading logic (the software update between the two days changed only log output), the same reaction time, and virtually the same spread earned per lot.
- Finding. One metric: the share of filled quotes whose price is run through within a second. It is a property of the market, it persists from one quarter-hour to the next, and across sessions it tracked the result per lot closely.8
- What changed. A named, measurable cause where there had been a mystery, and a proposal for a live run-through gauge to guide how much size to show.
Run-through rate and result per lot, 24 sessions
The more of the market’s resting orders are run through within a second, the worse the session: r = −0.63 across 24 illustrative sessions.
| Series | Market’s resting orders run through within a second (%) | Result per lot, indexed | Label |
|---|---|---|---|
| Other days | 17.7% | 24 | |
| Other days | 20.8% | 26 | |
| Other days | 17.5% | 48 | |
| Other days | 26.3% | 58 | |
| Other days | 26.5% | 13 | |
| Other days | 24.1% | −6 | |
| Other days | 27.3% | −39 | |
| Other days | 24.5% | −31 | |
| Other days | 25.0% | −18 | |
| Other days | 28.0% | 39 | |
| Other days | 30.1% | −14 | |
| Other days | 29.0% | 49 | |
| Other days | 27.6% | 13 | |
| Other days | 25.1% | 15 | |
| Other days | 23.4% | 57 | |
| Other days | 22.3% | 37 | |
| Other days | 23.7% | −30 | |
| Other days | 24.4% | 15 | |
| High run-through day | 45.2% | −30 | |
| High run-through day | 43.2% | −29 | |
| High run-through day | 41.8% | −62 | |
| Low run-through day | 13.1% | 100 | Best session |
| Low run-through day | 13.4% | 58 | |
| Low run-through day | 13.0% | 6 |
G
When big fills turn on you
Three questions, all Shuo’s: a fast close while the order book seemed to thin out, a difficult stretch in a quiet market, and a contract whose results changed with its quote size.
- The close. The answer was one minute of inventory carried through a short-covering rally. The thin book was no illusion, and it was partly the desk itself: its own quotes had become an unusually large share of the displayed book.12
- The quiet market. The quotes earned their full margin, and the cost of holding inventory decided the outcome. Profit five seconds after a fill fell steadily with the size of the fill: positive on the smallest fills, negative on the largest.13 That is measured at fill time, when a big fill is the sweep itself; measured at the start of a window, as the CHRONOS sizing study did, profit per lot was flat in quote size.
- The small quote. At very small quote sizes the exchange’s minimum-size obligation turned into top-up orders that fill only when the price runs them over: adversely selected fills.14
Profit five seconds after a fill, by fill size
The bigger the fill, the worse it turns out: +0.47 tick per lot on the smallest fills, −0.77 on the largest.
| Size of the fill event | Profit five seconds after the fill (ticks per lot) |
|---|---|
| 1–4 lots | 0.47 |
| 5–14 lots | 0.04 |
| 15–39 lots | −0.33 |
| 40+ lots | −0.77 |
H
A live A/B test of a machine-learning signal
Question, Shuo’s, and his own experiment design: does the model team’s price signal add value live? One contract ran with the signal off, a matched one with it on.
- Method. A treated-versus-control trial on two contracts, reconciled to settlement, then same-tape replays with the signal on and off, calibrated on live hedging fills. Uncertainty from a minute-block bootstrap, and the replay’s own error measured against live.
- Finding. Inconclusive, and reported that way. The replay’s own bias against live was as large as the effect it was asked to measure, and a raw comparison across two contracts did not survive adjusting for size. Shuo did not claim a result the data could not support.9
- What changed. A better experiment: swap the two contracts daily, judge on live minus replay, with a power analysis fixing in advance how many trading days are needed to detect an effect.
04All screens
Charts
A synthetic redraw in English, and a chart computed from public exchange order-book data, exported from Shuo’s Chinese-language report. Open either for its numbered notes.
05Under the hood
Identities, a classifier, replays and code
Under the hoodModels, math and code for the technical reader
The methods behind the cases, for a quant, an ML scientist or an engineer. The analysis is Python (one Monte Carlo study is C#): streaming parsers over the C++ engine’s rotating logs; five-level exchange snapshots, every 250 ms on the Dalian exchange; SQL pulls from the desk’s MariaDB tick store. A 9.5-million-row Level-2 archive rebuilt from engine prints matches the tick table exactly. Validation is by walk-forward and leave-one-day-out splits, minute-block bootstrap and power analysis. Tables and charts marked synthetic use generated data that shows the effect; the desk’s own figures are confidential and do not appear here.
1. The reconciliation gate
Before any attribution, the rebuilt book must reproduce the engine’s own running profit figure at every print, and the exchange settlement figure at the close. With signed fills at prices , position , book mid and contract multiplier , the identity below must hold. The rebuild is restart-aware, because the engine’s counters are scoped to a strategy instance and can rebase when it restarts.
| Case | Check | Result |
|---|---|---|
| A fast close in a thin book | Identity at every engine print | Exact on all 2,117 prints |
| A quiet-market window | Identity at every per-second print | Within one yuan on 99.97% of 21,874 prints |
| The stop case | Rebuilt account position vs the engine’s profit print | Equal on 99.98% of prints |
| Two products over two months | Engine P&L vs database P&L per contract-day | Equal on 58 of 62 clean contract-days |
| Same strategy, opposite days | Rebuild vs settlement vs engine | Gap of zero on every day of the panel |
| Level-2 archive built from engine prints | 9.5 million rows vs the tick table | 0.000% difference |
2. Edge versus carry
Once the gate passes, P&L is split on one event clock into the spread captured at each fill and the cost or gain of carrying inventory between fills. This single split answers most “what happened” questions: in one quiet-market case the edge term was the full half spread and the carry term decided the outcome. Mark-outs at 1 s, 5 s, 30 s and 5 min on exchange ticks, cut by fill size, queue position, order age and session, show when the carry is adverse selection.
| Size of the fill event | Fill events | Mark-out after 5 s, ticks per lot |
|---|---|---|
| 1–4 lots | 5,503 | +0.47 |
| 5–14 lots | 2,656 | +0.04 |
| 15–39 lots | 715 | −0.33 |
| 40+ lots | 126 | −0.77 |
3. Why a bigger quote weakens its own brake
The engine leans its quotes against inventory, and Shuo verified from the logs how: his reconstruction of the lean was exact on every quote decision of a full trading day. Its consequence explains three separate cases. The engine’s inventory lean per lot weakens as quote size grows, so large quotes weaken their own brake, and a position can build without the quotes leaning away from it. At very small quote sizes the same relation works in reverse: the exchange’s minimum-size obligation creates top-up orders larger than the quote itself, one of them fills, and the lean fires a stream of small hedges.
4. The insert/cancel loop: mechanism and patch
The fault is one of ordering. Within one quoting cycle the engine could send an order that a later step of the same cycle was already bound to remove, and that step can act only on orders the exchange has acknowledged. So the order goes out; on the next 250 ms snapshot it is acknowledged and canceled; once the cancel confirms, the condition that created it is back, and it is sent again: one cycle every two exchange snapshots, for as long as one engine setting is active. The fix Shuo specified is about ten lines: make the check before the order is created, not after. The C++ belongs to the engine team and is not reproduced here.
| Measure, ten trading days, both sides | Value |
|---|---|
| Loop ticks predicted / observed | 2,328 / 2,328 |
| Missed | 0 |
| False alarms on every other decision | 0 |
| Lots filled by loop orders | 0 |
| Cycle | Two exchange snapshots |
| Occurrences under any other setting | 0 |
5. The mechanism, tested as a classifier
A mechanism is a claim, so Shuo tested it as a binary classifier over every running tick and side of ten trading days. The label is what the engine did, read from its own order log: a loop order sent on that tick and side, or not. The prediction comes from that tick’s logged inputs alone. The rule has no fitted parameter, so there is nothing to overfit, and every tick is out of sample.
Two refinements were needed to reach exactness: orders the engine sets aside before it decides had to be set aside in the predictor too, and one logged input had to be recomputed at full precision because the log prints it rounded.
Why not simply flag bursts of cancels? A rate threshold finds the symptom. A rule that reproduces every occurrence and nothing else identifies the cause, and that is what makes a ten-line patch to someone else’s trading engine safe to propose.
An alternative fix was replayed on the same ticks and compared decision by decision. Both versions were written up for the engine team, and IT shipped the loop patch from this analysis.
confusion = Counter()
for tick in running_ticks: # every snapshot the engine acted on
for side in (BUY, SELL):
state = inputs_logged_at(tick, side) # only what the engine itself saw
predicted = mechanism_rule(state) # no fitted parameter
observed = loop_order_sent(order_log, tick, side)
confusion[predicted, observed] += 1
assert confusion[True, False] == 0 # no false alarm
assert confusion[False, True] == 0 # nothing missed| Every tick and side, ten trading days | Engine sent a loop order | Engine did not |
|---|---|---|
| Predicted | 2,328 | 0 |
| Not predicted | 0 | every other decision |
6. The run-through rate
Two days, identical parameters apart from size, identical latency, near-identical half-spread edge per lot, opposite results. The whole gap opens within about five seconds after each fill, so Shuo defined a statistic on exactly that window: a passive fill is “run through” when, within one second, the best price on the desk’s side has moved beyond the filled price. The market-wide version uses every passive fill implied by the exchange ticks, with the aggressor side solved from exact turnover.
Across sessions the market-wide rate tracked the result per lot closely, and the 15-minute rate persists from one window to the next, which is what makes it usable as a live gauge. The per-lot gap between the two days decomposes into three parts: the market regime, the allocation of size across the day, and fill selection within the same windows.
The statistic separates fills cleanly: thirty seconds on, run-through lots are down and the rest are up. One tempting fix was checked and rejected, because pooled days showed no gradient of fill quality in depth where the fix would have acted.
def seconds_to_run_through(fill, book, horizon=30.0):
"""Time until the best price on the filled side moves past the fill price."""
end = min(fill.time + horizon, session_end(fill.time))
for snap in book.snapshots(after=fill.time, until=end):
if fill.is_buy and snap.best_bid < fill.price:
return snap.time - fill.time
if fill.is_sell and snap.best_ask > fill.price:
return snap.time - fill.time
return None # censored: not run through in the window
def run_through_rate(quote_fills, book, within=1.0):
hit = total = 0
for fill in quote_fills:
t = seconds_to_run_through(fill, book)
total += fill.lots
if t is not None and t <= within:
hit += fill.lots
return hit / total| Measure | High run-through day | Low run-through day |
|---|---|---|
| Market’s resting volume run through within 1 s (day average) | 43% | 13% |
| Result per lot by session, indexed (100 = best session, 0 = break-even) | −30, −29, −62 | 100, 58, 6 |
7. Limit versus fill-and-kill: identification, and a method Shuo rejected
A fill-and-kill order and a limit order sent at the same instant receive the same immediate match. They differ only in the unmatched remainder: one cancels it, the other rests until filled or withdrawn. So on days when the engine sent limit orders, the later fills of the resting remainder are the treatment effect, observed directly, with no model. Hedges are identified by the engine’s own marker, and only periods with the same crossing threshold are compared.
Shuo’s first approach was a counterfactual: replay fill-and-kill days as if the remainder had rested, first in queue. It reproduced the later-fill volume closely but credited each lot well above its true mark-out, because in reality other orders rest ahead at that price. He discarded it. A regime check supports the conclusion: one limit-order period was unusually trending, so the decisive evidence is the other, ordinary one.
| Order type and period | Filled at once | Filled later | Never filled or dropped | Median wait of later fills |
|---|---|---|---|---|
| Limit orders, period 1 | 58% | 22% | 20% | 2.9 s |
| Fill-and-kill, period 1 | 58% | none | 42% | n/a |
| Limit orders, period 2 | 47% | 32% | 21% | 1.1 s |
| Fill-and-kill, period 2 | 47% | none | 53% | n/a |
8. A/B test of a price signal: an honest “inconclusive”
The live trial was Shuo’s design: the model team’s signal switched off on one contract and left on for another of similar volume. Raw live results are not comparable across two contracts, so the evaluation is a same-tape replica: the desk’s quoting logic replayed on each contract’s own order book with the signal’s recorded predictions (including those computed but not used on the switched-off contract), the size schedules actually used, and hedging fills calibrated on live behavior. Uncertainty comes from a minute-block bootstrap. The decisive step is measuring the replica’s own bias, live minus replica under each day’s live configuration: where that bias is as large as the estimated effect, the honest reading is “undetermined”, and that is what Shuo reported.
A timing check ruled out one explanation for the bias: the share of hedging orders whose target was gone by the next snapshot was compared between live trading and replicas with and without a one-snapshot lag. The follow-up is a crossover design: swap treated and control daily, judge on live minus replica, and fix the number of trading days in advance by a power analysis.
| Design element | Purpose |
|---|---|
| Treated and control contracts | A live on/off comparison at similar volume |
| Same-tape replica | Each contract replayed on its own order book, signal on and off |
| Minute-block bootstrap | Uncertainty that respects intraday dependence |
| Replica-bias check | Live minus replica under each day’s live configuration |
| Timing check | Rules out latency as the source of the bias |
| Crossover design with power analysis | Treated and control swapped daily; days needed fixed in advance |
9. Closing clearing against optimal-execution theory
The engine makes an urgent exit at the close. Shuo first measured what it costs: most of the cost is the half spread, which no urgent exit avoids, and only the extra paid on lots filled one level deeper could be saved by any execution.
Three families of alternatives were replayed on the recorded books. Patient clearing from a minute before the stop (the idea Shuo had argued for) did not come out ahead: it earns its half spread, but gives up far more final-minute quoting than it saves on the net position. A linear-target scheme did no better. The best start time found in sample was worth about zero under leave-one-day-out.
For smooth schedules he measured the transient-impact propagator at the close by regressing mid-price changes on signed trade flow at increasing lags. In the power-law model of Gatheral, Schied and Slynko, a smooth schedule pays when impact decays quickly. Here it does not: 64% of a trade’s impact is still present after 30 seconds. Seventeen schedules, the current exit among them, were replayed on the recorded books: the smooth ones cost more, a sweep through several levels was always worst, and a slower level-by-level exit only matched the current one. Even the most favorable fitted model saves less than the drift after a large exit costs an even-paced schedule.
The modeling fix that mattered most is crowd-out: a passive fill that a scheme chooses to give up does not vanish; the same aggressive order consumes other traders’ depth at that price instead. Without it, the replay credited “stop adding” with a saving that does not exist.
Price response to one trade, last minutes of trading
A trade’s push on the price peaks within three seconds, and 64% of it is still there thirty seconds later.
| Time after the trade (seconds) | Measured response |
|---|---|
| 0.00 | 65.1% |
| 0.25 | 82.1% |
| 0.50 | 86.4% |
| 0.75 | 91.7% |
| 1.00 | 95.2% |
| 1.25 | 98.7% |
| 1.50 | 99.1% |
| 1.75 | 99.6% |
| 2.00 | 99.7% |
| 2.25 | 99.8% |
| 2.50 | 99.9% |
| 2.75 | 100.0% |
| 3.00 | 99.2% |
| 3.25 | 98.3% |
| 3.50 | 97.5% |
| 3.75 | 96.6% |
| 4.00 | 96.1% |
| 4.25 | 95.6% |
| 4.50 | 95.1% |
| 4.75 | 94.7% |
| 5.00 | 94.2% |
| 5.25 | 93.7% |
| 5.50 | 93.2% |
| 5.75 | 92.7% |
| 6.00 | 92.4% |
| 6.25 | 92.1% |
| 6.50 | 91.7% |
| 6.75 | 91.4% |
| 7.00 | 91.0% |
| 7.25 | 90.7% |
| 7.50 | 90.4% |
| 7.75 | 90.0% |
| 8.00 | 89.8% |
| 8.25 | 89.5% |
| 8.50 | 89.2% |
| 8.75 | 88.9% |
| 9.00 | 88.7% |
| 9.25 | 88.4% |
| 9.50 | 88.1% |
| 9.75 | 87.8% |
| 10.00 | 87.6% |
| 10.25 | 87.3% |
| 10.50 | 87.0% |
| 10.75 | 86.7% |
| 11.00 | 86.5% |
| 11.25 | 86.2% |
| 11.50 | 85.9% |
| 11.75 | 85.6% |
| 12.00 | 85.4% |
| 12.25 | 85.2% |
| 12.50 | 84.9% |
| 12.75 | 84.7% |
| 13.00 | 84.4% |
| 13.25 | 84.2% |
| 13.50 | 84.0% |
| 13.75 | 83.7% |
| 14.00 | 83.5% |
| 14.25 | 83.2% |
| 14.50 | 83.0% |
| 14.75 | 82.8% |
| 15.00 | 82.5% |
| 15.25 | 82.3% |
| 15.50 | 82.0% |
| 15.75 | 81.8% |
| 16.00 | 81.6% |
| 16.25 | 81.3% |
| 16.50 | 81.1% |
| 16.75 | 80.8% |
| 17.00 | 80.6% |
| 17.25 | 80.3% |
| 17.50 | 80.1% |
| 17.75 | 79.8% |
| 18.00 | 79.6% |
| 18.25 | 79.3% |
| 18.50 | 79.1% |
| 18.75 | 78.8% |
| 19.00 | 78.6% |
| 19.25 | 78.3% |
| 19.50 | 78.1% |
| 19.75 | 77.8% |
| 20.00 | 77.6% |
| 20.25 | 77.3% |
| 20.50 | 77.1% |
| 20.75 | 76.9% |
| 21.00 | 76.6% |
| 21.25 | 76.4% |
| 21.50 | 76.1% |
| 21.75 | 75.9% |
| 22.00 | 75.6% |
| 22.25 | 75.4% |
| 22.50 | 75.1% |
| 22.75 | 74.9% |
| 23.00 | 74.6% |
| 23.25 | 74.4% |
| 23.50 | 74.1% |
| 23.75 | 73.9% |
| 24.00 | 73.5% |
| 24.25 | 73.1% |
| 24.50 | 72.7% |
| 24.75 | 72.3% |
| 25.00 | 72.0% |
| 25.25 | 71.6% |
| 25.50 | 71.2% |
| 25.75 | 70.8% |
| 26.00 | 70.4% |
| 26.25 | 70.0% |
| 26.50 | 69.6% |
| 26.75 | 69.3% |
| 27.00 | 68.9% |
| 27.25 | 68.5% |
| 27.50 | 68.1% |
| 27.75 | 67.7% |
| 28.00 | 67.3% |
| 28.25 | 66.9% |
| 28.50 | 66.6% |
| 28.75 | 66.2% |
| 29.00 | 65.8% |
| 29.25 | 65.4% |
| 29.50 | 65.0% |
| 29.75 | 64.6% |
| 30.00 | 64.3% |
| 30.25 | 63.9% |
| 30.50 | 63.5% |
| 30.75 | 63.1% |
| 31.00 | 62.7% |
| 31.25 | 62.3% |
| 31.50 | 61.9% |
| 31.75 | 61.6% |
def regressors(snapshots, tick):
"""Mid price in ticks and signed trade flow per snapshot."""
mid = [(s.best_bid + s.best_ask) / 2 / tick for s in snapshots]
flow = [0.0] * len(snapshots)
for j in range(1, len(snapshots)):
traded = snapshots[j].volume - snapshots[j - 1].volume
if traded > 0:
last = snapshots[j].last_price / tick
sign = (last > mid[j - 1]) - (last < mid[j - 1]) # signed against the previous mid
flow[j] = sign * traded
return mid, flow| Alternative to the current clearing | Tested on | Verdict |
|---|---|---|
| Wait for the swept price to return | 2,184 market-wide sweeps, last 15 minutes | Returns within 10 s 36% of the time; 7% after large sweeps |
| Quote reduce-only before the stop | Recorded fills | No gain at any lead time tested |
| Patient first-level clearing from a minute out | Recorded books | Not better |
| A linear-target scheme | Recorded books | Not better |
| Best start time found in sample | Leave-one-day-out | About zero |
| 17 execution schedules, theory optimum included | Recorded books | None better; the smooth ones cost more |
| Taper the quote size into the stop | Recorded books and fills | Worse at every lead time |
10. Failure modes engineered out
- A wrong claim, caught and turned into a rule. An early draft of one report carried a claim that rested on a truncated count. Shuo re-derived it from the engine’s raw logs, pairing every quoting line with the exchange’s book at the same tick, and corrected it along with five other figures. Since then every number in a report is written by the generator from JSON, later reports assert their own headline numbers, and re-derivation scripts rebuild the headlines from the raw logs.
- Instance-scoped counters. The engine’s position and profit counters belong to a strategy instance and can rebase when it restarts. All rebuilds work at account level and detect restarts.
- Orders classified from the engine’s record, not by price. Why each order was sent is read from the log, never inferred from where it was priced.
- Own quotes removed from depth. “External depth” is the displayed book minus the desk’s resting orders, taken from the engine’s record of the book before each decision.
- Counterfactuals that respect other traders. First-in-queue replays overstate value; dropped fills crowd out. Both biases were measured before the methods were used or rejected.
- Not done, and stated. Where the desk’s own orders were a large part of the book, no “smaller size” replay was run, because scaling the desk’s orders would have changed the market it was replayed against.
- Missing data handled by convention, three ways. Where a tie-break or assumption is needed, results are reported under all three conventions.
11. The full casebook
All fifteen, in order. Four are told in depth on their own pages: the new queueing strategy’s first live session in Smart Queue Review, the sizing validation in CHRONOS, the A/B test’s design in Live vs Backtest, and the ranking-rule study in Options Ranking Probability.
| # | Question | Method | Verdict |
|---|---|---|---|
| 1 | Was the market too thin to hedge in during a fast move? | Three records cross-checked trade by trade | No. The hedges filled at the bottom of the move; the first hypothesis was rejected |
| 2 | What mechanism was behind one sharp session? | Engine log lines paired with the exchange book at the same tick | One external sweep against symmetric quotes in a one-tick market |
| 3 | How did a new queueing strategy’s first live session compare with its backtest? | Every order classified from the engine’s record; mark-outs by order class | The gap traced to one order class; told in Smart Queue Review |
| 4 | Does CHRONOS’s sizing raise profit per lot? | Per-period attribution reconciled to settlement, against a control period | A colleague’s test, extended into a daily effect report and four parameter studies |
| 5 | Why are fills taking longer? | A Level-2 archive rebuilt from engine prints; queue-time distributions | A thicker best price and less taker flow: depth divided by flow tracks queue time closely |
| 6 | Why did a stop not behave as expected? | Account position rebuilt from every fill; each action traced to the record it used | Root cause proved from the logs; engine-side change specified |
| 7 | Why does one price level flicker? | Mechanism read from source, then tested as a per-tick classifier | An engine fault under one setting; 2,328 / 2,328 predicted |
| 8 | What happened in the final minutes of one session? | Edge and carry split; external depth net of own quotes | One minute of inventory carry in a book that was thin, partly because of the desk’s own quotes |
| 9 | Limit order or fill-and-kill? | A natural experiment on the resting remainder | Limit: the resting remainder fills later and profitably |
| 10 | Does the ML signal add value live? | Live A/B, same-tape replica, block bootstrap, bias check | Inconclusive; crossover design specified and sized in advance |
| 11 | How do results depend on quote size? | Contract-days grouped by quote size; orders classified from the engine’s record | At very small sizes the exchange’s minimum-size obligation becomes adversely selected top-up fills |
| 12 | A difficult stretch in a quiet market, with no shock? | Mark-outs by the size of the fill event | Adverse selection grows with the desk’s own fill size |
| 13 | A Monte Carlo study of an exchange ranking rule, for a colleague | Monte Carlo of 2 × 10⁹ draws per scenario | Checked by exact counting; told in Options Ranking Probability |
| 14 | Same strategy, opposite days? | Everything else ruled out; a market-wide run-through rate | The run-through rate tracked session results closely |
| 15 | Can the closing exit be cheaper? | Replays of patient, linear and 17 scheduled exits; a propagator fit; a margin model | No better mechanism; the margin model reproduces the broker’s calculation exactly |
Built with
- Python
- SQL · MariaDB
- Market microstructure
- Order-book replay
- P&L attribution
- Mark-out analysis
- A/B testing
- Classifier evaluation (precision · recall)
- Natural-experiment identification
- Counterfactual simulation
- Block bootstrap · power analysis
- Walk-forward · leave-one-day-out validation
- Transient-impact (propagator) regression
- Optimal execution
- Monte Carlo (C#)
- C++ code reading
- Streaming log parsers
- Generated HTML/SVG reports
06Timeline
Fifteen cases in three months
- Case 1 · The fast move that set the methodA colleague’s question answered in 74 minutes; the reconcile-first method is set.
- Case 2 · One sweep, one mechanismA draft claim caught on re-derivation and corrected; generated numbers become the rule.
- Case 3 · A new queueing strategy, first live sessionLive fills compared with the backtest, order class by order class.
- Case 4 · CHRONOS effect validationA colleague’s test becomes a daily report and four parameter studies.
- Case 5 · Fill waiting time and liquidityA 9.5-million-row order-book archive, verified against the tick table.
- Case 6 · A stop, traced action by actionAccount position rebuilt from every fill; engine-side change specified.
- Case 7 · The insert/cancel loopRoot cause in 29 minutes; 2,328 of 2,328 predicted; patch specified, later shipped by IT.
- Case 8 · A fast close in a thin bookOne minute of inventory carry; external depth measured net of the desk’s own quotes.
- Case 9 · Limit versus fill-and-killLimit orders win, on a natural experiment.
- Case 10 · A/B test of the ML signalInconclusive, reported as such; crossover design with power analysis.
- Case 11 · Quote size and the exchange obligationResults follow quote size through the exchange’s minimum-size obligation.
- Case 12 · A quiet-market windowFull half spread earned; carry decided the outcome, with adverse selection growing with fill size.
- Cases 13 and 14 · A ranking-rule Monte Carlo; opposite daysA Monte Carlo for a colleague, and the run-through metric.
- Case 15 · The closing exit and a margin modelThree report versions in two days; conclusion: keep the current exit.
- 1The match is exact in most cases, for example on all 2,117 engine prints of one day, and with a zero gap against both the engine and the settlement figure on every day of one panel. Elsewhere it holds within one yuan on 99.97% of 21,874 prints, or on 58 of 62 clean contract-days over two months; in the very first case the three records were matched trade by trade instead. The deep dive lists each check.
- 2Eleven of the fifteen began with Shuo’s own observation or question from live trading. Two began with a colleague’s request, one with a colleague’s test that he extended, and one includes a colleague’s questions.
- 3One commodity futures contract, one session. The chart is an illustration on synthetic data; the finding, that the hedges filled at the bottom of the move and that the first hypothesis did not hold, is as reported. “74 minutes” is the time from the question to the finished report.
- 4Ten trading days, both sides of the book. Each prediction uses only that tick’s own inputs, and the rule has no fitted parameter. The engine and its source code belong to the engine team: Shuo diagnosed the fault and specified the fix, and IT shipped the loop patch from his analysis. “29 minutes” is the time from his question to the log-proven root cause.
- 5The engine and its source code belong to the engine team. Shuo rebuilt the account’s position from every fill, traced each engine action to the record it used, and specified the engine-side change.
- 6Hedges are identified by the engine’s own marker, and only periods with the same crossing threshold are compared. The later fills of the resting remainder were valued by mark-outs at 5 seconds, 30 seconds and 5 minutes. The bar chart is an illustration on synthetic data.
- 7Return rates are measured on 2,184 market-wide sweeps of the best price level in the last fifteen minutes of trading, from exchange order-book data. The theory schedules follow the transient-impact models of Obizhaeva and Wang and of Gatheral, Schied and Slynko, with parameters Shuo measured at the close. Alternative exit schemes were compared on the same data.
- 8“Run through” means that within one second the best price on the filled side moved past the fill price (for a filled buy, the best bid fell below it). The market-wide rate is computed from exchange data. The relation was measured in sample on a short panel; the proposed live gauge needs more days before it sets a threshold. The chart is an illustration on synthetic data.
- 9The price signal belongs to the model team; the experiment design and its evaluation are Shuo’s. The design: treated and control contracts, a same-tape replica, a minute-block bootstrap, a check of the replica’s own bias, and a power analysis for the follow-up crossover test.
- 10Fifteen case folders, August to November 2026, each with its own brief, journal, code, data and report. Thirty HTML report files and four PDFs in total.
- 11Charts, figure data and screenshots on this page are synthetic, illustrative or public market data. Methods and outcomes are described as they happened; the desk’s own figures are confidential and do not appear here.
- 12External depth is the displayed five-level book minus the desk’s own resting orders, taken from the engine’s record of the book before each decision.
- 13Mark-out is the per-lot profit of a fill measured against the mid price five seconds later, grouped by the size of the desk’s fill event. The chart is an illustration on synthetic data; the finding, that adverse selection grew with the desk’s own fill size, is as reported.
- 14A designated market maker must keep a minimum size on both sides, within a maximum spread, for a minimum share of trading time; the engine tops resting quotes up to that minimum.