diff --git a/deploy/profile-scripts/strategy_qualify.py b/deploy/profile-scripts/strategy_qualify.py index 711a1110..88e41d9c 100644 --- a/deploy/profile-scripts/strategy_qualify.py +++ b/deploy/profile-scripts/strategy_qualify.py @@ -91,6 +91,47 @@ def evaluate_strategy(version, market="a", best_regime=None, bench=None): } +def evaluate_all_regimes(version, market="a", bench=None): + """评估策略在【每个有数据温区】的资格(2026-08-16 老莫:策略可适应多个温区) + 返回 {regime: {long_ok, mid_ok, short_ok, cagr_10y, cagr_2y, cagr_1y, trades_10y, trades_2y, trades_1y}} + 只包含温区数据存在(有 10y 记录)的温区 + """ + bench = bench or get_benchmarks(market) + if not bench: + return {} + out = {} + try: + conn = sqlite3.connect(str(DATA_DIR / "mofin.db"), timeout=5) + conn.row_factory = sqlite3.Row + # 该策略所有温区(有 10y 记录才算数) + regimes = [r[0] for r in conn.execute( + "SELECT DISTINCT regime FROM strategy_regime_perf_by_period " + "WHERE strategy=? AND market=? AND period_tag='10y'", + (version, market)).fetchall()] + for rg in regimes: + cagr = {} + for pt in ["1y", "2y", "10y"]: + r = conn.execute( + "SELECT cagr_pct, win_rate, trades FROM strategy_regime_perf_by_period " + "WHERE strategy=? AND market=? AND regime=? AND period_tag=?", + (version, market, rg, pt)).fetchone() + cagr[pt] = (r["cagr_pct"], r["win_rate"], r["trades"]) if r else (None, None, None) + c10, w10, t10 = cagr.get("10y", (None, None, None)) + c2, w2, t2 = cagr.get("2y", (None, None, None)) + c1, w1, t1 = cagr.get("1y", (None, None, None)) + out[rg] = { + "cagr_10y": c10, "cagr_2y": c2, "cagr_1y": c1, + "trades_10y": t10, "trades_2y": t2, "trades_1y": t1, + "long_ok": c10 is not None and c10 > bench.get("10y", 0), + "mid_ok": c2 is not None and c2 > bench.get("2y", 0), + "short_ok": c1 is not None and c1 > bench.get("1y", 0), + } + conn.close() + except Exception: + pass + return out + + def load_availability(): """读手动可用性状态 {version: {available: bool, note, updated_at}}""" try: