FakeSPD Backtester

Software · Quant research

FakeSPD Backtester 合成价差做市回测

A market simulator for trading the price gap between two delivery months of a commodity. Built from scratch under four weeks into the job, it matched an independent version exactly, picked settings the desk adopted for live trading, and reproduces 85–96% of live volume.

  • Designed and built from scratch by Shuo Huang
  • First run 27 Jul 2026
  • Exact match with an independent implementation
  • Settings adopted for live trading
  • ≈26,000 lines of Python, standard library only
  • 21 hand-computed unit tests

01System architecture

A written spec, one engine, and three independent checks on every number it prints.

The office PC runs plain Python with nothing added, not even numpy or pandas. So the engine is pure standard-library Python, market data arrives as one-click, read-only pulls, and nothing is trusted until a second, independent computation agrees with it.

A colleague’s idea

One-day R backtest

The strategy and the first script: one pair, one day.

Clean room

Written specification

Algorithm, seven parameters, quirks and open questions, written after one reading.

Office PC

Backtest engine

Rebuilds the spread from two legs, quotes, matches, marks. 867 lines, 21 tests.

Output

Reports

Per-fill CSV, equity curves, audit file and a self-contained HTML page with hand-written SVG charts.

Desk database

Tick database

MariaDB: Level-1 ticks, daily volume ranking, contract constants.

Read-only

One-click pull

SELECT-only SQL in monthly chunks that resume where they stopped.

Office PC

Multi-day driver

Streams multi-GB pulls day by day, picks each day’s pair, sweeps windows, extends the grid.

Independent check

Verification battery

Engine-free recompute of P&L, lots and fills; cut-out days re-run through the single-day engine.

Recorded sessions

Engine logs

Order books and fills recorded by the trading engine, session by session.

Office PC

Log parser

Extracts five-level books for both legs and the listed spread; pairs leg fills into spread fills.

Office PC

Spread-book engine

Quotes against the recorded spread book with the queue rule; 20 pricing variants, three fill models.

Independent check

Live validator

Replays live sessions and scores each matching rule against what traded.

Simplified: the lookback sweeps, the snapshot-order check and the legging model for spreads with no listed contract are separate scripts around the same engine. The SPD Parameter Optimizer calls this engine unchanged.

Why a clean room?

A port inherits every blind spot of the original. Shuo read the R file once to write a specification, then built the engine from the specification alone. Two independent implementations that agree exactly prove far more than one that agrees with itself, and comparing them surfaced an edge case that neither handled: a contract locked at its price limit.

Why no pandas?

The engine is Python 3.10 standard library only and its charts are hand-written SVG inside a single HTML file, so a report opens on any desk machine with nothing installed.

Why three checks?

A backtest fails quietly: a missing session shows up as missing profit, never as an error. So every multi-day result is recomputed without the engine, sample days are re-run through the single-day engine, and the matching model itself is scored against live fills.

02The story

An exact match with an independent build, under four weeks into the job, and settings the desk adopted for live trading.

