backtesting.py icon indicating copy to clipboard operation
backtesting.py copied to clipboard

Didn't get forced liquidation when the "Low Price" is very low.

Open peilinnnnnn opened this issue 2 years ago • 1 comments

image

As depicted in the picture, the first trade generated a profit, but during the trade, a bar had a significantly low "Low Price", indicating that in reality, the first trade would have been subject to forced liquidation due to my margin setting of 0.01. Is there a way to fix this issue now?

peilinnnnnn avatar Mar 16 '23 18:03 peilinnnnnn

Indeed, equity is computed only once per bar, taking into account only the last_price (i.e. close) for trade P/L computation. Nice catch!

https://github.com/kernc/backtesting.py/blob/0ce24d80b1bcb8120d95d31dc3bb351b1052a27d/backtesting/backtesting.py#L802-L813 https://github.com/kernc/backtesting.py/blob/0ce24d80b1bcb8120d95d31dc3bb351b1052a27d/backtesting/backtesting.py#L788-L790

kernc avatar Apr 01 '23 00:04 kernc