Limit Order Book Simulation
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
Platform Compatibility
Windows macOS LinuxCategories
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 |