Batch Inference Analysis logo

Batch Inference Analysis

CommunityPopular
qusong0627
batch-inference-analysis

批量推理结果分析 — 用 QuantMind 选股策略方法论分析每日信号、行业轮动、个股分数区间、负分参考。在 QuantBot / Claude Code 中分析批量推理结果、解读每日信号、判断市场状态、选股决策、做空参考时使用。触发词:分析批量推理、解读信号、每日选股、市场状态判断、行业轮动分析、负分参考、信号分析、批次分析、选股决策

Overview

Publisherqusong0627
RepositoryQuantMind
Skill namebatch-inference-analysis
Stars
1.7K
Forks
387
Bundled files
Instructions only
LicenseAGPL-3.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by qusong0627 on GitHub. Read the source before you install it.

Installation

Install the Batch Inference Analysis AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/qusong0627/QuantMind/tree/master/skills/batch-inference-analysis
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/qusong0627/QuantMind.git /tmp/QuantMind
mkdir -p .claude/skills
cp -r /tmp/QuantMind/skills/batch-inference-analysis .claude/skills/batch-inference-analysis
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Batch Inference Analysis in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Batch Inference Analysis on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Batch Inference Analysis is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

⚙️ 本技能遵循公共运行环境契约(最高优先级,先于本文其余内容执行): 详见 _shared/env-contract.md,执行前先读它。

批量推理结果分析技能

基于 QuantMind 选股策略方法论,分析批量推理产出的每日信号,做出入场/选股/买卖/做空决策。

数据基础

批量推理产出:

  • batch:多个交易日的推理集合(/models/inference/batch/{batch_id})
    • member_runs:每个交易日的 run 记录(run_id/trade_date/signals_count)
  • 单日 run:/models/inference/runs/{run_id}
    • items:5377+ 只股票信号,每只含 fusion_score(分数)/board(板块)/industry(行业)/market_cap_tier(市值分档)/trend(趋势)/prev_score/prev2_score/next_score

认证

bash
BASE=http://127.0.0.1:8000
TOKEN=$(curl -s -X POST $BASE/api/v1/auth/login -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"admin123","tenant_id":"default"}' \
  | python3 -c "import sys,json; print(json.load(sys.stdin).get('access_token',''))")
AUTH="Authorization: Bearer $TOKEN"

1. 拉取批量推理数据

bash
# 1. 批量推理历史
curl -s -H "$AUTH" "$BASE/api/v1/models/inference/batches?page=1&page_size=10"

# 2. 某批次详情(含 member_runs 每日记录)
curl -s -H "$AUTH" "$BASE/api/v1/models/inference/batch/{batch_id}"

# 3. 单日 run 信号(分析数据源)
curl -s -H "$AUTH" "$BASE/api/v1/models/inference/runs/{run_id}"

分析入口:用 batch 的 member_runs 拿到每日 run_id,逐个拉取信号分析,或用最近一个 run 分析今日。

批量聚合(推荐,一次拿全)

/models/inference/batch/{batch_id}/aggregate 一次性返回整批的聚合分析(免去逐日拉取):

bash
curl -s -H "$AUTH" "$BASE/api/v1/models/inference/batch/{batch_id}/aggregate"
# 返回: {per_symbol, groups, movers, daily, meta}
# per_symbol: 每只股票跨日分数/排名/IC
# groups: 行业/板块分组聚合
# movers: 分数变动最大的标的
# daily: 每日 TopN/分布
# meta: 批次数/区间/IC/共识带(Mann-Kendall 趋势)

2. 市场状态判断(三层过滤)

第1层:行业信号强度 — 决定是否入场

用 Python 计算行业 avg Top1:

python
import json, urllib.request

def fetch_run(run_id):
    req = urllib.request.Request(f"{BASE}/api/v1/models/inference/runs/{run_id}",
        headers={"Authorization": f"Bearer {TOKEN}"})
    return json.load(urllib.request.urlopen(req))  # 顶层直接含 items/total

def market_signal(items, top_n=20):
    # 取 Top20 按分数
    top = sorted(items, key=lambda x: -(x.get("fusion_score") or 0))[:top_n]
    # 按行业分组,取每行业最高分
    ind_top = {}
    for it in top:
        ind = it.get("industry", "") or "未知"
        s = it.get("fusion_score") or 0
        if ind not in ind_top or s > ind_top[ind]:
            ind_top[ind] = s
    ind_avg_top1 = sum(ind_top.values()) / max(1, len(ind_top))
    strong = sum(1 for s in ind_top.values() if s >= 0.10)
    return {"ind_avg_top1": ind_avg_top1, "strong_industries": strong, "top_industries": dict(sorted(ind_top.items(), key=lambda x:-x[1])[:5])}

入场阈值(参数扫描优化):

策略入场线空仓线强行业数
保守≥0.10<0.10≥5
平衡(推荐)≥0.09<0.06≥2
激进≥0.07<0.06≥1

判断:

  • ind_avg_top1 < 0.06 → 绝对空仓
  • 0.06-0.09 → 观望/极轻仓
  • ≥0.09 → 正常选股

第2层:大盘均线过滤 — 防崩盘

模型在暴跌时给高分是反向信号。用指数 K 线判断:

bash
# 上证指数 K 线(QuantDB index_daily)
curl -s -H "$AUTH" "$BASE/api/v1/market/kline?symbol=000001.SH&market=A&period=daily&days=30"

规则:上证指数 < MA20 → 强制空仓(避开 2024 年 2 月微盘崩盘)。

第3层:强行业数仓位管理

强行业数市场状态仓位
≥5强势100% 满仓
3-5震荡偏强50% 半仓
2-3震荡30% 轻仓
<1.5弱势空仓

3. 个股选股(分数区间)

核心分数区间

个股分数操作理由
0.10-0.12首选(黄金区间)胜率64.8%,均收+1.19%,最大亏损-10.4%
0.12-0.15可选(主板优先)胜率79%但样本少,警惕追高
0.15-0.20谨慎仅强市有效
≥0.20极谨慎趋势加速,样本少
<0.10不买信号太弱

注意:0.12-0.14 是"追高陷阱"(动量特征强,易买山顶);0.10-0.11 假信号区必须配合行业确认。 重要:以上绝对阈值基于特定模型分布,换模型后先看 score_distribution(第7节)用分位数映射。

python
def pick_stocks(items, market_sig):
    picks = []
    for it in items:
        s = it.get("fusion_score") or 0
        if not (0.10 <= s <= 0.12): continue
        if market_sig["ind_avg_top1"] < 0.09 and s < 0.11: continue  # 假信号区
        # 主板优先
        board = it.get("board", "")
        if "创业" in board or "科创" in board: continue
        # 排除 ST
        name = it.get("stock_name", "")
        if "ST" in name or "退" in name: continue
        picks.append(it)
    picks.sort(key=lambda x: -(x.get("fusion_score") or 0))
    return picks[:5]  # 每天选3-5只

3天趋势(决定买点)

用 prev_score/next_score 判断:

趋势模式操作
先升后降低→高→降最佳买点(胜率78%)
连续上升低→高→更高过热不追
连续下降高→降→降信号衰退不买

反直觉:分数下降比上升好——高位回落说明绝对分仍高。

4. 负分参考(做空/回避)

精确做空分数线

条件下跌概率做空均收
微盘(<30亿) + 分数≤-0.2072.0%+5.14%
微盘 + 分数≤-0.1568.6%+3.17%
小盘 + 分数≤-0.2065.5%+2.62%
中盘 + 分数≤-0.1760.4%+1.16%
大盘/超大盘 + 任何负分≤52%不做空

负分也会涨(错杀)

  • 超大盘负分 -0.13~-0.14:下跌概率仅 42%,均收 +3%——错杀最佳例证
  • 大盘负分 -0.11:上涨概率 51%
  • 科创板负分 -0.06~-0.15:均收全为正,做空价值最低
  • 警戒线 -0.22:即使大盘股低于此分也会崩

一句话落地

做空只做微盘/小盘 + 分数≤-0.15;大盘/超大盘/科创板的负分是错杀,-0.22 以下才真危险;轻负分(>-0.06)无信息。

python
def short_candidates(items):
    shorts = []
    for it in items:
        s = it.get("fusion_score") or 0
        if s > -0.15: continue
        tier = it.get("market_cap_tier", "")
        if tier in ("大盘", "超大盘"): continue  # 错杀
        if "科创" in it.get("board", ""): continue  # 抗跌
        shorts.append(it)
    shorts.sort(key=lambda x: x.get("fusion_score") or 0)
    return shorts[:10]

5. 行业轮动分析

python
def sector_rotation(batch_runs):
    # 跨多个交易日统计强行业出现频次
    from collections import Counter
    ind_days = Counter()
    for run in batch_runs[:30]:  # 最近30个交易日
        items = fetch_run(run["run_id"]).get("items", [])
        top = sorted(items, key=lambda x: -(x.get("fusion_score") or 0))[:20]
        for it in top:
            if (it.get("fusion_score") or 0) >= 0.10:
                ind_days[it.get("industry", "")] += 1
    return ind_days.most_common(10)

判断:

  • 行业信号持续 ≥3 天 = 真轮动(非一日游)
  • 新行业出现 Top1 ≥0.10 = 资金切换方向
  • 强行业数 ≥3/天 = 有行情;≤1.5/天 = 空仓

6. 完整分析流程

当用户要求"分析批量推理结果"时:

  1. 确认批次:/models/inference/batches 找最近 completed 的 batch
  2. 拿 member_runs:/models/inference/batch/{id} 得到每日 run_id
  3. 拉今日信号:取最新 run 的 items
  4. 市场状态:行业 avg Top1 + 强行业数 + 大盘均线
  5. 选股:分数 0.10-0.12 + 主板 + 3天趋势"先升后降"
  6. 负分参考:微盘/小盘极端负分列出做空候选
  7. 行业轮动:跨日统计强行业
  8. 输出决策:入场/仓位/个股清单/做空清单/规避

7. 不同模型分数范围的处理(关键)

每个模型训练后分数范围不同(实测:这个融合模型 fusion_score 范围 -0.996 ~ 0.965,而方法论假设 0-0.2 是另一套模型)。绝对阈值不能直接套用,必须先了解当前模型的分数分布。

python
def score_distribution(items):
    scores = sorted(x.get("fusion_score") or 0 for x in items)
    n = len(scores)
    return {
        "min": round(scores[0], 3),
        "max": round(scores[-1], 3),
        "p10": round(scores[int(n*0.1)], 3),
        "p25": round(scores[int(n*0.25)], 3),
        "p50": round(scores[int(n*0.5)], 3),
        "p75": round(scores[int(n*0.75)], 3),
        "p90": round(scores[int(n*0.9)], 3),
    }

模型分数范围 → 方法论阈值映射

方法论阈值(0.10-0.12 黄金区间等)基于特定模型的分布。使用时:

  1. 先跑 score_distribution 了解当前模型分布
  2. 用分位数替代绝对分数判断高低:
    • 黄金区间 ≈ 高分位带(如 p75-p90,需结合回测验证)
    • 追高区 ≈ 最高分位(p90+)
    • 负分做空 ≈ 最低分位(p10 以下)
  3. 跨模型对比时,统一用百分位排名,不用原始分数

模型选择(多模型择优)

不同模型分数分布和预测能力不同,分析时可对比:

bash
# 各模型推理历史分数(单股)
curl -s -H "$AUTH" "$BASE/api/v1/models/inference/stock/{symbol}/history"
# 模型列表(含元数据)
curl -s -H "$AUTH" "$BASE/api/v1/models"

择优标准:

  • 分数分布合理(不过度集中、有区分度)
  • 该模型回测胜率/IC 高(见 [[backtest-center]])
  • 黄金区间候选数量适中(太多=无区分度,太少=过严)

融合模型特殊处理

融合模型已按百分位加权合成,fusion_score 可直接用,但分数范围仍因源模型而异——同样先看分布再定阈值。

8. 模型分数校准回测(核心新增)

每个模型训练后分数范围不同,用历史信号自动回测找出该模型最适合的分数区间。

8.1 调用校准接口(异步任务 + 进度)

校准是后台任务,提交立即返回 task_id,轮询查进度(避免阻塞引擎):

bash
# 1. 提交校准任务(秒回 task_id)
curl -s -X POST -H "$AUTH" "$BASE/api/v1/selection/score-calibration?days=180&horizons=1,3,5,10&top_n=50"
# 返回: {"status":"submitted","task_id":"calib_xxx", ...}

