An algorithmic trading simulation

The purpose of this simulation is to buy one million shares using an algorithm working on a limit order book. The simulation is based on a statistical model of limit order and market order arrival: there is no inherent direction to price movements - this is truly a random walk - but the statistical order flow will adjust to reflect the balance of orders on the book.

The diagram opposite is updated as limit orders and market orders arrive. On the far left is the Open-High-Low-Close chart for the limit order book. The market VWAP is shown on the line joining the market metrics to those of the order being worked.

To the right in blue are the limit price for the order and the average execution price achieved by the algorithm. The figure in grey is the average execution price of another 'shadow' algorithm working an equivalent order.

The simulation runs one step at a time, during which limit and market orders arrive and the algorithms can also place their orders.

#quantitypricepricequantity#
561.5
561.25
561
560
559.75
559.5

The algorithm

The default trading algorithm is a simple implementation of a single synthetic iceberg order pegged to the bid. The iceberg quantity is calculated in relation to recent market volume, the order open quantity and a standard tranche size. When the order book is heavier on the bid, the algorithm will use a market order. To make it easy to understand, the algorithm omits complexities such as selling as well as buying.

The script is written in JavaScript based on a number of predefined objects. You can edit this script and replace the default by using the link below.

Use this script

The shadow algorithm

The shadow trading algorithm is a pure synthetic iceberg order pegged to the bid, with no aggression.