← All work
Simulation2026 / 10

MERCURY

A research-grade market simulator that shows how order-book rules, agent behavior, liquidity withdrawal, and controls shape market stress.

PythonAgent SimulationPytestQuarto
Source & deliverables
18benchmark scenarios
67passing tests
61%fragility reduction
9,549rebalancer net P&L
01 / Context

The question
behind the work.

Static price models cannot show how order-book rules, heterogeneous strategies, liquidity withdrawal, fees, and regulation interact to create or contain instability.

My role

I built the simulator, exchange mechanics, agent strategies, benchmark scenarios, stress controls, metrics, test suite, parameter sweeps, plots, and reproducible reporting workflow.

02 / Implementation

What I built.

MERCURY combines a continuous double auction, heterogeneous trading agents, fragmented venues, benchmark scenarios, parameter sweeps, and reproducible reports.

  • Implemented a continuous double auction with price-time priority, partial fills, cancels, replaces, iceberg orders, pegged orders, and maker-taker accounting.
  • Designed market-making, momentum, arbitrage, execution, panic, stop-loss, spoofing, and venue-arbitrage agents.
  • Added flash-crash, cross-asset, fragmented-venue, liquidity-withdrawal, and circuit-breaker experiments.
  • Built benchmark and sweep tooling that ranks cases by fragility and publishes reproducible plots and reports.
03 / In detail

The exchange engine

MERCURY starts with a continuous double auction rather than a prewritten price path. The exchange handles price-time priority, partial fills, cancels, replaces, iceberg orders, pegged orders, and maker-taker accounting, so prices, depth, and spreads emerge from the interaction inside the book.

I added market-making, momentum, arbitrage, execution, panic, stop-loss, spoofing, and venue-arbitrage agents to give the market different sources of liquidity, pressure, and feedback.

Stress behavior as a measurable output

The scenario library covers flash-crash formation, liquidity withdrawal, cross-asset spillovers, fragmented venues, fee economics, and circuit-breaker controls. Each experiment records market-quality and strategy outcomes rather than relying on a single price chart.

In the circuit-breaker comparison, measured fragility fell from 54.7493 to 21.0714 and crash detections fell from 45 to 9. Cross-asset and venue experiments also produced dislocation, routing, and P&L measures that can be compared across runs.

Research workflow around the simulator

I built benchmark, sweep, plotting, and reporting tooling around the exchange so one scenario can become a repeatable research family. Parameters, objectives, rankings, and visual outputs are kept outside notebook state and published through the same workflow.

The platform includes 18 benchmark scenarios and 67 passing tests across matching mechanics, metrics, reporting, and visualizations. The report bundle lets a reader inspect the conditions, figures, and results without rebuilding the environment from scratch.

04 / Engineering judgment

The decisions
that shaped it.

  1. Modeled events through an actual order book instead of applying exogenous price paths, allowing crashes and dislocations to emerge from interaction.
  2. Kept scenarios configuration-driven so market rules and participant behavior can be compared under the same measurement layer.
  3. Separated simulator, metrics, benchmarks, plotting, and reporting so research outputs do not depend on notebook state.

Evaluation & results

The system contains 18 benchmark scenarios and 67 passing tests. In the circuit-breaker comparison, measured fragility fell from 54.7493 to 21.0714 and crash detections fell from 45 to 9. Cross-asset and fragmented-venue experiments also produced measurable dislocation, routing, and P&L outputs.

05 / Working outputs

See it for yourself.

Select an image to view it at full size.

06 / Artifacts

Take a closer look.

01Research report02Benchmark summary03Reproduction commands
Next projectFulfillment Risk Simulation