# 2. 轮询任务进度(progress: 5→100,message 显示阶段)
curl -s -H "$AUTH" "$BASE/api/v1/selection/score-calibration/{task_id}"
# 返回: {"status":"running/completed","progress":85,"message":"回测中... 45/60 天","result":{...}}

参数:

  • days:回测历史交易日数(30~478)
  • horizons:未来 N 日列表(1,3,5,10 / 1,5,20 等)
  • top_n:重点标注排名前 N

流程:POST 提交 → 每 2 秒轮询 GET → 状态 completed 后取 result。后台任务阶段:读取信号(5%)→分组(15%)→价格面板(30%)→市值(45%)→回测(55%+逐日推进)→汇总(95%)→完成(100%)

8.2 输出解读

score_summary(分数档 × 多周期):

字段含义
score_band分数档(≤-0.25 ~ ≥0.20,正负对称)
n该档样本数
top50_count该档内排名前50样本数
avg_rank该档股票平均绝对排名
horizons每个 T+N 的:胜率/下跌概率/均收/中位收益

matrix(分数档 × 市值 × 下跌概率):主周期的市值分档下跌概率

neg_industry_avg(负分行业 avg):负分最深行业排序 neg_board_avg(板块负分 avg):主板/创业板/科创板/北交所

recommended_band:系统推荐的最优分数档

8.3 关键洞察(当前模型实测)

用 days=60&horizons=1,3,5,10 实测(94万样本):

  • 正分最优档:0.05~0.08 → T+5 胜率 53%、下跌 46.1%、均收 +0.753%
  • 方法论黄金区 0.10~0.12 在此模型反而均收 -0.387%(负!)→ 必须按模型校准
  • 极端负分 ≤-0.25 → T+5 下跌 62.1%、T+10 下跌 67.5%、均收 -4.971%(做空信号)
  • 负分行业 avg:林业/油服/种植业/农产品加工负分最深(做空首选)
  • 板块负分:创业板 -0.50 最深、科创板 -0.38 抗跌

8.4 校准方法

  1. 训练完新模型 → 跑 score-calibration
  2. 看 recommended_band → 该模型的最佳分数区间
  3. 对比不同模型 → 用各自 calibrated 区间,不用统一阈值
  4. 动态更新选股阈值 → 用该校准结果替换方法论默认值

9. 完整分析流程(含模型适配)

当用户要求"分析批量推理结果"时:

  1. 确认批次:/models/inference/batches 找最近 completed
  2. 拿每日 run:/models/inference/batch/{id} 的 member_runs
  3. 拉最新信号:/models/inference/runs/{run_id} 的 items
  4. 分数校准:/selection/score-calibration 看该模型最优分数档
  5. 市场状态:行业 avg Top1(用校准档映射阈值)+ 强行业数 + 大盘均线
  6. 选股:按校准档定位黄金区间 + 主板 + 3天趋势
  7. 负分参考:校准出的极端负分档 + 微盘/小盘
  8. 行业轮动:跨日统计强行业
  9. 输出决策:入场/仓位/个股/做空/规避

10. 常见问题

现象处理
信号分数普遍偏低/偏高不同模型分布不同,先 score-calibration 再定阈值
黄金区间选不出用校准档,或放宽到 p70-p90
行业为空部分 run 行业缺失,按 board 分组替代
跨模型对比统一用百分位排名,不用原始分数
想选最优模型对比各模型校准结果 + 回测指标
校准接口慢减少 days 或 horizons,或缓存结果

Frequently asked questions

What does the Batch Inference Analysis AI skill do?

批量推理结果分析 — 用 QuantMind 选股策略方法论分析每日信号、行业轮动、个股分数区间、负分参考。在 QuantBot / Claude Code 中分析批量推理结果、解读每日信号、判断市场状态、选股决策、做空参考时使用。触发词:分析批量推理、解读信号、每日选股、市场状态判断、行业轮动分析、负分参考、信号分析、批次分析、选股决策

Why use Batch Inference Analysis on TypingMind?

Because you install it once and use it with any model. Batch Inference Analysis is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Batch Inference Analysis in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/qusong0627/QuantMind/tree/master/skills/batch-inference-analysis. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Batch Inference Analysis?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Batch Inference Analysis?

As many as you like. As long as a model supports skills, you can use Batch Inference Analysis with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Batch Inference Analysis AI skill free?

Yes. It is published on GitHub by qusong0627 under the AGPL-3.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