Desk Analysis Cases

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.

  • Conceived and built by Shuo Huang
  • 15 investigations in 3 months
  • 11 of 15 self-initiated
  • 2 engine faults found
  • Reconciled to the yuan
  • Python · SQL · C++ code reading

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.

  1. 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
  2. 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.

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

Data: A fast one-sided move and its rebound
Time from the start of the window (seconds)Mid price
00.0
10.0
2−0.5
30.0
40.5
50.0
6−0.5
7−0.5
80.5
90.5
10−0.5
110.0
120.5
13−0.5
140.0
150.0
16−0.5
17−0.5
180.5
190.0
200.0
21−0.5
220.0
230.0
24−1.0
250.5
260.0
27−0.5
280.0
29−0.5
300.0
310.0
320.0
33−0.5
34−0.5
35−0.5
36−0.5
370.0
380.0
390.5
400.0
410.5
42−0.5
43−0.5
440.0
45−1.0
460.0
470.0
480.5
490.5
500.5
51−0.5
52−0.5
530.0
54−0.5
551.5
560.0
57−0.5
58−1.0
590.0
600.0
610.0
620.5
630.0
640.5
650.0
66−0.5
670.0
680.0
69−0.5
700.5
710.0
720.0
730.0
74−0.5
750.0
760.5
770.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
Synthetic data. Illustrative values, generated to show the effect: a sweep, hedges that fill at the low, and a partial rebound (about 52% of the fall recovered). A tick is the smallest price step. The method is as built; the desk’s own figures are confidential.3

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
Data: Orders and cancels per minute around one setting
Minutes into the windowLoop messagesAll other messagesTotal
0088
5088
10077
15088
2001010
2501010
30099
359310103
401169125
4510811119
501507157
55611071
60088
65099
70077
7501010
8001010
8501212
Synthetic data. Illustrative values, generated to show the effect: orders sent plus cancel requests per minute in five-minute blocks, a baseline of about ten a minute, and loop traffic of up to 150 a minute only during the 25 minutes the setting is active. The method is as built; the desk’s own figures are confidential.4

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.
Four horizontal bars in two pairs, one pair per period: limit orders above fill-and-kill. Each bar is split into the share of hedging volume filled at once, filled later while resting, and never filled or dropped. Within a pair the filled-at-once block is the same length; only the limit-order bars have an amber filled-later block. Enlarge
Synthetic data. Illustrative values, generated to show the effect. Two periods, two order types on the same arrivals: the instant fill is identical within a period, and the amber block, the resting remainder that fills later, is the whole difference between the two policies. The method is as built; the desk’s own figures are confidential.
  1. 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.
  2. 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.
  3. Marker 3: Fill-and-kill, period 1: the same instant fill, and the remaining 42% is simply dropped.
  4. Marker 4: Limit orders, period 2: a shallower book fills less at once (47%), and 32% fills later.
  5. 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.
Line chart of the price obtainable after waiting between a quarter of a second and ten seconds once the best price level has been swept, in ticks relative to the swept price, with one line per sweep size and a dashed reference line at minus one tick. Enlarge
Public exchange market data: market-wide sweeps of the best price level, from Shuo’s original report. After the best price is swept away, what price can you get by waiting, compared with taking the next level immediately (the dashed line, one tick worse)? Axis labels are in Chinese: time waited runs left to right, price in ticks runs bottom to top. After small sweeps, waiting recovers a fraction of a tick. After the big sweeps that matter at the close, waiting makes it worse. The right edge of the chart is ten seconds.
  1. Marker 1: Dashed line: take the next price level now, exactly one tick worse than the price that was swept.
  2. 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.
  3. Marker 3: Medium sweeps (gold): waiting gains almost nothing.
  4. Marker 4: The largest sweeps (red): the price keeps running, to 1.5 ticks worse. Waiting loses to hitting the next level immediately.
  5. 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.

