Rd Agent Factor Mining logo

Rd Agent Factor Mining

CommunityPopular
qusong0627
rd-agent-factor-mining

RD-Agent A股因子挖掘端到端流水线:环境 preflight → 启动演化 → 轮询完成 → 批量回测评估 → IC/Sharpe 排序 → explain 解读 → export 入库 → Markdown 报告。在 QuantBot / Claude Code 中挖因子时使用,一条命令跑完整流程。触发词:挖因子、因子挖掘、挖新因子、因子演化、RD-Agent、alpha agent、自动挖因子、一键挖因子、因子回测、演化因子、启动因子任务

Overview

Publisherqusong0627
RepositoryQuantMind
Skill namerd-agent-factor-mining
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 Rd Agent Factor Mining 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/rd-agent-factor-mining
  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/rd-agent-factor-mining .claude/skills/rd-agent-factor-mining
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Rd Agent Factor Mining 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 Rd Agent Factor Mining 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 Rd Agent Factor Mining 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,执行前先读它。

RD-Agent 因子挖掘(端到端流水线)

调用 RD-Agent(Alpha Agent)自动挖掘 A 股 alpha 因子,覆盖完整链路: preflight → evolve(LLM 演化)→ 轮询 → 批量回测 → 排名 → explain → export → 报告。

0. 环境前置(必须,一分钟先过)

做任何挖掘前,先跑容器内三项健康检查。任一 FAIL 都要先修再挖。

bash
cd ~/projects/quantmind && python3 scripts/alpha_agent/factor_pipeline.py --check-env
# 期望 3 项全 PASS: conda_shim / litellm_patch / deepseek_key
检查项作用失败处理
hardware最低 8 核 / 32GB。RD-Agent 演化会把 CPU/内存打满,低于此规格直接 412 失败,避免整机卡死换机器或关其他重负载;测试可设 ALPHA_AGENT_SKIP_HW_LOCK=1(生产勿开)
conda_shimRD-Agent LocalEnv 硬编码 rdagent4qlib conda 环境,容器无 conda,靠 shim 映射到容器 python确认 docker/conda-shim 挂载 /usr/local/bin/conda:ro 且文件有 +x
litellm_patchlitellm 1.97 + pydantic 2.13 冲突(Message is not fully defined)确认 docker/litellm_sitecustomize.py 挂载为 site-packages/sitecustomize.py:ro
deepseek_key因子挖掘走 DeepSeek 通道(llm_env.py 优先级最高)更新 ~/projects/quantmind/.env 的 DEEPSEEK_API_KEY,改后必须 docker compose up -d quantmind recreate

preflight 机制全在管道脚本内置;手动检修环境见文末「常见问题」。

1. 一键管线(推荐入口)

bash
cd ~/projects/quantmind

# 最小示例:一个方向,演化+批量回测+排名(默认报告 /tmp/rd_agent_factor_report.md)
python3 scripts/alpha_agent/factor_pipeline.py --direction "连板高度递减与涨停回封率"

# 全流程:演化 + 回测 + top5 解读 + 最高 |IC| 导出
python3 scripts/alpha_agent/factor_pipeline.py \
  --direction "筹码集中度上行伴随低位换手放大" \
  --universe csi300 --loops 3 \
  --explain-top 5 --export --min-ic 0.03 \
  --out /tmp/factor_report.md

# 只看环境
python3 scripts/alpha_agent/factor_pipeline.py --check-env

参数:

参数默认说明
--direction必填挖掘方向/假设,中文优先(见方向建议库)
--universecsi300csi300/csi500/csi1000/sse50/gem/star/csi800/all_a
--loops3演化轮数,实际以任务详情为准(可能出现归一值)
--check-envoff只跑环境健康检查
--no-backtestoff演化完成即停,不批量回测
--backtest-start2025-01-01回测起始日(到当天)
--backtest-universe=universe回测股票池
--explain-top N0对
--export / --min-icoff / 0.0对
--out/tmp/rd_agent_factor_report.md报告路径
--show-logoff轮询时打印任务日志

管线阶段(脚本自动执行):

  1. preflight 三项健康检查
  2. evolve 启动演化 → 拿 task_id
  3. 轮询 tasks/{id} 直到 completed(打印 phase/loop/error)
  4. 收集本次 task_id 的因子(metadata.task_id 过滤)
  5. 逐个 factor/{id}/backtest 触发 → 轮询全部 completed
  6. 按 |IC| 排序打印排行榜
  7. 对 --explain-top 因子 explain(LLM 解读,写入报告)
  8. --export 最高分因子
  9. 生成 Markdown 报告到 --out