Many commodities trade for several delivery months at once, and the gap between two of those months has a price of its own. A colleague had an idea for making markets in that gap and a one-day test of it. Shuo rebuilt the test from scratch and matched it exactly. Then, on his own initiative, he grew it into a research engine that replays months of recorded market data, tells the desk which commodities the idea pays on, picked settings the desk adopted for live trading, and was itself graded against live trading.

  1. 01

    The problem

    A futures exchange lets you trade the gap between two delivery months as one order: buy January soybean oil and sell May at a stated price difference. These spread orders are listed as contracts of their own (the Dalian exchange names them SP, Zhengzhou SPD), each with its own order book. On the desk, “SPD” is simply the word for a spread’s price.

    Market making means standing ready to both buy and sell, and earning the small gap between your two prices. A colleague had a strategy for doing that in spreads: work out what the spread should cost from the two months’ own prices, then offer to buy a little below and sell a little above.1 Nobody could say whether it would make money, because the evidence did not exist. Many listed spread books barely traded, and there was no recorded history for them to test against.

    • The spread’s own price board was blank or missing.
    • The only test was one script, for one pair, on one day.
    • A simulator that is wrong does not crash. It prints a profit.
  2. 02

    What he built

    Under four weeks into the job, Shuo was invited to write his own version so the two could be compared. He did not port the script. He read it once to write a specification, then built an independent Python engine from the specification alone, never reopening the original. The two agreed exactly on both test pairs, and comparing them surfaced an edge case that neither version handled.2

    The engine prices the spread the way you would price a pair of tickets from the two single fares when the pair’s own price board is blank: it rebuilds the spread, tick by tick, from the two months’ live quotes. That is the “fake” in FakeSPD. It then plays the strategy against months of recorded markets and reports profit, profit per lot (one lot is one contract) and how many days were positive.

    On his own initiative he then turned a one-day script into a research engine in three weeks, and kept building: about 26,000 lines of Python in all.3

    • Multi-day runs that pick the two most-traded contracts each day and follow them as trading moves from one delivery month to the next
    • Parameter sweeps that extend themselves when the best value sits on the edge of the grid
    • A verification battery that recomputes every result without the engine
    • A decoder for the trading engine’s logs, so the simulator can be scored against what really traded

    It built on habits he already had. An earlier silver calendar-spread backtest of his had been reconciled with a colleague’s independent calculation with zero mismatches across 61,665 common timestamps, and he had already made the desk’s market-making simulator run directly from exchange tick files.4

  3. 03

    What changed

    The desk adopted the settings this backtester picked for live trading.5

    The screening gave the desk an answer per commodity instead of an opinion. In half-year backtests, mean-reverting spreads paid on almost every trading day, flat ones were ruled out, and trending spreads lost about the quoted edge per lot: the signature of being picked off, filled only when the price is about to move against you.6

    Then the simulator itself was put on trial. When live traders reported their quotes sitting behind long queues, Shuo designed a way to model a queue in an order book that never reports a trade, after three conventional queue models had failed on that data. Checked later against live sessions and the exchanges’ official matching rules, his queue model reproduced 85–96% of live volume with no tuning. The original fill rule managed far less, so the queue model was adopted as the matching model, and every earlier listed-spread result that depended on the old rule was marked reference-only.7

    His suspicion that one default setting was holding the strategy back then became the SPD Parameter Optimizer, whose picks the desk went on to trade.

85–96%

of live trading volume reproduced by his queue-based fill model, with no tuning; the rule it replaced managed far less7

2

independent implementations, one in R and his in Python, in exact agreement on both test pairs2

20

quoting variants ranked under three fill models on recorded spread order books8

23

commodities on three Chinese futures exchanges run through the engine9

43GB

of tick data replayed, up to 12.7 million rows per product per half-year10

3weeks

to grow a one-day test script into a multi-day research engine, on his own initiative

03Evidence

Only the queue rule trades the way the live desk did

The validation replays live sessions under each rule for deciding when a resting quote fills. The quoting logic never changes and nothing is fitted, so it is a test, not a calibration. On the live sessions the queue rule reproduced 85–96% of live volume.7 The chart shows the shape of that result.11

Simulated against live volume, by fill rule

Only the queue rule lands near live volume on both spreads, with no tuning; the two touch rules fall far short.

Show the dataHide the data
Data: Simulated against live volume, by fill rule
CategorySpread 1Spread 2
Leg touch30%42%
Book touch6%11%
Queue rule90%93%
Synthetic data. Illustrative values, generated to show the effect: two anonymous listed spreads; 100% means the simulation traded exactly the live volume. Leg touch is the original rule (fill when the leg-implied spread touches the quote); book touch fills a quote only when the spread’s own book trades through it; the queue rule is Shuo’s. The method is as built; the desk’s own figures are confidential.

04Functions

From a one-day cross-check to the desk’s reference for spread backtests.

A

Rebuild and reconcile

An independent engine written from a specification alone, so that agreement with the original is evidence and not an echo.

  • Specification first: algorithm, seven parameters, every quirk and seven open questions, written before a line of code
  • 21 hand-computed unit tests: touch inclusivity, warm-up, withdraw boundaries, skew, limit stop, session edges
  • Exact agreement with the colleague’s R version on both test pairs2

B

Catch the fills that could not happen

