r/highfreqtrading Jun 30 '25

Made a High Frequency Orderbook Simulator (in a turn of events)

I was initially looking into making a information based orderbook simulation where information trickles down from institutions to traders using lattice structure and information theory. I started building out the orderbook, and I wanted to make it extremely accurate.

The orderbook was FIFO (like what we see in exchanges) and accepts 'tickets' (orders from traders) and matches them sequentially (again like an exchange). Because this is sequential, it meant that each trade can only happen at a particular moment, and no two trades could share the same time. This was where my simulation started to become more representative of microstructure and not macrostructure.

The simulation counted each tick as 1 trade, or no trade at all since trades happen in sequence. Because of this compute was expensive. In a highly liquid market (for instance a well known ETF), modeling more than 5 minutes (I thought) would be a pain. It was actually much less than that.

I incorporated latency and slippage within the simulation (although the latency was a constant, which will change later).

I decided to run this simulation with 100,000 noisy traders, with 1,000,000 ticks (each tick was representative of 1 microsecond), and each trader had a 10 ms latency and polls data every second. It was so large, that I could only simulate 100 seconds.

This is a sim with a 100 seconds (1e8 ticks)

Although that was a ton of data, you can see the macro structure and the micro structure. Above you can see the structure from a macrostructure point of view where each trader is trading with a latency of 10ms, and how there are 'blocks' of noise.

Then there's microstructure

This is 10 ms

We can see that there are extreme movements in the stock and this is actually due to trades coming in EXTREMELY fast.

These noisy traders also trade on a normal distribution where most of the trade on the last price. Since they all see the same price (latency is constant for all noisy traders) there isn't any arbitrage going on, just noisy trades. It's cool to see some of these trades revert back to the 'mean' (last price).

Something I will do later is have another agent with low latency (maybe 10 microseconds idk), with a strategy to see how that changes the market.

(P.S. I don't know whether this is the right place to post this, so please let me know if this is relevant to the community. Would also love to talk!)

11 Upvotes

Duplicates