Limit Order Book Simulation

A modified version of Limit Order Book Simulation written by Dimitri Shvorob.
1.4K Downloads
Updated 8 Jul 2010

View License

This difference here is this is pure limit order driven, i.e. 'Market Order' is considered as limit order with limit price higher or lower than current market price, in fact you can consider 'Market Order' as limit order with 'inf' limit price, and the priority of all market order is automatically maintained in heaps because of the way Order book read from OrderQueue and put into PriorityQueue.
The four heaps structure is simplified into two heaps structure, one for 'BUY' and one for 'SELL'.
The PriorityQueue is rewritten to make it Log(N) instead of N, but this makes trivial difference in this context since Heaps normally has <1000 orders.

In fact using Matlab timer function and attach one to each agent is not the ideal structure to simulate the real market, which allows 1) both time driven and event driven processing & 2) parallel processing for traders and exchange. I have tried to do multi-threading in Matlab, but apparently it is not supported.

We are currently writing a multi-threading version in java. I also wrote a more flexible simulation framework using Swarm(a multi-agent simulation library) dynamic scheduling engine in JAVA. The ultimate goal is to achieve arbitrarily realistic market simulation, allowing multiple exchange routing, multiple order books, FIX protocol, simulation of latency impact etc.

Cite As

Yuanhang Wang (2026). Limit Order Book Simulation (https://www.mathworks.com/matlabcentral/fileexchange/28156-limit-order-book-simulation), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Financial Toolbox in Help Center and MATLAB Answers
Version Published Release Notes
1.0.0.0