The cross-check surfaced an edge case that neither version handled: a contract locked at its price limit has an empty side, and an unguarded synthetic quote trades against nothing.

  • One leg sat at limit-up for 13 minutes; 4,233 of that afternoon’s 4,702 simulated fills were impossible12
  • Removing them flipped the simulated day from an apparent profit to a small loss
  • Kept as a guarded mode; across the half-year runs it changed nothing, so those results carry no such artifact

C

Scale from one day to a year

A multi-day driver that needs no hand-holding through contract rolls, odd trading hours or multi-gigabyte files.

  • Each day’s pair chosen automatically from the volume ranking: the most-traded contract triggers, the second is quoted
  • Trading sessions inferred from the ticks themselves and cross-checked against the official exchange hours, so a session table can never silently cut a session short
  • Grid auto-extension: if the best window is the largest tested, the sweep widens until it is not. On one spread the true optimum sat well beyond the original grid’s ceiling

D

Sort the spreads that pay from the ones that do not

Same engine, same parameters, twelve commodities: the results differ by orders of magnitude, so choosing the product is itself a source of return.

  • Mean-reverting spreads pay: in half-year backtests they were profitable on almost every trading day6
  • Trending spreads lose about the quoted edge per lot: the signature of adverse selection, filled only when the price is about to run through the quote
  • The window is a regime parameter: shortening it rescues nothing on a trending spread and destroys an oscillating one

Days with a backtest profit, by spread

Same engine, same settings: three spreads are profitable on almost every day, two on almost none.

Show the dataHide the data
Data: Days with a backtest profit, by spread
SpreadTrading days with a backtest profit (%)
Spread A99%
Spread B99%
Spread C98%
Spread D76%
Spread E49%
Spread F6%
Spread G0%
Synthetic data. Illustrative values, generated to show the effect: seven anonymous spreads, 100 simulated trading days each. Spreads A to C mean-revert, D is modest, E is flat and earns nothing per lot, F and G trend. The method is as built; the desk’s own figures are confidential.6

E

Model a queue in a book that prints no trades

Exchange spread books report zero volume, because the trades are booked on the two legs. Three conventional queue models failed on that data; Shuo’s rule reads the trades off the book itself.

  • Size at the desk’s price falls from 15 to 13: two lots traded ahead of the desk, and the desk’s place in the queue moves up by two
  • The level vanishes while the market moves past it: the whole level traded, the desk’s included
  • With it, the simulator’s fills began to track the live fills8

F

Hold the simulator up to live trading

The live side is decoded from the trading engine’s own logs, then the same sessions are replayed under every candidate matching rule.

  • Leg fills paired back into spread fills by their shared exchange order id; one live day reproduced the desk’s own record exactly
  • Spread-book queue rule: 85–96% of live volume, untuned. The original touch rule: far less7
  • The remaining gap was decomposed cause by cause: order size, the sessions the strategy actually quoted, its intraday schedule. A calibrated fill threshold failed a split-sample test and was not adopted

G

Become the reference

Once the engine could reproduce itself, it became the desk’s yardstick for other spread backtests.

  • Four other spread studies were reconciled against his engine and each discrepancy traced to its root cause
  • Each study was re-run from its own code and data before a cause was named: one reproduced on 1,620 of 1,620 runs
  • It is the evaluation engine inside every cycle of the SPD Parameter Optimizer, whose picks the desk went on to trade

05Under the hood

The simulator, three fill models and the test against live trading.

Under the hoodSpread construction, quoting loop, three fill models, live validation, gap attribution, pseudo-code

An event-driven tick replay of market making in a leg-synthesized calendar spread, in pure standard-library Python. The fair-value model is deliberately simple, a moving average with a proportional inventory skew, and it is a colleague’s design.1 The engineering is in everything around it: a specification that pins every quirk, reconciliation with an independent implementation, a fill model for a book that prints no volume, and an out-of-sample test of that fill model against live fills, with nothing fitted.

Building the synthetic spread

Both legs’ Level-1 rows are walked in receive-time order, keeping each leg’s latest bid, ask and mid. Only rows of the trigger leg (normally the more liquid month, which is also the hedge) are decision points; each pairs a fresh trigger quote with the quoting leg’s latest quote. The spread mid, the synthetic spread’s bid and ask, and the fair value are below. The lookback L counts trigger-leg rows, so the same L spans twice as much clock time on an exchange that publishes every 500 ms as on one that publishes every 250 ms. During warm-up the fair value follows the current spread.

