|
48 | 48 | compute_max_drawdown, |
49 | 49 | compute_sharpe_ratio, |
50 | 50 | ) |
51 | | -from strategies.constants import DEFAULT_TAKE_PROFIT_PCT, DEFAULT_TRAILING_STOP_PCT |
| 51 | +from strategies.constants import ( |
| 52 | + DEFAULT_TAKE_PROFIT_PCT, |
| 53 | + DEFAULT_TRAILING_STOP_PCT, |
| 54 | + TRAILING_STOP_TIERS, |
| 55 | + TRAILING_STOP_UNDERWATER_MULTIPLIER, |
| 56 | +) |
52 | 57 | from strategies.enums import Action |
53 | 58 | from strategies.log import get_logger |
54 | 59 | from strategies.signal_scorer import ( |
@@ -214,23 +219,19 @@ def is_on_cooldown(self, symbol: str, date: datetime) -> bool: |
214 | 219 | def _dynamic_trailing_stop_pct(self, pnl_pct: float) -> float: |
215 | 220 | """Return effective trailing stop % based on unrealized P&L. |
216 | 221 |
|
217 | | - Mirrors position_manager.dynamic_trailing_stop_pct: |
218 | | - P&L < 0%: 100% of base (full room) |
219 | | - P&L 0-3%: 75% of base |
220 | | - P&L 3-5%: 50% of base |
221 | | - P&L >= 5%: 37.5% of base |
| 222 | + Mirrors position_manager.dynamic_trailing_stop_pct — both read the |
| 223 | + same tiers from strategies.constants so the backtest's behavior |
| 224 | + cannot drift from the live exit manager (a previous bug had |
| 225 | + hard-coded 100/75/50/37.5 multipliers here that silently fell out |
| 226 | + of sync when constants changed). |
222 | 227 | """ |
223 | 228 | if not self.use_dynamic_stop: |
224 | 229 | return self.trailing_stop_pct |
225 | 230 |
|
226 | | - if pnl_pct < 0: |
227 | | - return self.trailing_stop_pct |
228 | | - elif pnl_pct < 3: |
229 | | - return self.trailing_stop_pct * 0.75 |
230 | | - elif pnl_pct < 5: |
231 | | - return self.trailing_stop_pct * 0.50 |
232 | | - else: |
233 | | - return self.trailing_stop_pct * 0.375 |
| 231 | + for threshold, multiplier in TRAILING_STOP_TIERS: |
| 232 | + if pnl_pct >= threshold: |
| 233 | + return self.trailing_stop_pct * multiplier |
| 234 | + return self.trailing_stop_pct * TRAILING_STOP_UNDERWATER_MULTIPLIER |
234 | 235 |
|
235 | 236 | # --- Entry --- |
236 | 237 |
|
|
0 commit comments