Overview
Queue position models estimate where your order sits in the order book queue at a given price level. This is crucial for accurate fill simulation because:- You only get filled when orders ahead of you are filled first
- Orders can be canceled, improving your position
- Your position determines when you’re at the “front” and eligible for fills
With Level-3 (Market-By-Order) data, queue position is tracked exactly using FIFO rules, making queue models unnecessary. See Level-3 Backtesting for details.
Why Queue Position Matters
Consider this scenario:- Overestimating fills: Assuming you’re always at the front
- Incorrect alpha: Strategy appears more profitable than reality
- Failed live trading: Backtest diverges from live results
Available Queue Models
HftBacktest provides several queue models with different accuracy/performance tradeoffs.1. Risk-Averse Queue Model
The most conservative model - assumes you’re always at the back of the queue:- When you submit an order, your queue position = total quantity at that price
- Your position only improves when trades occur at your price
- Quantity increases don’t affect your position
- Quantity decreases don’t affect your position (conservative assumption)
2. Probability-Based Queue Model
A more realistic model using probabilistic estimates:- Initial Position: When you join, position = current quantity at price level
-
Trade Occurs: Your position moves forward by the trade quantity
-
Quantity Decreases: Cancellations improve your position based on probability
3. Power Probability Queue Model
Uses a power function to adjust the probability:- n = 1 (Linear)
- n = 3 (Cubic)
- n = 5 (Higher Power)
Choosing the power parameter:
- n = 1-2: Conservative, similar to risk-averse
- n = 3-4: Balanced, works well for most markets
- n = 5+: Optimistic, use when you know cancels are mostly behind you
- Calibrate by comparing backtest to live trading results
4. Logarithmic Probability Queue Model
Uses logarithmic probability function:Calibrating Queue Models
The best way to calibrate is by comparing backtest results with live trading:Step 1: Run Live Trading
Run your strategy live for a period and record:- All orders submitted
- Fill rates at each price level
- Time to fill
- Partial vs full fills
Step 2: Backtest Same Period
Backtest over the exact same time period with different queue models:Step 3: Compare Metrics
Compare key metrics between backtest and live:| Metric | Live Trading | Backtest (n=3) | Backtest (n=5) |
|---|---|---|---|
| Fill Rate | 65% | 63% | 78% |
| Avg Time to Fill | 2.3s | 2.5s | 1.8s |
| Total Trades | 1,234 | 1,189 | 1,456 |
| Sharpe Ratio | 2.1 | 2.0 | 2.4 |
Good Calibration Indicators:
- Fill rate within 5-10% of live
- Trade count within 10% of live
- Similar time-to-fill distributions
- PnL correlation > 0.9 between backtest and live
Market-Specific Considerations
Large Tick Size Markets
Markets with large tick sizes (CME, some crypto pairs) make queue position critical:Small Tick Size Markets
Markets with tiny tick sizes (most crypto) are more forgiving:Custom Queue Models
Implement your own queue model by subclassingQueueModel:
Debugging Queue Position
Track queue position throughout the backtest:Best Practices
Start Conservative
Start Conservative
Begin with risk-averse or low-power models (n=1-2). Gradually increase optimism only after validating with live trading.
Validate with Live Data
Validate with Live Data
The only way to know if your queue model is accurate is to compare backtest results with actual live trading over the same period.
Consider Market Microstructure
Consider Market Microstructure
Different markets have different cancellation patterns:
- HFT-heavy markets: More cancellations, often behind you
- Retail markets: Fewer cancellations, more random
- Large tick markets: Queue position critical
- Small tick markets: Less sensitive to queue model
Monitor Over Time
Monitor Over Time
Market microstructure changes. Recalibrate your queue model periodically by comparing recent backtests with live results.
Next Steps
Level-3 Backtesting
Perfect queue tracking with Market-By-Order data
Latency Modeling
Model realistic order latencies