From 02c4c86b06b37b3913d8111545ed68ae78c88e80 Mon Sep 17 00:00:00 2001 From: hmo Date: Fri, 14 Aug 2026 22:47:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20strategy=5Frouter=E5=8F=8C=E5=B8=82?= =?UTF-8?q?=E5=9C=BA=E8=B7=AF=E7=94=B1=E2=80=94=E2=80=94A=E8=82=A1?= =?UTF-8?q?=E6=8C=89A=E8=82=A1=E6=B8=A9=E5=8C=BA=E6=BF=80=E6=B4=BB(?= =?UTF-8?q?=E4=B8=8D=E5=8F=98),=E6=B8=AF=E8=82=A1=E7=AD=96=E7=95=A5(hk=5Fm?= =?UTF-8?q?r1)=E6=8C=89=E6=B8=AF=E8=82=A1=E6=B8=A9=E5=8C=BA=E6=BF=80?= =?UTF-8?q?=E6=B4=BB(=E8=AF=BBmarkets.hk=E6=B8=A9=E5=8C=BA+strategy=5Fregi?= =?UTF-8?q?me=5Fperf=20market=3Dhk),=E8=BE=93=E5=87=BAstrategy=5Fweights.j?= =?UTF-8?q?son=E5=8A=A0markets.hk=E7=BB=B4=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/strategy_router.py | 58 +++++++++++++++++++---- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/deploy/profile-scripts/strategy_router.py b/deploy/profile-scripts/strategy_router.py index fabdb2ad..753565d5 100644 --- a/deploy/profile-scripts/strategy_router.py +++ b/deploy/profile-scripts/strategy_router.py @@ -40,10 +40,27 @@ FAMILY_MAP = { "v4.0d": "trend", "v4.0e": "trend", "v4.0f": "trend", "v4.0g": "trend", "v4.0h": "trend", "v4.1": "trend", "v5.0": "trend", "v11.0": "trend", "v11.1": "trend", + "hk_mr1": "mr", # 港股深度超卖反弹(2026-08-14 港股归因研发,trend_down 主战场) } -def load_regime(): +def load_regime(market='a'): + """读取当前温区。market='a'(默认,A股 smoothed 顶层,行为不变) / 'hk'(港股 markets.hk)""" + if market == 'hk': + try: + p = Path("/home/hmo/MoFin/data/market_regime_smoothed.json") + if p.exists(): + d = json.loads(p.read_text(encoding="utf-8")) + mk = (d.get("markets") or {}).get("hk") or {} + if mk.get("current_regime"): + return {"regime": mk["current_regime"], "date": mk.get("current_date", "")} + except Exception: + pass + try: + from market_regime import load_market_regime + return load_market_regime(market='hk') + except Exception: + return {"regime": "unknown"} try: p = Path("/home/hmo/MoFin/data/market_regime_smoothed.json") if p.exists(): @@ -59,22 +76,25 @@ def load_regime(): return {"regime": "unknown"} -def load_temp(): +def load_temp(market='a'): + """读取当前温度。market='a'(默认,A股) / 'hk'(港股)""" try: from temp_band import get_market_temp - return get_market_temp() + return get_market_temp(market=market) except Exception: return {"band": "unknown", "rsi": None} -def load_regime_perf(): +def load_regime_perf(market='a'): + """读取策略-温区表现。market='a'(默认,A股,行为不变) / 'hk'(港股策略)""" conn = None try: import sqlite3 conn = sqlite3.connect("/home/hmo/MoFin/data/mofin.db", timeout=30) conn.execute("PRAGMA busy_timeout=30000") rows = conn.execute( - "SELECT strategy, regime, trades, win_rate, avg_pnl FROM strategy_regime_perf" + "SELECT strategy, regime, trades, win_rate, avg_pnl FROM strategy_regime_perf " + "WHERE COALESCE(market,'a')=?", (market,) ).fetchall() result = {} for strat, reg, n, wr, pnl in rows: @@ -122,9 +142,10 @@ def route(regime, temp, perf): def main(): - regime = load_regime() - temp = load_temp() - perf = load_regime_perf() + # A股路由(完全不变) + regime = load_regime() # A股温区 + temp = load_temp() # A股温度 + perf = load_regime_perf('a') # A股策略表现 weights = route(regime, temp, perf) out = { "state": regime.get("regime", "unknown"), @@ -136,9 +157,28 @@ def main(): "updated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "note": "温区(平滑K=5)选策略类型 + 温度(rsi)乘数;策略全温区发信号,适用温区由实测动态决定", } + # 港股路由(2026-08-14 新增,不影响A股)——港股策略按港股温区激活 + try: + hk_regime = load_regime('hk') + hk_temp = load_temp('hk') + hk_perf = load_regime_perf('hk') + if hk_perf: + hk_weights = route(hk_regime, hk_temp, hk_perf) + out["markets"] = {"hk": { + "state": hk_regime.get("regime", "unknown"), + "state_date": hk_regime.get("date", ""), + "temp_band": hk_temp.get("band", "unknown"), + "weights": hk_weights, + "active": [k for k, v in hk_weights.items() if v["matched"]], + }} + except Exception as e: + print(f"港股路由失败(不影响A股): {e}", flush=True) OUT.write_text(json.dumps(out, ensure_ascii=False, indent=1), encoding="utf-8") print(f"strategy_weights.json: 状态={out['state']} 温度={out['temp_band']}(rsi={out['temp_rsi']})") - print(f"激活策略: {out['active']}") + print(f"激活策略(A股): {out['active']}") + if "markets" in out: + hk = out["markets"]["hk"] + print(f"港股温区={hk['state']} 激活策略(港股): {hk['active']}") print("权重排名(前15):") for name, w in list(weights.items())[:15]: mark = "✓" if w["matched"] else "观察"