diff --git a/strategy_lab.py b/strategy_lab.py index e7c4f12c..4b16cc61 100644 --- a/strategy_lab.py +++ b/strategy_lab.py @@ -271,6 +271,24 @@ STRATEGIES.update({ entry_overrides={"vol_ratio_min": 0.9, "vol_ratio_max": 2.0, "sector_slope_max": 1.0, "hl_only": True, "rsi_delta_min": 6}, exit_overrides={"tp_pct": None, "use_pivot_sr": True, "max_hold_days": 20}), + "v11.2": _v40_branch("v11.2", "真波段+枢轴减半", + "v8.1真波段(MA10先出再进) + 弱支撑止损 + 强压减半仓——取MA10贴身波段与枢轴风控两者之长", + "v11.0的'枢轴波段'实为纯硬扛(弱撑从不触发),v8.1才是真波段(44次先出10次再进);用枢轴弱撑做初始止损、强压减半落袋改善风险结构", + entry_overrides={"vol_ratio_min": 0.9, "vol_ratio_max": 2.0, "sector_slope_max": 1.0, + "hl_only": True, "rsi_delta_min": 6}, + exit_overrides={"tp_pct": None, "exit_mode": "swing_ptp", "sl_atr": 1.5, "max_hold_days": 60, "reentry_days": 10, "stop_mode": "pivot_ws"}), + "v11.3": _v40_branch("v11.3", "真波段+强撑止损+减半", + "v11.2的弱支撑止损太紧(77%被洗)——改强支撑止损+强压减半", + "v11.2实证:弱支撑是日内贴身位,当止损77%出场率无法接受;改用更宽的强支撑", + entry_overrides={"vol_ratio_min": 0.9, "vol_ratio_max": 2.0, "sector_slope_max": 1.0, + "hl_only": True, "rsi_delta_min": 6}, + exit_overrides={"tp_pct": None, "exit_mode": "swing_ptp", "sl_atr": 1.5, "max_hold_days": 60, "reentry_days": 10, "stop_mode": "pivot_ss"}), + "v11.4": _v40_branch("v11.4", "v8.1+强压减半", + "v8.1原样(ATR止损+MA10波段) + 仅加强压减半落袋——隔离减半特征", + "v11.2证明弱撑止损有毒,v11.3测强撑,v11.4回到v8.1的ATR止损只保留强压减半这一个枢轴特征", + entry_overrides={"vol_ratio_min": 0.9, "vol_ratio_max": 2.0, "sector_slope_max": 1.0, + "hl_only": True, "rsi_delta_min": 6}, + exit_overrides={"tp_pct": None, "exit_mode": "swing_ptp", "sl_atr": 1.5, "max_hold_days": 60, "reentry_days": 10, "stop_mode": "atr"}), # ── 港股专用版本(港股通宇宙归因推导,2026-07-29)── "h1.0": { "version": "h1.0", @@ -913,6 +931,63 @@ def run_backtest(strategy_version, start_date, end_date, capital=1000000, save=T pnl = (total_ret - 1) * 100 exit_price = ep * total_ret hold_days = len(future) if future else 0 + elif exit_cfg.get('exit_mode') == 'swing_ptp': + # ── v11.2: MA10真波段 + 弱支撑止损 + 强压减半仓 ── + reentry_window = exit_cfg.get('reentry_days', 10) + _stop_mode = exit_cfg.get('stop_mode', 'atr') + ws0 = last.get('weak_support') or 0 + ss0 = last.get('strong_support') or 0 + r2_0 = last.get('strong_resist') or 0 + if _stop_mode == 'pivot_ws' and 0 < ws0 < ep: + stop_cur = ws0 + elif _stop_mode == 'pivot_ss' and 0 < ss0 < ep: + stop_cur = ss0 + else: + stop_cur = stop + remaining = 1.0 + realized_pnl = 0.0 + in_pos = True + entry_p = ep + wait = 0 + exit_reason = 'keep' + half_done = False + for k, fb in enumerate(future): + fh, fl, fc = fb.get('high') or 0, fb.get('low') or 0, fb.get('close') or 0 + fma10 = fb.get('ma10') or 0 + if in_pos: + # 强压减半落袋 + if r2_0 > 0 and not half_done and fh >= r2_0: + realized_pnl += remaining * 0.5 * (r2_0 / entry_p - 1) + remaining *= 0.5 + half_done = True + if fl <= stop_cur: + realized_pnl += remaining * (fc / entry_p - 1) + remaining = 0 + exit_reason = 'stop' + in_pos = False + break + if fma10 > 0 and fc < fma10: + realized_pnl += remaining * (fc / entry_p - 1) + in_pos = False + wait = reentry_window + exit_reason = 'swing_out' + else: + wait -= 1 + if wait < 0: + break + prev_high = future[k-1].get('high') or 0 if k > 0 else 0 + if fma10 > 0 and fc > fma10 and fh > prev_high: + in_pos = True + entry_p = fc + stop_cur = fb.get('weak_support') or stop_cur + r2_0 = fb.get('strong_resist') or r2_0 + half_done = False + exit_reason = 'swing_re' + if in_pos: + realized_pnl += remaining * ((future[-1].get('close') if future else entry_p) / entry_p - 1) + pnl = realized_pnl * 100 + exit_price = ep * (1 + realized_pnl) + hold_days = len(future) if future else 0 else: exit_price = exit_reason = None hold_days = 0