一个方向跑完约 30–90 分钟(数据管线 + LLM 演化 + 逐因子回测)。

1.5 因子工厂(QuantDB 富字段 × 算子 × 窗口 → 成千上万表达式因子)

R&D-Agent 是「LLM 提假设 → 逐因子回测」;因子工厂是「系统性批量衍生」:拿 QuantDB 的几百个数值字段 (l1_factors / features_daily)做算子 × 窗口 × 二元组合,全量算 IC/ICIR、相关性去重,产出可训练 parquet。 适合「数据面已知、想从海量式子里筛好货」。两者互补,可都跑。

bash
# 容器内执行(重依赖 duckdb/pandas,QwenPaw 本地 venv 跑不了)
docker exec -w /app quantmind python /app/backend/scripts/factor_factory.py \
  --start-date 2025-09-01 --end-date 2026-08-31 --top-n 200
# 冒烟(小样本,先验证环境)
docker exec -w /app quantmind python /app/backend/scripts/factor_factory.py --smoke
  • 产物:data/quantcustom/6_ml_datasets/l1_factors/dt=YYYYMMDD/data.parquet(列:symbol(后缀式) + date + OHLCV + 因子 float32)、MANIFEST.csv、PROPOSALS.json。
  • 关键参数:--windows 5,10,20,60、--ops tsrank,tsstd,roc,zscore,delta,decay,slope、--cs-ops csrank,cszscore、--binary-ops csdiff,csratio,tscorr、--top-n 200、--pool-factor 3.0、--corr-threshold 0.85、--jobs 0(自动并行)、--compression zstd、--out。
  • 只读展示:GET /api/v1/alpha-agent/factory-factors(读 MANIFEST,前端因子库加「工厂」徽标,仅展示不回测/训练操作)。
  • 训练侧读取:QuantDBFactorReader(mode="CUSTOM")(QM_QUANTCUSTOM_DATA_DIR)。
  • 落盘/目录口径见 [[quantdb-data-structure]] 的 quantcustom 小节。

2. 手动分步(需要精细控制时用 API)

认证

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"

池子 / 类别 / 数据健康

bash
curl -s -H "$AUTH" "$BASE/api/v1/alpha-agent/universes"        # 支持的股票池
curl -s -H "$AUTH" "$BASE/api/v1/alpha-agent/markets"          # 支持的市场
curl -s -H "$AUTH" "$BASE/api/v1/alpha-agent/factor-categories" # 挖掘类别参考
curl -s -H "$AUTH" "$BASE/api/v1/alpha-agent/data-summary"      # 数据覆盖(日期/股票数)

启动演化

bash
curl -s -X POST "$BASE/api/v1/alpha-agent/evolve" -H "$AUTH" \
  --data-urlencode "market=a_share" \
  --data-urlencode "universe=csi300" \
  --data-urlencode "loop_n=3" \
  --data-urlencode "direction=低换手率高动量" \
  -w "\nHTTP %{http_code}\n"
# 返回 task_id(后续所有步骤用)

轮询 / 取消

bash
curl -s -H "$AUTH" "$BASE/api/v1/alpha-agent/tasks/{task_id}"      # 状态 progress/phase/loop/error
curl -s -H "$AUTH" "$BASE/api/v1/alpha-agent/tasks/{task_id}/log"  # 实时日志(含失败原因)
curl -s -X POST -H "$AUTH" "$BASE/api/v1/alpha-agent/tasks/{task_id}/cancel"
# 状态机: pending → running → backtesting → completed | failed

因子回测(注意是 query 参数,不是 form)

bash
curl -s -X POST -H "$AUTH" "$BASE/api/v1/alpha-agent/factors/{factor_id}/backtest?start_date=2025-01-01&end_date=2026-08-21&universe=csi300&data_source=qlib_bin"
# factors 列表里 ic_value/sharpe_ratio/rank_ic 回测完成后回填;status 变 completed

解读 / 导出 / 统计

