small_sample
实际返回值是 status="small_sample"(样本量不足),不是 weak_signals(信号弱)。
两者含义完全不同:前者说「我不敢判」(统计效力不足),后者说「我判了,结论是不行」。
报告把它渲染成「❌ 未过」,抹掉了这个区别 —— 这是第一个口径问题。
market_daily / pre-trade-risk / rank_predictions 都是当日生成,没有陈旧读取output/daily/2026-09-15-pre-trade-risk.json」
—— 这是纯文案写死,与真实取数无关(但它会误导诊断方向,我一开始就被带偏过)
| 数据日 | ML 输出 n | 正分 | Gate4 实际返回 | 若 n≥8 | 若 n≥5 |
|---|---|---|---|---|---|
| 2026-09-08 | 12 | 6 | ✅ ok | ✅ | ✅ |
| 2026-09-09 | 12 | 6 | ✅ ok | ✅ | ✅ |
| 2026-09-10 | 8 | 4 | ❌ small_sample | ✅ | ✅ |
| 2026-09-11 | 10 | 6 | ✅ ok(临界) | ✅ | ✅ |
| 2026-09-14 | 5 | 5 | ❌ small_sample | ❌ | ✅ |
| 2026-09-15 | 5 | 3 | ❌ small_sample | ❌ | ✅ |
| 2026-09-16 | 9 | 3 | ❌ small_sample | ✅ | ✅ |
small_sample(n<10),
没有一天是 weak_signals(正分<3)。实现:tools/analysis/pre_trade_risk_check.py::check_gate4_strategy_match
def check_gate4_strategy_match(code: str, data_date: str) -> dict:
"第4关:策略匹配"
ml = _load_json(f"{PROJECT_ROOT}/output/ml/rank_predictions_{data_date}.json")
if not ml:
return {"status": "no_ml_data", "pass": False, "detail": {}}
predictions = ml.get("predictions", [])
pos_scores = [p for p in predictions if p.get("ml_score", 0) > 0]
neg_scores = [p for p in predictions if p.get("ml_score", 0) <= 0]
# 样本量判断
if len(predictions) < 10:
return {"status": "small_sample", "pass": False, "detail": detail}
# 如果正分标的太少,策略信号弱
if len(pos_scores) < 3:
return {"status": "weak_signals", "pass": False, "detail": detail}
return {"status": "ok", "pass": True, "detail": detail}
code 完全没用 —— 函数签名收了个股代码,
但两条判据只读 ML 全局产物 → 同一天所有候选返回的 detail 一模一样(实测三只票的 detail 完全相同)。len(predictions) 不是"候选池规模",
而是 候选池25 − discipline_blocked − sector_capped 的结果,
阻断项随市场状态剧烈波动(实测 5~17 只)→ 该阈值不稳定可满足。small_sample(不敢判)与 weak_signals(判了不行)
在 pass 上都是 False,下游只能看到"未过"。
predictions 的长度不是候选池规模,而是三道筛选后的剩余:
| 数据日 | 候选池 | discipline_blocked | sector_capped | = predictions | 主要阻断原因 |
|---|---|---|---|---|---|
| 2026-09-08 | 25 | 13 | 0 | 12 | 板块排名靠后 / 低价弱反弹 |
| 2026-09-10 | 25 | 17 | 0 | 8 | 低价弱反弹 / 板块排名靠后 |
| 2026-09-11 | 25 | 5 | 3 | 10 | 信号日涨停 / 板块排名靠后 |
| 2026-09-14 | 25 | 13 | 1 | 5 | 信号日涨停 ×3 / 近 2 日跌超 5% |
| 2026-09-15 | 25 | 8 | 1 | 5 | 信号日涨停 ×4 / 板块排名靠后 |
| 2026-09-16 | 25 | 5 | 2 | 9 | 信号日涨停 ×2 / 板块排名靠后 |
predictions 的长度压到了 10 以下,
于是 Gate4 判「样本量不足」。| DDD 概念 | 本系统对应 | 问题 |
|---|---|---|
| 限界上下文 | Gate4 属 Discipline(买入前风控) |
✅ 归属清楚 |
| 聚合根 | 本应查 CandidatePool / ModelLineage |
⚠️ 实际不查聚合根,直接读 ML 产物文件 |
| 不变量 | 「候选与模型策略匹配」 | 🔴 本体零登记 → 无法验证、无法豁免 |
| 读模型 (Read Model) |
rank_predictions.json 的 predictions 数组 |
🔴🔴 被当成真源使用。读模型是为消费而投影的产物, 长度由投影规则(含纪律过滤)决定,不该承载"样本量"这种契约语义 |
predictions 的长度是「投影后的剩余」,不是「候选池的真实规模」。实测本体 ontology/2026-09-14/ontology.yaml 中的出现次数:
| 标识 | 中文 | 本体中出现次数 | 状态 |
|---|---|---|---|
1_trap_detect | 假突破检测 | 0 | 未登记 |
2_data_integrity | 数据完整性 | 0 | 未登记 |
3_stock_quality | 标的质量 | 0 | 未登记 |
4_strategy_match | 策略匹配 | 0 | 未登记 |
5_t1_constraint | T+1 约束 | 0 | 未登记 |
strategy_match / gate4 | — | 0 | 未登记 |
pre_trade_risk_check.py 这个「执行器」,没有登记五关本身。ontology_gate 的 R1~R4 有完整登记
(gate_r1_sector_concentration / gate_r2_held_deprioritize /
gate_r3_over_position_block / gate_r4_feature_governance,
含 params_from: rules/registry.json#… 的参数真源指向)。gate_r3_over_position_block 的写法:params_from: rules/registry.json#position.single-position-caprules/registry.json,本体只声明「从哪读」。
改阈值须改 registry(有审计痕迹),而不是偷偷改一个 < 10。
| 问题 | 修法 |
|---|---|
| 报告页脚硬编码 09-15 | 改为读 risk_rel 实际路径(脚本里已有变量,只是文案写死了) |
small_sample 与 weak_signals 混渲染为「未过」 |
报告应区分:small_sample → 显示「⚠️ 样本不足·不予判定」;
weak_signals → 「❌ 信号弱」。
「不敢判」与「判了不行」对交易决策的含义完全不同 |
模块 docstring 与 intraday_advice_20260915.py 的路径引用 |
去掉写死的 2026-09-15,改为模板变量 |
len(predictions) < 10 这个阈值,是对「什么」的要求?small_sample 不再判 pass=False,
而是降级为「该关不参与计数」,五关按实际参与的关数折算(4 关过 → 仍可半仓)。small_sample 一个降级通道(C,避免因上游波动误伤)。
但这属于判据变更,必须按你的规矩先回测校准,不能直接拍。
| 补充项 | 内容 |
|---|---|
| 五关登记为 functions | 照 gate_r1~r4 范式,补 gate_1_trap_detect ~ gate_5_t1_constraint,
每条声明 on_object / returns / params_from |
阈值移入 rules/registry.json |
新增 discipline.gate4-sample-threshold 等条目,让阈值可审计、可回溯 |
| 本体校验 C20 | 「五关阈值必须来自 registry,不得硬编码」—— 扫描 check_gate*.py 中的字面量阈值 |
| # | 教训 | 本轮证据 |
|---|---|---|
| 1 | 读模型(Read Model)不能当契约真源用。 它的长度/形态由投影规则决定,会随无关的下游过滤而变。 |
predictions = 候选池 − 阻断项;「信号日涨停」纪律过滤把它压到 5~9 |
| 2 | 两个下游机制不该通过「共享输出长度」隐性耦合。 纪律过滤与 Gate4 各自独立生效是设计意图,耦合是意外副作用。 |
09-14/09-15 各有 3~4 只被"信号日涨停"阻断 → 直接导致 Gate4 判 small_sample |
| 3 | 「不敢判」与「判了不行」必须分开展示。 前者是统计效力问题(可能修数据源),后者是策略结论(应尊重)。 混在一起 → 掩盖真因、误导诊断方向。 |
报告统一渲染「❌ 未过」,4 天全是 small_sample 却被读成"策略不匹配" |