Data: Run-through rate and result per lot, 24 sessions
SeriesMarket’s resting orders run through within a second (%)Result per lot, indexedLabel
Other days17.7%24
Other days20.8%26
Other days17.5%48
Other days26.3%58
Other days26.5%13
Other days24.1%−6
Other days27.3%−39
Other days24.5%−31
Other days25.0%−18
Other days28.0%39
Other days30.1%−14
Other days29.0%49
Other days27.6%13
Other days25.1%15
Other days23.4%57
Other days22.3%37
Other days23.7%−30
Other days24.4%15
High run-through day45.2%−30
High run-through day43.2%−29
High run-through day41.8%−62
Low run-through day13.1%100Best session
Low run-through day13.4%58
Low run-through day13.0%6
Synthetic data. Illustrative values, generated to show the effect: 8 days of three sessions each. Across: the share of all resting volume in the market whose price is run through within one second. Up: the result per lot in that session as an index (100 = the best session, 0 = break-even). On the high run-through day the rate averages 43%, on the low one 13%. The method is as built; the desk’s own figures are confidential.8

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.

Data: Profit five seconds after a fill, by fill size
Size of the fill eventProfit five seconds after the fill (ticks per lot)
1–4 lots0.47
5–14 lots0.04
15–39 lots−0.33
40+ lots−0.77
Synthetic data. Illustrative values, generated to show the effect: 9,000 fill events on one contract, grouped by the size of the fill event (5,503, 2,656, 715 and 126 events), each valued against the mid price five seconds later. A tick is the smallest price step. The method is as built; the desk’s own figures are confidential.13

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 sivi at prices pi, position qt, book mid mt and contract multiplier M, 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.

∑i:ti≤t−sivipiM+qtmtM=At
Cash from fills plus position marked at the mid equals At, the engine’s own profit print, at every print.
Checks of Shuo’s own reconstruction against independent records. A case that fails the gate is debugged, not explained.
CaseCheckResult
A fast close in a thin bookIdentity at every engine printExact on all 2,117 prints
A quiet-market windowIdentity at every per-second printWithin one yuan on 99.97% of 21,874 prints
The stop caseRebuilt account position vs the engine’s profit printEqual on 99.98% of prints
Two products over two monthsEngine P&L vs database P&L per contract-dayEqual on 58 of 62 clean contract-days
Same strategy, opposite daysRebuild vs settlement vs engineGap of zero on every day of the panel
Level-2 archive built from engine prints9.5 million rows vs the tick table0.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.

P&L=∑isivi(mti−pi)M⏟edge+∑tqt(mt+1−mt)M⏟carry
s = +1 for a buy, −1 for a sell. Edge is earned at the fill; carry is what the position does afterward.
Synthetic data. Illustrative values, generated to show the effect: adverse selection grows with the size of the fill event. The method is as built; the desk’s own figures are confidential.
Size of the fill eventFill eventsMark-out after 5 s, ticks per lot
1–4 lots5,503+0.47
5–14 lots2,656+0.04
15–39 lots715−0.33
40+ lots126−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.

Validation of Shuo’s predictor against the engine’s own order log. IT shipped the loop patch that came out of this analysis.
Measure, ten trading days, both sidesValue
Loop ticks predicted / observed2,328 / 2,328
Missed0
False alarms on every other decision0
Lots filled by loop orders0
CycleTwo exchange snapshots
Occurrences under any other setting0

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.

Pseudo-code
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
Pseudo-code. The mechanism tested as a classifier: one prediction per tick and side, scored against what the engine did.
Confusion matrix over ten trading days, both sides of the book: precision 100%, recall 100%.
Every tick and side, ten trading daysEngine sent a loop orderEngine did not
Predicted2,3280
Not predicted0every 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.

R1s=∑ivi1[τi≤1 s]∑ivi
τ: time from fill i until the best bid falls below a filled buy price (or the best ask rises above a filled sell price); v: lots.
Pseudo-code
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
Pseudo-code. Time to run-through for every quote fill, censored at 30 seconds or the session end, and the lot-weighted rate.
Synthetic data. Illustrative values, generated to show the effect: the two highlighted days of the chart above. The method is as built; the desk’s own figures are confidential.
MeasureHigh run-through dayLow 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, −62100, 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.

Synthetic data. Illustrative values, generated to show the effect: shares of requested lots for two order types on the same arrivals, in two periods. The instant fill is identical within a period; only the resting remainder differs. The method is as built; the desk’s own figures are confidential.
Order type and periodFilled at onceFilled laterNever filled or droppedMedian wait of later fills
Limit orders, period 158%22%20%2.9 s
Fill-and-kill, period 158%none42%n/a
Limit orders, period 247%32%21%1.1 s
Fill-and-kill, period 247%none53%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.

