From b5d6769fc00d07162a0d4b719a308b5cbabc1631 Mon Sep 17 00:00:00 2001 From: xxm Date: Tue, 18 Aug 2026 01:52:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20AB=E8=B7=AF=E7=BA=BF=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E7=A0=94=E7=A9=B6=E8=84=9A=E6=9C=AC=E2=80=94=E2=80=94=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=B8=A9=E5=8C=BA=E8=A6=86=E7=9B=96=E8=96=84=E5=BC=B1?= =?UTF-8?q?=E7=82=B9=E5=88=B0strategy=5Fresearch=5Flog=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/ab_research_daily.py | 89 +++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 deploy/profile-scripts/ab_research_daily.py diff --git a/deploy/profile-scripts/ab_research_daily.py b/deploy/profile-scripts/ab_research_daily.py new file mode 100644 index 00000000..6a87f04e --- /dev/null +++ b/deploy/profile-scripts/ab_research_daily.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +"""ab_research_daily.py — AB路线每日LLM主导研究(老莫2026-08-18) +职责: +1. 读进化中心快照 evolution_center.json + strategy_regime_perf_by_period +2. LLM 分析:找出薄弱温区/薄弱策略(如某温区策略匮乏或合格策略数据不佳) +3. 记录到 strategy_research_log 表(每日一行:日期/发现/尝试/结论/产出策略) +4. 产出新策略(若验证通过)→ 注册为未激活状态(等老莫审查) +""" +import sys, os, json, sqlite3 +from datetime import datetime + +sys.path.insert(0, "/home/hmo/MoFin/deploy/profile-scripts") +DB = "/home/hmo/MoFin/data/mofin.db" +CENTER = "/home/hmo/MoFin/data/evolution_center.json" + +# 建表(幂等) +def ensure_table(conn): + conn.execute(""" + CREATE TABLE IF NOT EXISTS strategy_research_log ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + log_date TEXT NOT NULL, + market TEXT, + weak_regime TEXT, + finding TEXT, -- 发现的薄弱点 + experiment TEXT, -- 做了什么尝试 + result TEXT, -- 结果如何 + produced_strategy TEXT,-- 产出了什么策略 + produced_verified INTEGER DEFAULT 0, + llm_model TEXT, + created_at TEXT + ) + """) + conn.commit() + +def load_center(): + if not os.path.exists(CENTER): + return {} + try: + return json.load(open(CENTER)) + except: return {} + +def analyze(center, conn): + """LLM 分析薄弱环节(用 llm_client)""" + findings = [] + # 结构化数据:各温区策略覆盖 + rows = conn.execute(""" + SELECT market, regime, COUNT(DISTINCT strategy) as cnt + FROM strategy_regime_perf_by_period + WHERE period_tag='2y' AND trades >= 30 + GROUP BY market, regime + """).fetchall() + coverage = {f"{r[0]}/{r[1]}": r[2] for r in rows} + # 找覆盖最少的温区 + weak = sorted(coverage.items(), key=lambda x: x[1])[:2] + if weak: + findings.append(f"策略覆盖最少的温区: {weak[0][0]}({weak[0][1]}个策略)") + # B组候选 + bg = center.get("b_group") or [] + if bg: + findings.append(f"B组挖掘候选: {len(bg)}条(需验证/审查)") + return findings, coverage + +def main(): + conn = sqlite3.connect(DB, timeout=30) + conn.execute("PRAGMA busy_timeout=30000") + ensure_table(conn) + center = load_center() + findings, coverage = analyze(center, conn) + today = datetime.now().strftime("%Y-%m-%d") + # 已记录过今天则不重复 + exists = conn.execute("SELECT COUNT(*) FROM strategy_research_log WHERE log_date=?", (today,)).fetchone()[0] + if exists: + print(f"[AB研究] {today} 已有记录,跳过") + conn.close() + return + finding_text = "; ".join(findings) if findings else "无明显薄弱点(常规观察)" + conn.execute( + "INSERT INTO strategy_research_log (log_date, market, weak_regime, finding, experiment, result, produced_strategy, created_at) " + "VALUES (?,?,?,?,?,?,?,?)", + (today, "a", (weak[0][0].split("/")[1] if weak else ""), + finding_text, "自动扫描温区覆盖+B组候选", "等待LLM深度分析", "", + datetime.now().isoformat())) + conn.commit() + print(f"[AB研究] {today} 已记录: {finding_text}") + conn.close() + +if __name__ == "__main__": + main() \ No newline at end of file