Fill Models, Partial Fills and Order Queues
A fill model decides when and at what price backtest orders execute. Learn market, limit and stop fill assumptions, queue position and adverse selection.
A backtest must decide what happens when the strategy sends an order: does it fill, at what price and how much? These rules make up the fill model. Optimistic fill models are a hidden source of fake profits, especially for strategies that use limit orders, trade small moves or depend on precise entries. Realistic fill modelling matters most for short term strategies, where a tick or two per trade can be the entire edge.
Fill assumptions by order type#
| Order | Simple assumption | More realistic assumption |
|---|---|---|
| Market order | Fill at the next bar's open or last price | Fill at the ask (buy) or bid (sell), plus slippage scaled to size and volatility. See Market Orders |
| Limit order | Fill if price touches the limit | Fill only if price trades through the limit, or after your queue position is reached. See Limit Orders |
| Stop order | Fill at the stop price | Fill at the next available price after the stop triggers, often worse in gaps. See Stop Orders |
| Stop limit | Fill at the limit | May not fill at all if price gaps past the limit. See Stop-Limit Orders |
The limit order problem#
Limit orders look great in naive backtests: you buy at your price whenever it is touched. In reality:
- Queue position: other orders at the same price fill first. Price may touch your level without reaching your order. See Fill Probability and Queue Position.
- Adverse selection: your limit buys tend to fill when the price keeps falling, and miss when it bounces immediately. Filled orders are disproportionately the bad ones.
Partial fills and size#
Large orders relative to available liquidity may fill only partly or move the price. A fill model can cap fills at a share of the volume traded in each bar, such as 5% to 10%, and apply market impact to larger orders. See Market Impact.
Gaps and stops#
Stops do not protect against gaps. If a stock closes at $50 and opens at $44 after bad news, a stop at $48 fills near $44. Backtests should fill stops at the first available price after the trigger, including gaps. See Price Gaps and How to Trade Them.
Data resolution matters#
| Data | Fill modelling quality |
|---|---|
| Daily bars | Only rough; intraday order of highs and lows unknown |
| Minute bars | Better; still ambiguous within each bar |
| Tick or trade data | Good for trade through tests |
| Order book data (Level 2 or 3) | Allows queue position modelling. See Order Book Feeds: Snapshots and Incremental Updates |
Ambiguous bars should be resolved conservatively, such as assuming the stop was hit before the target.
A conservative default fill model#
- Market orders: fill at the next available price, crossing the spread, plus slippage.
- Limit orders: fill only when price trades through by at least one tick, and cap size by volume.
- Stops: fill at the next price after triggering, including gaps.
- Ambiguous bars: assume the worse outcome.
- Compare with live fills once trading and adjust. See Slippage Analysis.
Simulating with market replay#
For high frequency strategies, firms replay historical order book data through a simulated exchange matching engine, modelling queue position and latency. This is the most realistic approach but requires detailed data and engineering. See Market Data Replay and Matching Engines.
Frequently asked questions#
What is a fill model in backtesting?#
The set of rules a backtest uses to decide whether orders execute, at what price and in what quantity.
Why do limit orders look too good in backtests?#
Because naive models fill them whenever price touches the limit, ignoring queue position and the tendency for limit orders to fill mainly before adverse moves.
How should stop orders be filled in a backtest?#
At the first available price after the stop is triggered, which can be much worse than the stop price when markets gap.
Next, learn to test many positions together in Portfolio and Multi-Asset Backtesting.
3 quick questions on this lesson. Get them all right to finish it.
Turn on JavaScript to take the quiz.
Mentioned in
- The Trading Research ProcessResearch and Backtesting
- Why Strategies FailResearch and Backtesting
- Backtesting MethodologyResearch and Backtesting
- Look-Ahead BiasResearch and Backtesting
- Event-Driven vs Vectorized BacktestingResearch and Backtesting
- From Backtest to Live: Paper, Shadow and CanaryAlgorithmic Trading