qmt-inner-backtest

qmt-inner-backtest is a skill for Claude Code, Codex from dfkai/xtquantai. It costs 96 tokens per session (3,719 once invoked), scanned A, original, MIT.

A procedure for turning a trading strategy or research report into a QMT daily factor backtest script. QMT is a Chinese trading-platform environment, and a backtest simulates how a strategy would have traded using historical data.

In plain words
What is it for?
Reproducing research factors, selecting stocks with cross-sectional rankings, applying industry or market-cap adjustments, and testing fixed-size equal-weight portfolios in QMT.
Why use it?
It provides a fixed structure for calculating factors and signals before executing scheduled portfolio changes, reducing the work of assembling a complete script.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/dfkai/xtquantai/qmt-inner-backtest
Any agent
npx skills add dfkai/xtquantai --skill qmt-inner-backtest
Clone the repo
git clone --depth 1 https://github.com/dfkai/xtquantai

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for qmt-inner-backtest

README.md
[![agentmods](https://agentmods.dev/badge/skills/dfkai/xtquantai/qmt-inner-backtest.svg)](https://agentmods.dev/skills/dfkai/xtquantai/qmt-inner-backtest)
Your own site
<a href="https://agentmods.dev/skills/dfkai/xtquantai/qmt-inner-backtest"><img src="https://agentmods.dev/badge/skills/dfkai/xtquantai/qmt-inner-backtest.svg" alt="Measured on agentmods" height="20"></a>
Per session 96 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,719 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00096 $0.03719
Opus 5 $0.00048 $0.01860
Sonnet 5 $0.00019 $0.00744
Haiku 4.5 $0.00010 $0.00372

Measured 4d ago against content hash 1e6059072ae4, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

qmt-inner-backtest scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/daily-factors-backtest.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/qmt-inner-backtest/SKILL.md · 278 lines

How it starts

The opening of the file, as written. The whole thing — 278 lines — stays where its author put it; the contents beside it link to each section on GitHub.

QMT 内置因子回测

概述

基于 scripts/daily-factors-backtest.py 生成 QMT 策略编辑器内置回测 脚本。

核心模式:after_init 预计算全区间因子与买卖信号 → handlebar 按调仓日执行交易

母版路径:本 skill 目录下的 scripts/daily-factors-backtest.py(相对 SKILL.md 所在目录)

适用场景

适合 不适合
日频截面因子选股(Barra 风格处理) Tick/分钟高频
固定持仓数 Top-N 等权调仓 期货开平仓(qmt-future-trade,规划中)
研报因子复现、上下影线/价值/动量等 目标持仓型期货实盘(qmt-live-strategy-template,规划中)
申万行业 + 市值中性化 仅要信号推送(qmt-live-signal-feishu,规划中)

母版架构(必须理解再改)

daily-factors-backtest.py
├── 文件头 # coding:gbk + 策略说明 docstring
├── 因子函数库          ← 【主要替换区】factor_xxx + 中性化/去极值
├── init(C)             ← 【配置区】回测区间、股票池、资金、因子参数
├── after_init(C)       ← 【信号区】拉数据 → 算因子 → 过滤 → 生成 g.buy/sell_signals
├── handlebar(C)        ← 【执行区】调仓日卖出/买入(通常保留)
├── 交易执行函数         ← 通常原样保留
└── 辅助工具函数         ← 通常原样保留(IPO/ST/涨跌停/财务宽表)

各段职责

函数/变量 做什么
全局状态 g = G() 跨函数共享参数、信号矩阵、持仓
因子库 factor_ubl(...) 输入 OHLCV/市值等宽表,输出因子 DataFrame(index=日期, columns=股票)
因子后处理 filter_extreme_mad_df / neutralize_by_market_cap / neutralize_by_industry_zscore / cross_section_zscore Barra 风格流水线,按研报需求保留或删减
初始化 init(C) g.start_date/g.end_dateg.stock_poolg.max_positionsg.rebalance_days 等;预定义 g.buy_signals/g.sell_signals 防空矩阵
预计算 after_init(C) 一次性拉全区间行情+财务 → 算因子 → IPO/ST/停牌过滤 → 截面排名 → shift(1) 生成 T+1 信号
执行 handlebar(C) g.rebalance_days 个交易日调仓:先卖后买,开盘价成交
交易 execute_sell/buy_signals 涨停不买、跌停不卖;科创板 200 股、其余 100 股整数倍
辅助 get_ipo_mask / get_st_mask / get_financial_wide_table 上市满 120 天、ST 区间、财务字段宽表

信号时序(防未来函数)

df_rank = df_factor_filtered.rank(axis=1, ascending=g.rank_ascending)
df_is_top_n = df_rank <= g.max_positions
g.buy_signals = df_is_top_n.shift(1).fillna(False)   # T 日因子 → T+1 日买入
g.sell_signals = ~g.buy_signals

禁止去掉 .shift(1),除非用户明确要求当日收盘调仓且接受前视偏差。

Agent 工作流

1. 解读策略输入

用户可能提供:文字描述、研报 PDF、截图、已有因子公式。提取并输出 策略规格表(生成前给用户确认):

Read the full file on GitHub · 278 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 278 lines · 96 tokens per session scan A 1e6059072ae4

Subscribe to this mod's changes

qmt-inner-backtest is a skill published in the GitHub repository dfkai/xtquantai (161 stars, last pushed 2mo ago), licensed MIT. It adds 96 tokens to every session and 3,719 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

skillshare-changelog

Generate CHANGELOG.md entry from recent commits in conventional format. Also syncs the website changelog page. Use this skill whenever the user asks to: generate a changelog, document what changed between tags, or create a new CHANGELOG entry. If you see requests like "write the changelog for v0.17", "what changed…

runkids/skillshare · 134 tokens

skillshare-update-docs

Update website docs to match recent code changes, cross-validating every flag against source. Use this skill whenever the user asks to: update documentation, sync docs with code, document a new flag or command, fix stale docs, or update the README. This skill covers all website/docs/ categories (commands, reference…

runkids/skillshare · 123 tokens

weekly-crm-report

Cleans a weekly CRM export and produces a regional sales summary. Activates when the user asks to clean a CRM export, deduplicate sales rows, calculate regional totals, or generate a weekly sales report from a CSV.

FrancyJGLisboa/agent-skill-creator · 49 tokens

cloudbase-document-database-in-wechat-miniprogram

Use CloudBase document database WeChat MiniProgram SDK to query, create, update, and delete data. Supports complex queries, pagination, aggregation, and geolocation queries.

TencentCloudBase/CloudBase-AI-Toolkit · 46 tokens

ulw-research

Team-first maximum-saturation research orchestration. ALWAYS asks which final format to render (PDF+DOCX default), then stands up a max-size cooperating team (teamcreate): one member per axis plus skeptic/red-team members for ultradebate/hyperdebate cross-critique, explore/librarian lanes, live journaling, an EXPAND…

code-yeongyu/oh-my-openagent · 224 tokens

dashscope

DashScope (Alibaba Cloud Bailian / 阿里云百炼) integration — image generation (qwen-image-2.0-pro), text-to-speech (qwen3-tts-flash), and ASR with word-level timestamps (qwen3-asr-flash-filetrans). Use when generating images via Qwen-Image, narrating via Qwen-TTS, or transcribing with word-level timestamps via Qwen-ASR.

calesthio/OpenMontage · 93 tokens