Each trading session is an independent backtest: flat at the start, flattened at the end at the last spread mid. Session windows are trimmed five minutes at both ends, and night sessions that run past midnight are split.

Sj=mtrig−mquoteSjbid=btrig−aquoteSjask=atrig−bquoteθj=1L∑i=j−Lj−1Si
m, b, a: mid, best bid and best ask of the trigger and quoting legs at trigger-leg row j. S: leg-implied spread. θ: fair value, the mean of the previous L spread mids (current row excluded).

The quoting loop

On every trigger row, in this exact order: compute the fair value; match resting orders against the row; skew for inventory; stop if the trigger leg is close to a price limit; withdraw quotes too close to fair value; post one new level per side; prune to the best levels kept. Here q is net position in lots, n the order size, τ the tick, e the quote edge in ticks and δ the skew gain: a proportional inventory controller, so a long position pushes both quotes down.

In the reference fill model a resting bid at price p fills when p≥Sask and a resting ask when p≤Sbid: inclusive, at the desk’s price, full size. There is no queue, no partial fill and no fee layer.

Session P&L is the contract multiplier times the signed cash of every fill plus the closing flatten, and profit per lot divides it by all lots traded. The engine reports every result per lot, in ticks, because a market maker’s volume is bounded by exchange rules and risk limits, so the scarce resource is lots, not opportunities.

θ~j=θj−δ·qjn·τpbid=⌊θ~j−eττ⌋τpask=⌈θ~j+eττ⌉τ
Inventory-skewed fair value, then the bid floored and the ask ceiled to the tick grid.
Pseudo-code
for each update of the trigger leg:
    fair      = mean of the previous L spread mids        # current row excluded
    fill resting quotes that the market has reached
    fair_adj  = fair - skew_gain * (position / order_size) * tick
    if the trigger leg is close to its price limit: stop quoting
    cancel bids at or above  fair_adj - withdraw_edge
    cancel asks at or below  fair_adj + withdraw_edge
    post a bid at  floor_to_tick(fair_adj - edge)         # unless one rests there
    post an ask at ceil_to_tick(fair_adj + edge)
    keep only the best K levels on each side
Pseudo-code. The quoting loop as high-level steps, one pass per update of the trigger leg.

Three fill models, and why the first two fail on a listed spread

1. Leg-implied touch (the reference rule). Fill when the leg-implied spread touches the desk’s price. It under-fills listed spreads badly, because spread market makers sit inside the leg-implied spread: the spread’s own book is far tighter than the book implied by the two legs, so most fills happen at prices the leg-implied spread never reaches.

2. Spread-book touch. Fill when the listed spread book’s opposite best crosses the desk’s price. A passive quote capped at the touch can then fill only when the book moves through it, which is the adverse-selection half of market making. The ordinary fill, someone hitting a resting order, leaves no trade print on a spread book, so this rule never sees it.

3. Book-diff queue (Shuo’s rule). Queue position is the visible size at the desk’s price when the desk joins. A decrease in that size is read as trades ahead of the desk; a level that vanishes while the market moves past it is read as fully traded; a level that merely leaves the visible five carries no information and earns no credit. Three conventional queue models had failed on this data first: consuming the queue with traded volume is a silent no-op when reported volume is always zero, and crediting progress only while the size is seen shrinking collapsed simulated fills to almost nothing.

A size decrease can be a cancellation, so the rule is optimistic by construction: on the same days it produces many times the fills of rule 2, and the truth sits between. The live validation measured the bias with a factor κ, the share of each decrease counted as traded. Even κ=1 slightly under-fills live trading, so it was kept.

How wide each book is when a quote fills

The book the touch rule watches is 2.5 to 3.4 times wider than the spread’s own book, and most fills are priced inside it.

Show the dataHide the data
Data: How wide each book is when a quote fills
CategorySpread’s own bookLeg-implied book
Spread 11.86.2
Spread 21.74.2
Synthetic data. Illustrative values, generated to show the effect: the width of each book just before a fill, weighted by lots, on two anonymous listed spreads. In this illustration 70% and 58% of fills are priced strictly inside the leg-implied book, where a touch rule cannot fill. The method is as built; the desk’s own figures are confidential.
Qt+1=Qt−κ·max(0,Vt−Vt+1),fill whenQt+1≤0
Q: size still ahead of the desk’s order at a price. V: displayed size at that price in consecutive snapshots. κ = 1 counts every decrease as a trade; a smaller κ under-fills further.
Pseudo-code
on each new snapshot of the spread's own order book:
    for each of our resting bids, at price p:
        before = displayed size at p in the previous snapshot
        now    = displayed size at p in this snapshot
        if p was not visible before: skip              # no information, no credit
        if p is no longer visible:
            if the best bid is now below p: fill       # level swept, so we traded too
            skip                                       # it only left the visible five
        if now < before:
            queue_ahead[p] -= kappa * (before - now)   # read as trades ahead of us
            if queue_ahead[p] <= 0: fill
    # the ask side mirrors this
Pseudo-code. The bid side of the book-diff queue rule, simplified; the ask side mirrors it.

Validation against live fills

Recorded market data for two exchange-listed spreads were replayed with each session’s own parameters and order-size schedule, inside each live session window. The quoting logic is identical under every rule; only the matching rules change. Nothing was fitted, so the comparison is a test of each rule and not a calibration.

The first rule fails for a structural reason: a passive quote at the spread book’s own best price fills at a level the leg-implied spread rarely reaches.

The verdict, matching model 3: a queue of directly entered orders in the spread book with κ=1; one decision per complete exchange snapshot; implied fills (orders the exchange derives from the legs, which by rule queue behind every directly entered order and never show in market data) only once the desk is at the front; continuous sessions only. Spreads with no listed contract are modeled as two legged orders with leg queues. On the live sessions the adopted rule reproduced 85–96% of live volume with no fitted parameter.7

Synthetic data. Illustrative values, generated to show the effect: ratios of simulated to live volume on two anonymous listed spreads; 1.00 is a perfect match. The adopted rule sits closest to live volume, the touch rules miss most of it, and every rejected alternative lands further away. The method is as built; the desk’s own figures are confidential.
Matching ruleSpread 1: volume ÷ liveSpread 2: volume ÷ live
Spread-book queue, κ = 1 (adopted)0.900.93
Spread-book queue, κ = 0.50.540.49
Leg-implied touch (the original rule)0.300.42
Spread-book touch, no queue credit0.060.11
Implied orders priced off the previous snapshot2.401.68
Adding immediate taker fills on crossing1.751.70

Closing the live gap one cause at a time

A single ratio of simulated to live volume can sit at 1.00 while individual days miss badly in both directions: opposite errors cancel. So the comparison did not tune anything toward the live total. Shuo decoded the live side from the engine logs (leg fills paired into spread fills by their shared exchange order id, every parameter and intraday change recovered per day) and removed one known difference at a time.

The first-order gap was order size, then the days on which the strategy was actually switched on, then its intraday size changes, then the sessions in which it was not quoting at all. A proposed fill threshold calibrated to live results failed a split-sample test and was not adopted.

The attribution, step by step. The ratios themselves are the desk’s and are not shown.
StepWhat was matched to liveWhat it showed
1. Fixed one-lot ordersNothing yetSimulated volume far below live
2. Each day’s first order size, active days onlyOrder size, active daysThe aggregate lines up while single days still miss in both directions
3. The intraday size scheduleEvery logged size changeVolume overshoots: the simulation still trades in sessions the strategy sat out
4. Only the sessions the strategy quotedThe quoting sessionsThe overshoot shrinks

From screening to adoption

The screening rounds used the leg-implied touch rule, so they rank products and point at parameters; they are not profit forecasts, and the page says so wherever they appear.6 The lookback was chosen per product by half-year sweeps, and the desk adopted windows those sweeps picked for live trading.5

The sweeps also extend their own grid whenever the best window sits on its edge (up by ×1.25, ×1.5, ×2, ×3; down by ×0.75, ×0.5, ×0.25; at most three rounds). On one spread the extension moved the backtest optimum well beyond the original grid’s ceiling.

Two cross-product findings survived every later round. The lookback is a regime parameter: short windows cut losses on trending spreads and destroy oscillating ones. On a trending spread every session-by-window cell of the sweep was negative, and a short window reduced the loss without ever rescuing it; on an oscillating one the same shortening flipped a profitable day to a loss. And losing products paid away almost exactly the quoted edge per lot despite completely different tick sizes, multipliers and volumes, because fills arrive only when the spread runs through the quote and keeps going.

Synthetic data. Illustrative values, generated to show the effect: seven anonymous spreads, 100 simulated trading days each, profit per lot in units of the quoted edge. The screening itself ran under the leg-implied touch rule at the reference parameters: touch = fill, no queue, no fees, flatten at mid. The method is as built; the desk’s own figures are confidential.
SpreadDays with a profitPer lot, in quoted edgesReading
Spread A99 / 100+0.57Mean-reverting: hit, then the spread comes back
Spread B99 / 100+0.59Mean-reverting: hit, then the spread comes back
Spread C98 / 100+0.65Mean-reverting: hit, then the spread comes back
Spread D76 / 100+0.34Modest: pays on most days, thinly
Spread E49 / 100−0.01Flat: too static for its tick. Ruled out
Spread F6 / 100−0.93Trending: about one quoted edge lost per lot
Spread G0 / 100−1.01Trending: about one quoted edge lost per lot

What the spread’s own order book said

Live traders reported quotes resting behind long queues. Parsed from recorded order books, the complaint became measurable on every fill: the size already resting ahead of a new quote, how often an order reached the front of its queue, and how often a fill faced a large resting order on the opposite side.

A colleague proposed three pricing ideas: tilt fair value by the book’s imbalance, clamp it away from thick levels, or price off the spread’s own book (plain or size-weighted mid). Shuo built the engine that tests them: 20 variants under three fill models, with queue metrics on every fill, ranked by profit per lot.8

  • The fill model decides the answer. The unmodified strategy came out positive under the queue rule and negative under spread-book touch, on the same days and quotes. Ranking pricing ideas before fixing the fill model would have ranked artifacts.
  • Book-aware pricing helps. Under the queue rule every book-aware variant beat the unmodified strategy on profit per lot.
  • The weighted mid is a sub-tick effect. It differs from the plain mid by less than half a tick at the median, which rounding to the price grid erases, so book imbalance works better as a tilt of fair value than as a different mid.
  • Robustness over rank. The variant that held up under all three fill models priced off the spread book’s size-weighted mid inside a protection band.

Questions a quant will ask

  • Why a moving average and not a fitted model? The fair-value rule is the strategy as the colleague specified it. The engine’s job was to measure that strategy honestly, and the sweeps show how much rides on its single window.
  • Why count the window in rows and not seconds? The strategy re-prices on updates of the trigger leg, so rows are its clock, and the engine’s spread arithmetic was checked against recorded spread values.
  • Why not fit κ to the live fills? A spread book prints no volume, so κ cannot be identified from market data, and a handful of live sessions is a test set, not a training set. The untuned value already lands within 4–15% of live volume and errs on the conservative side.
  • Why not get a bigger sample from a reconstructed book? A spread book rebuilt from the legs matched the listed book’s best prices less than 5% of the time. More days of the wrong object is not a larger sample.
  • Is a short run of live sessions enough? Enough to reject a rule that falls far short of live volume, and the limits are stated: two listed spreads on one exchange, and replayed books that contain the live strategy’s own orders. Earlier listed-spread results stay reference-only until re-run.
  • Why no fees or slippage? Results are gross, in ticks per lot, and the closing flatten is a mark at the mid, not an executable price. That is why the screening results are labeled as screening.

Failure modes engineered out

  • Limit lock. A leg pinned at its price limit has an empty side; the synthetic quote then trades against nothing. Guarded mode suppresses any fill built on an empty book side.
  • Stale leg. Exchanges publish every contract’s snapshot in contract-code order, so a trigger row that arrives first pairs a new price with the other leg’s old one: a spread that never existed. A same-snapshot re-run measures the effect, and the adopted matching model decides once per complete snapshot.
  • Grid edge. An optimum on the boundary of the grid is a statement about the grid. The sweep extends itself and the report carries a boundary warning.
  • Delivery month and expiry. Pair selection follows volume, and reports highlight every pair change, so a roll cannot hide inside an average.
  • Wrong sessions. Trading hours are not in the database. The session layout is inferred from which hours the ticks occupy and compared with the hand table; it reproduced the table for all eight products tested.
  • Wrong object, bigger sample. A spread book reconstructed from the legs matched the listed spread book’s touch less than 5% of the time, so it was rejected as a stand-in: more days of the wrong object is not a larger sample.
  • Self-agreement. Every refactor is re-proven byte-identical on an earlier run, and every multi-day result is recomputed from the fills file by a script that does not import the engine.

Built with

  • Python (standard library only)
  • SQL · MariaDB
  • Backtesting
  • Event-driven tick replay
  • Market microstructure
  • Order-book queue modeling
  • Fill-model validation against live trades
  • Grid search with automatic extension
  • Split-sample testing
  • Clean-room specification
  • Unit testing
  • Reconciliation with an independent implementation
  • Log parsing
  • SVG / HTML reporting

06Releases

Shipped in versions, like a product.

  1. Specification, engine, first runSpecification written, engine built from it, 13 hand-computed tests passing, and the limit-lock artifact found on the first day.
  2. Cross-check passedExact agreement with the independent R implementation on both test pairs. First lookback sweeps.
  3. Multi-day driverDaily automatic pair selection with roll handling; the first 20-day runs.
  4. Half-year runsHalf-year replays of four products from chained one-click pulls.
  5. Grid auto-extensionA best value on the edge of the grid now widens the sweep by itself.
  6. Order-book variants and the queue ruleListed spread books parsed from recorded sessions; book-diff queue fill rule; 20 pricing variants ranked by profit per lot.
  7. Edge sweepA 12-month run on two Dalian products and a sweep of the quote edge: the starting point of the SPD Parameter Optimizer.
  8. Live vs backtestLive fills decoded from engine logs and compared with the backtest, one cause at a time.
  9. Snapshot order and leggingSame-snapshot re-run and a legging model for spreads with no listed contract.
  10. Matching model 3Fill model checked against the official exchange matching rules and against live sessions; the spread-book queue adopted.
  1. 1The strategy idea and the first one-day R backtest are a colleague’s. The independent engine, the multi-day research tooling, the queue rule, the live comparison and the matching study are Shuo Huang’s.
  2. 2The colleague’s R script and the Python engine written from the specification, compared on two contract pairs (styrene and LLDPE) for one trading day with identical parameters.
  3. 3About 26,000 lines across about 140 Python scripts in the project: the engine and its drivers (about 10,000 lines in 45 scripts, including the SPD Parameter Optimizer built on the engine), the order-book variant engine, the live comparison, the audits, the matching study, SQL generators and the runner. A colleague’s code, backups and archives are excluded.
  4. 4Earlier work by Shuo Huang on the same desk: a silver calendar-spread backtest, and a runner that feeds the desk’s market-making simulator from exchange tick files.
  5. 5Which settings, on which spreads and when, and the live results, are confidential. The strategy was designed by a colleague, the live strategy code is the desk engine’s, and going live was a desk decision.
  6. 6Backtests under the reference fill rule at the reference parameters: a touch counts as a fill, with no queue and no fees, positions flattened at the mid at each session end. They screen products and point at parameters; they are not realizable returns. Per-product results are confidential.
  7. 7Simulated volume ÷ live volume for the spread-book queue rule with no fitted parameter, on live sessions of two exchange-listed spreads replayed with each session’s own parameters and order-size schedule: 85–96% across the two. The original leg-implied touch rule reproduced far less. Results of that original rule on listed spreads are treated as reference-only until re-run on spread-book data.
  8. 8The unmodified strategy and 19 variants replayed on recorded order books of listed spreads. The quoting-variant ideas tested in the study were a colleague’s.
  9. 912 commodities in the backtester’s own research rounds (Dalian and Shanghai exchanges) and 11 more through the SPD Parameter Optimizer, which calls this engine unchanged (adding Zhengzhou): 23 commodities on three exchanges.
  10. 10Size of the tick pulls held for this project: 43 GB in 34 files. A half-year pull is 8.6 to 12.7 million tick rows per product.
  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. 12One styrene trading day in July 2026, replayed from public exchange tick data: one leg was locked at limit-up for 13 minutes of the afternoon session. The fills are simulated ones.
Previous
Previous

Desk Analysis Cases

Next
Next

Smart Queue Review