Skip to content
All library documents

Partial-Fill Exchange Modeling for Order-Book Backtests

Code Stratmill research code

Summary

This exchange model describes how a backtest can simulate partially filled limit orders. It supports limit orders with several time-in-force rules and uses a queue model to track an order’s position at its price level. When trades occur at that price, the model updates the queue and fills the order only when the estimated quantity ahead has been consumed. Price movement through an order can trigger a full fill, while liquidity-taking orders are executed against available book quantity.

The implementation also accounts for order latency, acknowledgments, cancellations, modifications, fees, and fill responses. Its documentation cautions that taking liquidity without changing displayed depth can produce unrealistic results for large orders. Queue position and partial fills are difficult to model accurately, and the suggested practical check is to compare simulated fills with live trading. The code explains mechanics rather than presenting validation results, so realism depends on the chosen queue, latency, fee, and depth models.

Key ideas

  • The model supports limit orders and GTC, FOK, IOC, and GTX time-in-force instructions.
  • A queue model estimates whether trades at an order’s price consume enough quantity ahead to produce a partial fill.
  • Orders crossed by price movement can receive full fills, while liquidity-taking fills use displayed book quantity.
  • Order latency and fee models contribute to the simulated execution process.
  • Large liquidity-taking orders may be simulated unrealistically if execution does not alter the displayed book.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.