Agent-Based Order Flow Simulation

Why Not Just Use a Random Walk?

The textbook model of price movement is geometric Brownian motion:

P(t+1) = P(t) * exp(mu*dt + sigma*sqrt(dt)*Z)

It's elegant, but it is also wrong in every way that matters for a trading simulator. Real price action has clustered volatility, microstructure noise, bid-ask bounce, order flow imbalance, and liquidity-dependent impact. A random walk gives you none of that.

We needed a price generation model that produces tick-level data a trader can actually practice against: realistic spreads, variable liquidity, institutional sweeps, momentum cascades, and the kind of sticky S/R levels that emerge from resting order flow. So we built one from the ground up using agent-based modeling.

The Architecture

The tick engine runs a simulation each second of the trading session. At its core is a limit order book (LOB) populated by four agent types, each operating on different time scales and with different objectives. Their aggregate behavior produces emergent price dynamics that match the statistical properties of real market data without being scripted.

The approach draws from the tradition of agent-based financial modeling pioneered by Cont and Bouchaud (2000) and extended by subsequent work on LOB dynamics.

Reference: Cont, R. & Bouchaud, J.P. (2000). "Herd Behavior and Aggregate Fluctuations in Financial Markets." Macroeconomic Dynamics, 4(2), 170-196. arXiv:cond-mat/9712318

The Four Agents

Market Makers refresh the order book each tick, posting bids and offers around the mid price. Their spread widens with local volatility:

spread = tick_size * base_spread * (1 + vol_multiplier * realized_vol)

This produces tight spreads during quiet periods and wide spreads during fast moves, exactly as observed in real futures markets.

Institutional Flow arrives in bursts. When triggered (at a configurable rate per second), an institutional agent commits to a direction with persistence probability p and places a sequence of orders over multiple seconds:

P(continue same direction) = 0.85-0.94 depending on instrument
Order size ~ Uniform(size_min, size_max) lots

This creates the sustained directional sweeps you see on tape when a large participant is working a position. The persistence parameter controls how "clean" or "choppy" the institutional flow appears.

Retail Noise fires at higher frequency but lower size. These agents trade in both directions semi-randomly, contributing to the noise floor around the trend. Their primary function in the model is to create realistic volume profiles and prevent the price from moving in unnaturally smooth trajectories.

Momentum Chasers look at the last 5 ticks and pile on in the direction of short-term movement. They amplify moves that are already happening, creating the acceleration you see when price breaks through a level with conviction.

Self-Exciting Order Flow (Hawkes Process)

Real trade arrivals are not uniformly distributed in time. They cluster. A burst of trades triggers more trades. This is the key insight of Hawkes process modeling in finance.

We implement this as a stochastic intensity that jumps on each event and decays exponentially between events:

lambda(t) = mu + alpha * sum(exp(-beta * (t - t_i)))

Where: - mu is the base arrival intensity (trades per second at rest) - alpha is the excitation jump (how much each trade increases the rate) - beta is the decay rate (how quickly intensity returns to baseline)

In practice: an institutional sweep triggers a cascade of momentum orders and retail reactions, producing the realistic "bursts" of activity followed by quiet periods that characterize real order flow.

Reference: Bacry, E., Mastromatteo, I., & Muzy, J.F. (2015). "Hawkes Processes in Finance." Market Microstructure and Liquidity, 1(1). arXiv:1502.04592

For a deeper treatment of Hawkes processes applied specifically to price dynamics at the microstructural level, see also:

Reference: Bacry, E. & Muzy, J.F. (2014). "Hawkes model for price and trades high-frequency dynamics." Quantitative Finance, 14(7). arXiv:1301.1135

Price Formation

Each second, the price update combines signals from all agents:

dp = target_pull + flow_impact + pool_attraction + mean_reversion + noise

Target pull (0.15 weight toward the candle's macro trajectory) ensures the tick path respects the broader session structure. Without this, the microstructure simulation would drift arbitrarily.

Flow impact is proportional to the net order imbalance from all agents. When institutional flow is heavy in one direction, price moves. When flow is balanced, price oscillates around the current level.

Pool attraction models liquidity clustering at key levels. We pre-compute 3-5 "liquidity pools" per session (analogous to support/resistance), and price is weakly attracted toward them:

pool_pull = strength * (pool_price - current_price) / (|distance| + tick_size)

This produces the observed tendency of price to "magnetize" toward certain levels before either bouncing or breaking through.

Mean reversion is a weak pull toward the session VWAP, preventing drift:

mr_pull = strength * (vwap - price)

The strength is small (0.001-0.004 depending on instrument) but prevents the simulation from generating unrealistic one-directional sessions.

Order Imbalance Decay

After each tick, the accumulated order imbalance decays:

imbalance(t+1) = imbalance(t) * 0.85

This prevents stale flow from dominating the simulation. New information (agent actions) matters more than old information. The 0.85 decay rate was calibrated against real ES tape data to match the autocorrelation structure of signed trade flow.

Instrument-Specific Calibration

Each instrument gets its own parameter set. ES (E-mini S&P) has tight spreads, moderate institutional persistence, and strong mean reversion. GME has wide spreads, low institutional persistence, heavy retail flow, and high Hawkes excitation. The parameter differences produce qualitatively different trading experiences that match what you'd see on the real tape for those instruments.

What This Gets You

The end result is tick-by-tick data where:

These aren't cosmetic features. They're properties that matter for execution practice. If you're learning to read tape, you need a tape that behaves like tape. If you're practicing limit order placement, you need a book that responds realistically to aggression. That's what this engine provides.

Further Reading

For a comprehensive treatment of multi-agent LOB simulation frameworks:

Reference: Cont, R., Stoikov, S., & Talreja, R. (2010). "A Stochastic Model for Order Book Dynamics." Operations Research, 58(3). arXiv:1005.0182

For an overview of how Hawkes processes are applied to high-frequency order flow imbalance:

Reference: Fosset, A., Bouchaud, J.P., & Benzaquen, M. (2020). "Non-parametric Estimation of Quadratic Hawkes Processes for Order Book Events." arXiv:2005.05775

← Back to Blog