lumibot icon indicating copy to clipboard operation
lumibot copied to clipboard

Fix error when filled_quantity is negative in broker.py

Open LawiK974 opened this issue 1 year ago • 1 comments

It appears that filled_quantity is not anymore positive, so the code should be updated.

This causes me a lot of errors printing in backtesting and even wrong backtest results.

This is my first PR on lumibot, please correct me if i'm wrong.

Description by Korbit AI

What change is being made?

Remove the check that raises an error when filled_quantity is negative in broker.py.

Why are these changes being made?

The previous implementation incorrectly assumed that filled_quantity must always be positive, which is not necessarily true in all trading scenarios. This change allows for more flexibility in handling trade events where filled_quantity might be negative.

LawiK974 avatar Aug 28 '24 08:08 LawiK974

You've used up your 5 PR reviews for this month under the Korbit Starter Plan. You'll get 5 more reviews on September 20th, 2024 or you can upgrade to Pro for unlimited PR reviews and enhanced features in your Korbit Console.

korbit-ai[bot] avatar Aug 28 '24 08:08 korbit-ai[bot]

@LawiK974 Why do you think that quantity should be negative? I've never seen any broker accept negative quantities

grzesir avatar Aug 28 '24 22:08 grzesir

@grzesir thank you for your response.

humm there is something wrong in the code, during my backtesting, I always get a lot of errors for negative filled_quantity.

Maybe it's either https://github.com/Lumiwealth/lumibot/blob/b3307f6d77a322e4a1e9836a34998be0ce6d13b7/lumibot/backtesting/backtesting_broker.py#L578 : where filled_quantity = order.quantity must be replace by the absolute value ?

LawiK974 avatar Aug 29 '24 06:08 LawiK974

@grzesir thank you for your response.

humm there is something wrong in the code, during my backtesting, I always get a lot of errors for negative filled_quantity.

Maybe it's either

https://github.com/Lumiwealth/lumibot/blob/b3307f6d77a322e4a1e9836a34998be0ce6d13b7/lumibot/backtesting/backtesting_broker.py#L578

: where filled_quantity = order.quantity must be replace by the absolute value ?

That sounds like a more likely cause of the error you're getting. Order quanity should never be negative. What part of the code do you mean exactly?

grzesir avatar Sep 03 '24 22:09 grzesir