diff --git a/deploy/profile-scripts/hk_backtest.py b/deploy/profile-scripts/hk_backtest.py index 40a28f53..c874ae07 100644 --- a/deploy/profile-scripts/hk_backtest.py +++ b/deploy/profile-scripts/hk_backtest.py @@ -224,29 +224,42 @@ def main(): ap = argparse.ArgumentParser() ap.add_argument("--version", default=None) ap.add_argument("--slots", type=int, default=8) + ap.add_argument("--strike", type=int, default=2) + ap.add_argument("--cooldown", type=int, default=40) + ap.add_argument("--td-guard", type=int, default=5, help="trend_down连续超过N天暂停超卖策略(防守)") args = ap.parse_args() panel = load_panel() print(f"港股面板: {len(panel)} 行\n", flush=True) + # trend_down 连续天数(组合级防守) + rm = load_regime_map() + dates = sorted(rm.keys()) + td_run = {} + run = 0 + for d in dates: + run = run + 1 if rm[d] == "trend_down" else 0 + td_run[d] = run + versions = [args.version] if args.version else list(HK_STRATEGIES.keys()) all_trades = [] - rm = load_regime_map() # 港股温区映射(组合温区调度) for v in versions: strat = get_hk_strategy(v) if not strat: print(f"未知策略: {v}") continue print(f"=== {v} ({strat['name']}) ===", flush=True) - trades = gen_trades_defensive(panel, strat, strike=3, cooldown_days=15) + trades = gen_trades_defensive(panel, strat, strike=args.strike, cooldown_days=args.cooldown) if not trades: print(" 无交易\n", flush=True) continue - # 温区调度:只保留策略适用温区的交易(组合正确性关键) + # 温区调度 + 组合级防守(trend_down 连续>N天暂停超卖,避免持续下跌被埋) reg = strat.get("regime", "all") if reg != "all" and args.version is None: trades = [t for t in trades if rm.get(t["entry_date"]) == reg] - print(f" 温区调度({reg}): 保留 {len(trades)} 笔", flush=True) + if reg == "trend_down" and args.td_guard > 0: + trades = [t for t in trades if td_run.get(t["entry_date"], 0) <= args.td_guard] + print(f" 温区调度({reg})+防守: 保留 {len(trades)} 笔", flush=True) m = portfolio_metrics(trades, slots=args.slots) print(f" 交易{m['trades']} 胜率{m['win_rate']:.0f}% 组合年化{m['cagr']}% " f"近1年{m['year1']:+.1f}% 近6月{m['month6']:+.1f}% 近3月{m['month3']:+.1f}%\n", flush=True) diff --git a/deploy/profile-scripts/hk_strategies.py b/deploy/profile-scripts/hk_strategies.py index 8c119f18..5cee5ef3 100644 --- a/deploy/profile-scripts/hk_strategies.py +++ b/deploy/profile-scripts/hk_strategies.py @@ -25,9 +25,9 @@ HK_STRATEGIES = { "mcap_q_max": 0.2, # 市值分位<0.2(小市值,+2.84pp) "sec_ret20_min": 10, # 行业20日动量>10%(+1.47pp) }, - "exit": {"tp_pct": 0.30, "sl_pct": 0.12, "max_hold_days": 40}, + "exit": {"tp_pct": 0.40, "sl_pct": 0.12, "max_hold_days": 40}, }, - # trend_down:深度超卖反弹(由果及因:RSI<20/bias60<-20,持续下跌市避被埋,胜率72%) + # trend_down:深度超卖反弹(持续下跌市靠组合级防守避免被埋) "hk_mr1": { "version": "hk_mr1", "name": "港股深度超卖反弹(trend_down主战场)",