bash
curl -s -X POST -H "$AUTH" "$BASE/api/v1/alpha-agent/factors/{factor_id}/explain"   # LLM 解读因子逻辑
curl -s -X POST -H "$AUTH" "$BASE/api/v1/alpha-agent/factors/{factor_id}/export"    # 加入生产特征库
curl -s -H "$AUTH" "$BASE/api/v1/alpha-agent/factors"                               # 全部因子(含本次 task 的)
curl -s -H "$AUTH" "$BASE/api/v1/alpha-agent/stats"                                 # avg_ic/best_sharpe 等

3. 方向建议库(direction 直接用)

优先挖 78 核心因子集之外的空白区(筹码/微观结构/连板情绪/隔夜/资金流持续性):

text
1. 连板情绪承继   连板高度递增与涨停回封率,捕捉题材情绪承接力由弱转强的启动票
2. 筹码分布       筹码集中度上行伴随低位换手放大,获利盘充分消化的突破信号
3. 隔夜/日内背离  隔夜收益与日内收益背离,捕捉大单隔夜布局意图
4. 资金流持续性   主力大单净流入的天数持续性与金额强度共振
5. 下行波动偏度   低下行风险与负偏度修正,挖掘低波动异象的非对称变体
6. 量价微观结构   开盘跳空幅度与量能共振,叠加尾盘动量延续
7. 动量质量       趋势斜率 R2 与收益动量叠加,过滤高噪音动量
8. 波动聚簇修正   波动率自相关的反转信号(高低波动切换)
9. 流动性衰减     换手率衰减速度与跌幅对比
10. 行业相对强度   个股相对行业指数 20 日超额与行业轮动方向一致

每批建议跑 1–3 个方向(串行排队),避免队列过载。

4. 验收标准(工具完成后自查)

  • preflight 三项 PASS
  • 演化任务 completed(非 failed)
  • 有因子入库且完成批量回测(ic_value 非空)
  • 排行榜上 |IC| 高、ICIR 明显 > 0 的因子受关注
  • 高分因子完成 explain,解读与 direction 假设一致(非噪声)
  • 确认有效的因子已 export(日志有导出记录)
  • 报告落盘(默认 /tmp/rd_agent_factor_report.md)

5. 常见问题与踩坑

现象根因处理
timeout: failed to run command 'python' + conda: not found容器无 conda,RD-Agent 需 rdagent4qlib envconda shim 挂载 /usr/local/bin/conda;宿主机文件记得 chmod +x
Message is not fully defined / ChatCompletionReasoningSummaryTextBlock is not definedlitellm 1.97 + pydantic 2.13 冲突docker/litellm_sitecustomize.py 挂载为 sitecustomize
Authentication Fails ... api key is invalidDEEPSEEK_API_KEY 失效换 key 到 .env,docker compose up -d quantmind recreate 才生效
因子 status=pending 且 ic_value=null还没跑回测触发 backtest(pipeline /--no-backtest 时更是如此)
任务秒 failed先看 tasks/{id}/log 尾部具体错误常见上面两类,按表修
engine upstream unavailable(503)回测并发把 engine 挤忙稍等重试;少并行任务
传 universe=all_a 详情显示 csi300后端对部分池归一以任务详情 universe 为准

6. 参考文件

  • 一键管线:scripts/alpha_agent/factor_pipeline.py
  • 环境修复:docker/conda-shim、docker/litellm_sitecustomize.py(compose 挂载固化)
  • RD-Agent Runner 入口:scripts/alpha_agent/run_rd_agent.py
  • 因子工厂:backend/scripts/factor_factory.py(+ backend/scripts/alpha_library_factors.py 复用算子/写盘)

Frequently asked questions

What does the Rd Agent Factor Mining AI skill do?

RD-Agent A股因子挖掘端到端流水线:环境 preflight → 启动演化 → 轮询完成 → 批量回测评估 → IC/Sharpe 排序 → explain 解读 → export 入库 → Markdown 报告。在 QuantBot / Claude Code 中挖因子时使用,一条命令跑完整流程。触发词:挖因子、因子挖掘、挖新因子、因子演化、RD-Agent、alpha agent、自动挖因子、一键挖因子、因子回测、演化因子、启动因子任务

Why use Rd Agent Factor Mining on TypingMind?

Because you install it once and use it with any model. Rd Agent Factor Mining 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 Rd Agent Factor Mining in TypingMind?

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

Which AI models can use Rd Agent Factor Mining?

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 Rd Agent Factor Mining?

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

Is the Rd Agent Factor Mining 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 👇