Market microstructure research platform · Rust + Python

hft-sim

A deterministic exchange, a latency-aware discrete-event simulator, autonomous trading agents and a ten-step market-making ladder. A research layer measures everything from the exchange's own logs, and keeps simulation results apart from historical-market evidence.

8.6 M/s
messages through the matching engine with ~1,000 resting orders (2.4 M/s with ~190,000)
218 + 27
Rust and Python tests passing, with no compiler warnings
134 / 136
deliberately planted bugs caught by the tests; the other 2 proven unobservable
1,136 / 1,136
real Bitstamp order-level snapshots reproduced by the book rebuild

How a simulated market runs

No trader ever sees the true book. Every message takes a sampled amount of time, and every order passes the same gateway checks a real venue would apply.

AgentsNoise, fundamental, informed, technical, pairs, execution, latency-arbitrage and market-making agents
Latency linksSampled delays with heavy tails and spikes; never reordered on a link
GatewaysThrottles, pre-trade risk limits, client ids, ledgers
Matching enginePrice-time priority, auctions, self-trade prevention; a pure function of its input
Delayed feedsOrder-by-order data, private or shared per location, rebuilt into each agent's own book view

The exchange's event log feeds the metrics and the research layer. Every run is reproducible from its seed, down to a digest of the event stream.

What is inside

Each part is specified in its own document and tested against something independent of itself.

Exchange core

Limit and market orders, GTC/IOC/FOK, post-only, cancel/replace with CME-style priority, self-trade prevention, call auctions and halts. It is checked against an independent naive implementation over about 18 million fuzzed commands.

Matching rules →

Simulation kernel

A discrete-event loop with latency profiles per location, gateway sessions, engine queues and delayed market-data feeds. 1,000 agents on shared feeds run 5.3× faster than real time.

Simulation model →

Agents and a calibrated market

A background market calibrated to five stylised facts: cancellation rates, the share of orders executed, a one-tick spread, long-memory order signs and concave price impact. Strategy agents trade against it through the latency model.

Calibration →

Market-making ladder

Ten steps, from a fixed spread to Avellaneda–Stoikov and Guéant–Lehalle–Fernandez-Tapia, with volatility, order-flow, adverse-selection, queue-position and multi-level variants. Formulas transcribed from the papers and checked numerically.

Market making →

Research layer

Rule 600/605 spreads, an exact PnL decomposition, latency races, queue fill rates and order-flow imbalance, all from the exchange's logs. A Python package runs seed grids with confidence intervals and writes the research reports.

Metrics →

Historical data

A Nasdaq ITCH 5.0 reader and a LOBSTER adapter. Real order-level data recorded from Bitstamp's public feed, checked order by order against the exchange's own snapshots; two Nasdaq venues' full equity day rebuilt without an inconsistency; a replay fill model checked against real fills on all three.

Historical data →

Two kinds of evidence, kept apart

A strategy that does well in a simulator has only done well in that simulator. Simulation findings and real-data checks are reported separately, each with its limits.

Simulation stage · phase 4

Eight research questions, 8 seeds each, two backgrounds

  • More inventory aversion gave a market maker more PnL and less inventory risk, through less adverse selection.
  • Signal quality, not the number of informed traders, decided the maker's PnL.
  • Fill probability fell from about 90% at the front of the queue to about 10% behind 500 shares.
  • A remote maker sent about 3× more cancels too late, but lost little PnL.
  • Adverse selection was about a third complete after 50 ms, and complete by 1 s.
  • Order-flow imbalance explained about 5% of 0.1 s price moves and about 60% at 10 s.
  • The adaptive maker beat the static one in all eight settings.
  • More makers meant lower PnL each, more in total, and a deeper book.

The maker made money in nearly every configuration. That is a fact about this simulator, which is why none of it is a profitability claim. Read the results →

Historical stage · phase 5

Real order-level data: Bitstamp BTC/USD and two Nasdaq venues

  • Bitstamp, 19 minutes: the book rebuilt from 365,180 order events reproduces all 1,136 of the exchange's own order-level snapshots. Broken copies of the data are caught down to one satoshi on one order.
  • Run leave-one-out on 172,862 real resting orders, the replay fill model never filled an order the exchange left unfilled, nor one earlier or for more. With the takers' published orders, and history rebuilt without each order, it recovers 292 of 298 real fills at the right millisecond and 99.6% of the volume.
  • The same check found an optimistic trade-through rule in the model, and it was fixed.
  • Nasdaq BX and Nasdaq's main market, 30 December 2019: 29.2 and 268.7 million ITCH messages rebuild without a single inconsistency. For each day's 8 most-traded stocks, the best 10 levels agree with an independent rebuild after all 10 million book changes.
  • Both venues matched orders by price, then by receipt. The apparent queue jumps were orders ranked at a better price than displayed, or received earlier than displayed. Run leave-one-out on 1.24 million real orders, the replay model made no false, early or excess fill, after four corrections the checks themselves prompted.

Two venues, one window each. Read the details →

How correctness is checked

Documents

The full specification and evidence, as written in the repository.