Skip to content
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

Fill Prices in BackTest: Candle Open vs Close #278

Closed
davidlatte opened this issue Aug 30, 2023 · 0 comments · Fixed by #279
Closed

Fill Prices in BackTest: Candle Open vs Close #278

davidlatte opened this issue Aug 30, 2023 · 0 comments · Fixed by #279
Assignees

Comments

@davidlatte
Copy link
Collaborator

davidlatte commented Aug 30, 2023

Currently, when running a strategy in backtest, the "get_last_price()" method returns the candle-open price (this is good!). However, when submitting a market order, the fill price is being set to the candle-close price, which could be far away in time/price depending on the data and settings used. This is causing BackTest Profit and Loss calculations and other metrics to be very different from actual live paper trading results on occasions where orders are placed on large candles.

In some simple paper trading cases I've run, the market orders are usually filled very close to the "get_last_price()" value and I think that Lumibit Backtest should be updated to match this behavior. Additionally, this same delay seems to occur in "some" limit and stoploss orders depending on whether the trigger price occurs with in the body of the candle vs the wick of the candle.

  • When triggered in the body region, fill price is waiting for the close price to execute.
  • When triggered in the wick region, fill price is set immediately to the trigger price

Limit Order Use Case 1:

AAPL stock
Open: $100
Close: $110
High: $115
Low: $95

Limit: $90 for a sell
Meaning “I want to sell aapl, but I want at least $90”

Backtest Fill Price = $110
Ideal Fill Price = $100

Limit Order Use Case 2:

AAPL stock
Open: $100
Close: $110
High: $115
Low: $95

Limit: $112 for a sell

Backtest Fill Price = $112
Ideal Fill Price = $112

In short, why would Lumibot trigger "instantly" when filling in a wick but "wait until the close" to fill in the body?

Things to fix:

  • Market order should fill at/near "get_last_price()" (aka candle open)
  • Limit/Stop orders should fill at the trigger price in both body and wick candle regions
@davidlatte davidlatte self-assigned this Aug 30, 2023
@davidlatte davidlatte linked a pull request Aug 30, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant