refactor: limit pre-window balance aggregation to equity mode

This commit is contained in:
ABS
2026-02-19 04:14:41 +08:00
parent 780858f538
commit 0672d8f094

View File

@@ -54,17 +54,17 @@ class MaxDrawdown(IProtection):
if len(trades_in_window) < self._trade_limit:
return None
# Get all trades to calculate cumulative profit before the window
all_closed_trades = Trade.get_trades_proxy(is_open=False)
profit_before_window = sum(
trade.close_profit_abs or 0.0
for trade in all_closed_trades
if trade.close_date_utc <= look_back_until
)
try:
if self._calculation_mode == "equity":
# Standard equity-based drawdown
# Get all trades to calculate cumulative profit before the window
all_closed_trades = Trade.get_trades_proxy(is_open=False)
profit_before_window = sum(
trade.close_profit_abs or 0.0
for trade in all_closed_trades
if trade.close_date_utc <= look_back_until
)
trades_df = pd.DataFrame(
[
{"close_date": t.close_date_utc, "profit_abs": t.close_profit_abs}