fix: handle floating point precision in take_profit check and final_balance calculation
Two bugs fixed: 1. final_balance was incorrectly calculated as balance + balance when position=0 due to expression structure 2. take_profit check needed epsilon for floating point precision (95 * 1.10 = 104.50000000000001 instead of 104.5)
This commit is contained in:
@@ -176,7 +176,8 @@ class BacktestEngine:
|
||||
|
||||
if self.take_profit_percent is not None:
|
||||
take_profit_price = self.entry_price * (1 + self.take_profit_percent / 100)
|
||||
if current_price >= take_profit_price:
|
||||
# Use small epsilon to handle floating point precision
|
||||
if current_price >= take_profit_price - 0.001:
|
||||
return {"reason": "take_profit", "price": take_profit_price}
|
||||
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user