Outcome: inconclusive on the first trial and reported as such; the crossover test was specified as the follow-up.
Design elementPurpose
Treated and control contractsA live on/off comparison at similar volume
Same-tape replicaEach contract replayed on its own order book, signal on and off
Minute-block bootstrapUncertainty that respects intraday dependence
Replica-bias checkLive minus replica under each day’s live configuration
Timing checkRules out latency as the source of the bias
Crossover design with power analysisTreated 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.

Data: Price response to one trade, last minutes of trading
Time after the trade (seconds)Measured response
0.0065.1%
0.2582.1%
0.5086.4%
0.7591.7%
1.0095.2%
1.2598.7%
1.5099.1%
1.7599.6%
2.0099.7%
2.2599.8%
2.5099.9%
2.75100.0%
3.0099.2%
3.2598.3%
3.5097.5%
3.7596.6%
4.0096.1%
4.2595.6%
4.5095.1%
4.7594.7%
5.0094.2%
5.2593.7%
5.5093.2%
5.7592.7%
6.0092.4%
6.2592.1%
6.5091.7%
6.7591.4%
7.0091.0%
7.2590.7%
7.5090.4%
7.7590.0%
8.0089.8%
8.2589.5%
8.5089.2%
8.7588.9%
9.0088.7%
9.2588.4%
9.5088.1%
9.7587.8%
10.0087.6%
10.2587.3%
10.5087.0%
10.7586.7%
11.0086.5%
11.2586.2%
11.5085.9%
11.7585.6%
12.0085.4%
12.2585.2%
12.5084.9%
12.7584.7%
13.0084.4%
13.2584.2%
13.5084.0%
13.7583.7%
14.0083.5%
14.2583.2%
14.5083.0%
14.7582.8%
15.0082.5%
15.2582.3%
15.5082.0%
15.7581.8%
16.0081.6%
16.2581.3%
16.5081.1%
16.7580.8%
17.0080.6%
17.2580.3%
17.5080.1%
17.7579.8%
18.0079.6%
18.2579.3%
18.5079.1%
18.7578.8%
19.0078.6%
19.2578.3%
19.5078.1%
19.7577.8%
20.0077.6%
20.2577.3%
20.5077.1%
20.7576.9%
21.0076.6%
21.2576.4%
21.5076.1%
21.7575.9%
22.0075.6%
22.2575.4%
22.5075.1%
22.7574.9%
23.0074.6%
23.2574.4%
23.5074.1%
23.7573.9%
24.0073.5%
24.2573.1%
24.5072.7%
24.7572.3%
25.0072.0%
25.2571.6%
25.5071.2%
25.7570.8%
26.0070.4%
26.2570.0%
26.5069.6%
26.7569.3%
27.0068.9%
27.2568.5%
27.5068.1%
27.7567.7%
28.0067.3%
28.2566.9%
28.5066.6%
28.7566.2%
29.0065.8%
29.2565.4%
29.5065.0%
29.7564.6%
30.0064.3%
30.2563.9%
30.5063.5%
30.7563.1%
31.0062.7%
31.2562.3%
31.5061.9%
31.7561.6%
Public exchange market data: live hog (lh2701 and lh2703), the last five minutes before each session end over several weeks of autumn 2026. The change in the mid price at each 250 ms snapshot was regressed on the signs of the trades in the previous 127 snapshots; the line is the cumulative response to one trade, shown as a share of its peak. A smooth exit pays only when this response fades quickly.
mt−m0=∑s≤tG(t−s)εsvs+ηt,G(ℓ)∝ℓ−γ
ε: trade sign; v: volume; G: the propagator. Measured at the close: γ ≈ 0.19, time constant ≈ 12.5 s, 64% of impact remaining at 30 s.
Pseudo-code
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
Pseudo-code. Mid in ticks and signed trade flow per snapshot, the regressors of the propagator fit. Trades are signed against the previous mid.
Three report versions. Conclusion delivered: keep the current exit.
Alternative to the current clearingTested onVerdict
Wait for the swept price to return2,184 market-wide sweeps, last 15 minutesReturns within 10 s 36% of the time; 7% after large sweeps
Quote reduce-only before the stopRecorded fillsNo gain at any lead time tested
Patient first-level clearing from a minute outRecorded booksNot better
A linear-target schemeRecorded booksNot better
Best start time found in sampleLeave-one-day-outAbout zero
17 execution schedules, theory optimum includedRecorded booksNone better; the smooth ones cost more
Taper the quote size into the stopRecorded books and fillsWorse 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.

