feat: AB路线每日研究脚本——记录温区覆盖薄弱点到strategy_research_log表
This commit is contained in:
@@ -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()
|
||||||
Reference in New Issue
Block a user