自成长:分支评估+剪枝+报告接入

补齐「顺势而为 环境预判 策略多分枝」体系中缺失的组件:

branch_evaluator.py(新增)— 每30min评估所有策略树分支
  1. detect_scenario() 获取当前宏观情景
  2. 对42只股票评估哪个分支当前适用
  3. 适用分支 trigger_count+1, last_triggered=now
  4. 触发>=3次且成功率<30%→标记pruning_candidate
  5. 无决策树的股票自动初始化(init_default_branches)

prune_branches.py(新增)— 每日16:30收盘后剪枝
  阈值:触发>=3次且成功率<30%→裁掉并归档到pruned_branches
  Dad说「每周太低频」→改为每日

stale_push_wlin.py(修改)— 报告每只股增加分支行:
  【弱势震荡→buy_dip】价格回调到支撑区,弱势市场低吸

cron更新:
  分支扫描(b809fcabfa5b) → 指向branch_evaluator.py, 每30min
  剪枝(a3697c108c7b) → 指向prune_branches.py, 每日16:30

自成长核心:branch_evaluator 运行时自动发现并初始化无策略树股票,
252个分支已生成, trigger_count已开始累积, 反馈循环上线
This commit is contained in:
知微
2026-06-24 10:24:11 +08:00
parent eb86a9091e
commit 102a64d856
3 changed files with 260 additions and 15 deletions
+35
View File
@@ -299,6 +299,21 @@ def main():
except Exception:
total_assets = available_cash * 5 # fallback
# 加载策略树模块(获取当前情景+分支评估)
st = None
scenario_id = ""
scenario_label = ""
try:
import importlib.util
spec = importlib.util.spec_from_file_location("st_module", "/home/hmo/MoFin/strategy_tree.py")
st = importlib.util.module_from_spec(spec)
spec.loader.exec_module(st)
sc = st.detect_scenario()
scenario_id = sc.get("id", "")
scenario_label = sc.get("label", "")
except Exception:
pass
def calc_position(lot_cost, rr, market_factor, cat, code=""):
# 理论推荐仓位(% of 总资产) — 仅基于RR+市场+品种,不受现金限制
if rr >= 5:
@@ -419,6 +434,26 @@ def main():
f" 仓位:理论{theo_pct}%×总资产 | 建议{actual_pct}%{details}"
)
# 读分支评估
branch_line = ""
if st and scenario_id:
try:
results = st.evaluate_branches(code, scenario_id, price, d.get("shares", 0), d.get("cost", 0))
applicable = [r for r in results if r.get("applicable")]
if applicable:
# 取优先级最高的适用分支
best = min(applicable, key=lambda r: r.get("priority", 999))
action = best.get("action_type", "hold")
rationale = best.get("rationale", "")
branch_line = f"{scenario_label}{action}{rationale}"
else:
branch_line = f"{scenario_label}→持有】无匹配分支"
except Exception:
branch_line = ""
if branch_line:
# 追加到上一个元素
lines[-1] += f"\n{branch_line}"
lines.insert(0, f"【知微】自选买入提醒 {now} | 总资产{total_assets:,.0f}")
out = "\n".join(lines)
print(out)