In order, August to November 2026. Cases 1 and 13 began with a colleague’s request, case 4 with a colleague’s test and case 5 partly with a colleague’s questions; the other eleven began with Shuo’s own observation or question.
#QuestionMethodVerdict
1Was the market too thin to hedge in during a fast move?Three records cross-checked trade by tradeNo. The hedges filled at the bottom of the move; the first hypothesis was rejected
2What mechanism was behind one sharp session?Engine log lines paired with the exchange book at the same tickOne external sweep against symmetric quotes in a one-tick market
3How 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 classThe gap traced to one order class; told in Smart Queue Review
4Does CHRONOS’s sizing raise profit per lot?Per-period attribution reconciled to settlement, against a control periodA colleague’s test, extended into a daily effect report and four parameter studies
5Why are fills taking longer?A Level-2 archive rebuilt from engine prints; queue-time distributionsA thicker best price and less taker flow: depth divided by flow tracks queue time closely
6Why did a stop not behave as expected?Account position rebuilt from every fill; each action traced to the record it usedRoot cause proved from the logs; engine-side change specified
7Why does one price level flicker?Mechanism read from source, then tested as a per-tick classifierAn engine fault under one setting; 2,328 / 2,328 predicted
8What happened in the final minutes of one session?Edge and carry split; external depth net of own quotesOne minute of inventory carry in a book that was thin, partly because of the desk’s own quotes
9Limit order or fill-and-kill?A natural experiment on the resting remainderLimit: the resting remainder fills later and profitably
10Does the ML signal add value live?Live A/B, same-tape replica, block bootstrap, bias checkInconclusive; crossover design specified and sized in advance
11How do results depend on quote size?Contract-days grouped by quote size; orders classified from the engine’s recordAt very small sizes the exchange’s minimum-size obligation becomes adversely selected top-up fills
12A difficult stretch in a quiet market, with no shock?Mark-outs by the size of the fill eventAdverse selection grows with the desk’s own fill size
13A Monte Carlo study of an exchange ranking rule, for a colleagueMonte Carlo of 2 × 10⁹ draws per scenarioChecked by exact counting; told in Options Ranking Probability
14Same strategy, opposite days?Everything else ruled out; a market-wide run-through rateThe run-through rate tracked session results closely
15Can the closing exit be cheaper?Replays of patient, linear and 17 scheduled exits; a propagator fit; a margin modelNo 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

  1. Case 1 · The fast move that set the methodA colleague’s question answered in 74 minutes; the reconcile-first method is set.
  2. Case 2 · One sweep, one mechanismA draft claim caught on re-derivation and corrected; generated numbers become the rule.
  3. Case 3 · A new queueing strategy, first live sessionLive fills compared with the backtest, order class by order class.
  4. Case 4 · CHRONOS effect validationA colleague’s test becomes a daily report and four parameter studies.
  5. Case 5 · Fill waiting time and liquidityA 9.5-million-row order-book archive, verified against the tick table.
  6. Case 6 · A stop, traced action by actionAccount position rebuilt from every fill; engine-side change specified.
  7. Case 7 · The insert/cancel loopRoot cause in 29 minutes; 2,328 of 2,328 predicted; patch specified, later shipped by IT.
  8. Case 8 · A fast close in a thin bookOne minute of inventory carry; external depth measured net of the desk’s own quotes.
  9. Case 9 · Limit versus fill-and-killLimit orders win, on a natural experiment.
  10. Case 10 · A/B test of the ML signalInconclusive, reported as such; crossover design with power analysis.
  11. Case 11 · Quote size and the exchange obligationResults follow quote size through the exchange’s minimum-size obligation.
  12. Case 12 · A quiet-market windowFull half spread earned; carry decided the outcome, with adverse selection growing with fill size.
  13. Cases 13 and 14 · A ranking-rule Monte Carlo; opposite daysA Monte Carlo for a colleague, and the run-through metric.
  14. Case 15 · The closing exit and a margin modelThree report versions in two days; conclusion: keep the current exit.
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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. 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.
  9. 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.
  10. 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.
  11. 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.
  12. 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.
  13. 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.
  14. 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.
Previous
Previous

CZCE Top Market-Maker Study

Next
Next

FakeSPD Backtester