Skip to content
All library documents

Limit Order Backtesting Requires Queue and Execution Simulation

Article Quant Q&A · Author: user1769197

Summary

The document explains why realistic limit order backtests require more than signal timestamps and price bars. A useful simulation needs full order book data, precise timestamps, tracking of strategy orders and their states, latency estimates, and handling for venue-specific matching rules and events. Hidden liquidity, adverse selection, auctions, and the market impact of publishing orders create further uncertainty. The response characterizes the engineering effort as substantially greater than for market order simulation.

As a rough fill estimate, it suggests maintaining a simulated order book and acknowledging a fill when subsequent trades occur behind the strategy’s order in priority. This is explicitly an imprecise estimate, not a complete venue simulator. The response recommends passive order simulation chiefly for strategies intended to provide liquidity, or for strategies already viable with market orders that use limits to reduce slippage. It also notes that position limits and pre-trade risk controls should be represented in both simulation and production.

Key ideas

  • Limit order backtests need order book data, order state tracking, and detailed timing and latency information.
  • Venue rules and events such as hidden liquidity or auctions complicate fill simulation.
  • A separate simulated book can estimate fills by tracking trades that occur behind the strategy order.
  • This queue-based fill estimate is imprecise and should not be treated as a full market simulation.
  • Position limits and pre-trade risk controls belong in both backtest and production systems.

Tags

Full text
# Backtesting with limit orders using tick data


# Backtesting with limit orders using tick data












I have full order book data and I am writing a backtest for limit orders (to launch a new position not perofit taking or stop loss). I notice that this is actually a lot more difficult to write than a backtest for market orders because the backtest needs to take into account of when the limit order got hit and it could happen after the second signal is generated and a second batch of limit orders are sent out. And what if the limit order is never hit and I would probably need to expire the order within 10 minutes in the backtest. In addition, if I set a limit to the position that i am allowed to take, this makes the backtest very difficult to write.

I would like to know if anyone has done limit orders backtesting? Any advices? Or this is actually a very bad idea ?

## Answer by databento (score 4)

https://quant.stackexchange.com/a/73900

> this is actually a lot more difficult to write than a backtest for market orders

This is to be expected. In my experience, the engineering difficulty and time goes up 1-2 orders of magnitude, because, among many things:

- On the market simulation side, you need full order book data, instead of BBO only; much more precise timestamping on your data; much more bookkeeping of strategy orders; much finer measurement of various matching engine, gateway, and client side latencies; to account for at least an order of magnitude more obscure matching scenarios and edge cases like auctions, halts, RFQs, non-pure price-time priority, implied book; to deal with unobservable behavior like adverse selection, hidden liquidity; simulate self-exciting effects that would be present in production when your orders actually get published in the feed; tooling for post-trade calibration of your simulation.

- On the client side, you now need to manage a much larger state space.

Firms that excel at simulation-based trading dedicate tens of man years to fine-tune it, and have specialists for writing simulation targeting specific venues. Even some of the top 30 market makers don't have good passive simulation.

> I would like to know if anyone has done limit orders backtesting? Any advices? Or this is actually a very bad idea ?

Also see my response here. I generally recommend against it unless the principal purpose of your strategy is to provide liquidity and tighten the spread. Otherwise the next best reason is that you're using limit orders purely to reduce slippage, but your strategy is already passable (and in production for some time) with market orders.

The worst reason to be considering it is if your strategy has still not been deployed to production and you're incorporating passive, non-marketable orders to make it pass whatever concrete or subjective threshold you have for deploying the strategy.

> because the backtest needs to take into account of when the limit order got hit

> In addition, if I set a limit to the position that i am allowed to take, this makes the backtest very difficult to write.

You're not wrong regarding both statements here. It's entirely a matter of implementation difficulty. That said, both of these are among the easier problems with passive simulation actually:

- You can make a first order estimate (this will be imprecise) when the "limit order got hit" by maintaining a separate order book structure on the simulator side, and ack'ing a fill to the strategy when a trade takes place on your stored book data with lesser priority than your order.

- Most strategies should have position limits, even liquidity-taking strategies. Even if not for model or risk management purposes, you'd still need a position limit due to margin requirements. If your platform is well-designed, the same pre-trade risk layer will handle both simulation and production, and part of this - the strategy still needs a position exceeded failure state - will be modularized away from your strategy logic.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

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