Building an Order Book Backtest with HftBacktest
Summary
This tutorial introduces a workflow for inspecting market data and orders in HftBacktest. It shows how to configure an asset with historical tick data, an optional starting snapshot, contract and tick sizes, latency, queue position, exchange fill behavior, and fees. Examples then retrieve best bid and ask prices, inspect several levels of depth, submit and cancel limit orders, track order states, and clear inactive orders. The tutorial also explains that prices use floating point values, recommends rounding for display, and notes that backtest instances should be closed after use.
The later sections demonstrate recording simulated account states, exporting records, and producing performance summaries and plots. Data can be loaded lazily to manage memory or preloaded for repeated runs when memory permits. These are infrastructure examples rather than a trading strategy or performance study. Results depend on the historical feed and modeling choices, including latency, queue assumptions, fill rules, and fees; the tutorial gives no evidence that any particular configuration reproduces live execution accurately.
Key ideas
- An asset configuration specifies data, contract details, latency, queue modeling, fill behavior, and fees.
- The backtest interface exposes best quotes, market depth, orders, and order status updates.
- Limit orders can be submitted, canceled, and removed from the record after becoming inactive.
- Lazy loading can reduce memory pressure, while preloading can help when rerunning tests.
- Recorded states support performance summaries and visualizations, but accuracy depends on model assumptions.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.