Fix error when filled_quantity is negative in broker.py
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.
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.
@LawiK974 Why do you think that quantity should be negative? I've never seen any broker accept negative quantities
@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 ?
@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.quantitymust 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?