project

C++ Limit Order Book & Market-Making Simulator

Matching Engine, ITCH Replay, Market-Making Diagnostics, and Artifact Validation

result3.7M events/sec benchmark, 12,423 QQQ ITCH messages, 30-seed strategy statistics, 10-seed fill-rate diagnostics, and validator-backed artifacts.

A systems-focused market microstructure project implementing a deterministic C++ matching engine, benchmark harness, ITCH replay path, and market-making simulator for comparing naive symmetric quoting with Avellaneda-Stoikov-style inventory-aware quoting under controlled synthetic and ITCH-calibrated flow.

status: complete CTest: 69/69 passed pytest diagnostics: 21 passed ruff: clean CI: green validator: passed

Problem

Can I build a C++ market microstructure simulator whose claims are backed by deterministic matching behavior, reproducible benchmarks, bounded real-data replay, risk controls, paired statistical testing, mechanism diagnostics, and artifact validation?

Approach

Implemented the matching engine, replay tools, market-making simulator, benchmark harness, strategy comparison, queue diagnostics, fill-rate mechanism pass, and artifact validator as one reproducible research stack.

The project deliberately separates strategy comparison from mechanism validation: Stage 5C is the stronger 30-seed strategy-statistics pass, while the fill-rate extension is a focused ten-seed diagnostic for sparse execution flow versus queue position.

What it implements

  • Price-time priority matching engine
  • Partial fills across levels
  • Cancel and replace
  • Self-trade prevention
  • CSV replay
  • Direct external_execute support
  • Map and flat order book variants
  • Benchmark harness
  • Nasdaq ITCH replay
  • Naive and Avellaneda-Stoikov market makers
  • PnL attribution and reconciliation
  • Risk controls and terminal liquidation
  • Paired same-seed statistical testing
  • Queue-position diagnostics
  • Quote lifecycle tracking
  • Execution opportunity audit
  • Artifact validator

Main finding

The strongest final microstructure result is not a profitability claim. The checked diagnostics show that ITCH-calibrated fill-rate collapse is dominated by sparse external executions rather than queue burial.

Physical first-in-queue placement does not materially rescue fill rates, while increasing execution intensity and slowing requotes move fills in the expected direction.

Headline results

Synthetic benchmark1,000,000 events at about 3.7M events/sec on Apple M3
ITCH replay12,423 bounded QQQ messages translated and replayed
Strategy statistics30-seed Stage 5C paired strategy pass
Quote lifecycle rows252,000 in the full fill-rate pass
Execution opportunity rows50,304
Paired-difference rows4,500
Physical zero-queue rows30,000 validated with initial_queue_ahead == 0
Test status69/69 CTest, 21 pytest diagnostics, ruff clean

What failed or changed

The early synthetic flow overstated execution activity relative to the bounded ITCH sample.

The flat order book initially looked faster than the map book on one paired run, but longer diagnostics showed the result was workload and host-noise sensitive rather than a general array-book win.

The initial strategy framing was too broad. Stage 5C supports selected inventory-risk and risk-adjusted improvements under hand-chosen flow, not broad PnL dominance.

The queue-position diagnostic showed queue depth matters, but the follow-up fill-rate extension narrowed the final mechanism finding: sparse executions dominate the checked ITCH-calibrated fill-rate collapse.

What improved

Added a focused ten-seed fill-rate mechanism pass with 3 regimes, 2 strategies, 8 scenarios, and a physical zero-queue scenario.

Generated full fill-rate artifacts: 252,000 quote lifecycle rows, 50,304 execution opportunity rows, 4,500 paired-difference rows, and 60 zero-queue comparison rows.

Validated the physical zero-queue invariant: all 30,000 physical zero-queue quote rows had initial_queue_ahead == 0.

Strategy finding

The strategy comparison is intentionally narrow. Stage 5C supports selected inventory-risk and risk-adjusted improvements for Avellaneda-Stoikov under hand-chosen flow, but not broad PnL dominance.

Under ITCH-calibrated sparse flow, strategy effects are much smaller than flow-profile effects.

Validation

  • CTest: 69/69 passed
  • Pytest diagnostics and artifact validator: 21 passed
  • Ruff: all checks passed
  • CI green on main
  • Markdown links clean
  • Artifact validator checks schemas, full-mode coverage, same-seed pairing, physical zero-queue invariant, fill decomposition reconciliation, execution-opportunity reconciliation, no-fill taxonomy, PnL identities, mechanism monotonicity, and stale/overclaim wording.

Final interpretation

Sparse execution flow, not queue burial, dominates the checked ITCH-calibrated fill-rate collapse. Physical first-in-queue placement does not materially rescue fills, while increasing execution intensity and slowing requotes move fill rates in the expected direction.

This is a controlled simulator diagnostic, not live trading evidence.

Limitations

  • One-instrument simulator.
  • Bounded public QQQ ITCH sample, not a full-day market reconstruction.
  • Synthetic regimes are controlled experiments, not live trading evidence.
  • No hidden liquidity, auctions, pegged orders, venue-specific order attributes, full exchange participant identity, or full venue model.
  • Not production trading infrastructure.
  • No trading edge or profitability claim.
  • No broad Avellaneda-Stoikov superiority claim.
  • Stage 5C remains the stronger 30-seed strategy-comparison pass; the fill-rate extension is a ten-seed mechanism-validation pass, not a broad strategy-confidence result.

How to reproduce

The repository includes CMake build commands, CTest coverage, benchmark artifacts, ITCH replay artifacts, paired delta outputs, queue-position diagnostics, fill-rate artifacts, and the artifact validator.

The README gives the main commands; the research note and fill-rate diagnostics doc keep the stage-by-stage numbers, caveats, validation checks, and final interpretation.