From 38e19fcc2c85c15379d53050cb7daa93707a02c3 Mon Sep 17 00:00:00 2001 From: xxm Date: Sun, 16 Aug 2026 10:39:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B8=AF=E8=82=A1=E5=9F=BA=E5=87=86?= =?UTF-8?q?=E6=94=B9=E4=B8=8B=E8=B7=8C=E5=B8=82=E6=97=B6=E6=AE=B5(?= =?UTF-8?q?=E5=88=86=E6=AE=B5=E7=AE=97HSI=E6=94=B6=E7=9B=8A=E5=86=8D?= =?UTF-8?q?=E5=90=88=E5=B9=B6)=E2=80=94=E2=80=94=E8=80=81=E8=8E=AB?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E5=8F=A3=E5=BE=84,1y10.4%/2y8.7%/10y4.5%?= =?UTF-8?q?=E6=97=A0=E5=A4=B1=E7=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/strategy_qualify.py | 41 +++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/deploy/profile-scripts/strategy_qualify.py b/deploy/profile-scripts/strategy_qualify.py index 88e41d9c..d5eab8ed 100644 --- a/deploy/profile-scripts/strategy_qualify.py +++ b/deploy/profile-scripts/strategy_qualify.py @@ -24,7 +24,11 @@ BENCH_DAYS = {"1y": 365, "2y": 730, "10y": 3650} def get_benchmarks(market="a"): - """大盘年化基准:1y/2y/10y""" + """大盘年化基准:1y/2y/10y + A股:全年大盘年化(market_regime 指数 close,复利年化) + 港股(2026-08-16 老莫确认):下跌市时段基准——trend_down 日期的 HSI 表现, + 线性放大年化(trend_down 时段收益 × 365/td天数)。港股策略只在下跌市运行,与全年比不公平。 + """ out = {} try: conn = sqlite3.connect(str(DATA_DIR / "mofin.db"), timeout=5) @@ -41,6 +45,41 @@ def get_benchmarks(market="a"): yrs = days / 365.0 if pct > -100: out[label] = round(((1 + pct / 100) ** (1 / yrs) - 1) * 100, 1) + # ── 港股:下跌市时段基准(trend_down 期间 HSI,按每次时段分段算再合并)── + if market == "hk": + out = {} + for label, days in BENCH_DAYS.items(): + cutoff = (datetime.now() - timedelta(days=days)).strftime("%Y-%m-%d") + rows = conn.execute( + "SELECT date, regime, close FROM market_regime WHERE market='hk' AND date>=? " + "ORDER BY date", (cutoff,)).fetchall() + # 分段:连续 trend_down 日组成段,段内 HSI 末/首 -1 + closes = {r[0]: r[2] for r in rows} + seg_ret = [] + in_seg = False + seg_first = None + seg_last_close = None + for d, reg, c in rows: + if reg == "trend_down" and c: + if not in_seg: + in_seg = True + seg_first = c + seg_last_close = c + else: + if in_seg: + seg_ret.append((c / seg_first - 1) * 100 if c and seg_first else 0) + in_seg = False + seg_first = None + seg_last_close = None + if in_seg and seg_first: + # 最后一段未结束(窗口尾部仍下跌市),用段内最后 close + if seg_last_close: + seg_ret.append((seg_last_close / seg_first - 1) * 100) + if not seg_ret: + continue + # 合并:段收益加总(下跌市期间累计表现),线性年化 ×365/窗口天数 + total_ret = sum(seg_ret) + out[label] = round(total_ret * (365.0 / max(days, 1)), 1) conn.close() except Exception: pass