Skip to content

Enhance backtest execution model with state-aware fills #2564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stastnypremysl opened this issue Apr 27, 2025 · 3 comments
Open

Enhance backtest execution model with state-aware fills #2564

stastnypremysl opened this issue Apr 27, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@stastnypremysl
Copy link
Collaborator

stastnypremysl commented Apr 27, 2025

Bug Report

In the given folder, there is a strategy, its output and data to run on.

It opens two limit orders with the same price.

Expected Behavior

Only the first limit order sent is being filled.

Actual Behavior

Both limit orders are being filled at once from the same liquidity.

Steps to Reproduce the Problem

  1. Download the data
  2. Extract the zip file and change extracted catalog path in strategy.py to the catalog
  3. ./strategy.py >strategy.out 2>&1
  4. less strategy.out
  5. Find the following lines in the beginning

Image

Specifications

  • OS platform: Gentoo Linux (native build, amd64)
  • Python version: Python 3.12.9 (native build)
  • nautilus_trader version: 1.217.0 (revision 95a671e; make build-wheel)

Additional notes

  • The simulation is running on aggregated trade ticks from Binance data collection
  • The instrument information was downloaded using the NT Binance client
  • Ignore the 1.217.6 version in the log - no changes in the source codes was made other then change of version
@stastnypremysl stastnypremysl added the bug Something isn't working label Apr 27, 2025
@cjdsellers
Copy link
Member

Hi @stastnypremysl

Thanks for the report.

The current execution simulation for backtesting is stateless - only considering the book at each time point based on historical data, and does not change the book state based on user orders, or persist any memory of previous fills. The core fill simulation function is here (and so the system is operating to spec).

This is also described here in the backtesting docs, and mentioned on the ROADMAP - additional enhancements, so improving this would have a higher priority than many other categories of feature requests (when bandwidth can be allocated).

It's also worth considering that running backtests based on trades with no further pre-processing will be unrealistic, because there would most likely be more size available at the top of the book than the size of an individual trade.

@cjdsellers cjdsellers added enhancement New feature or request and removed bug Something isn't working labels Apr 27, 2025
@cjdsellers cjdsellers changed the title Two limit orders with the same price double take the same order Enhance backtest execution model with state-aware fills Apr 27, 2025
@stastnypremysl
Copy link
Collaborator Author

Hi @cjdsellers.

I must have missed that.

Thank you for the advise. I want to use trade ticks + (possibly L2/L3 quote ticks, when slow backtest doesn't matter), or trade based bars (when performance for ML is needed) as on non-liquid pairs I want to act mainly as maker and top of the head liquidity is really low.

@stastnypremysl
Copy link
Collaborator Author

Hi, @cjdsellers.

I am reading the documentation in https://nautilustrader.io/docs/latest/concepts/backtesting and I am not sure, whether FillModel shouldn't do what I need. (e.g. Queue Position for Limit Orders implies, it should be state aware, if I understand right)

Will it start working if it is enabled?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants