Install any skill in seconds. Free to start, no credit card required.
Get Started Free →A股量化策略回测/因子验证。当用户说"回测"、"策略回测"、"backtest"、"因子验证"、"这个策略历史表现怎么样"、"测一下"、"量化回测"、"历史收益率"、"夏普比率"、"最大回撤"时触发。基于历史K线和财务数据,对用户指定的投资策略进行回测验证,计算收益率/夏普比率/最大回撤/胜率等绩效指标。支持研报风格(formal)和快速结果风格(brief)。
.claude/skills/aifinlab-a-share-quant-backtest/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-14 | ✗→✓ | ▲ Improved | 29% | 0% |
| case-15 | ✗→✓ | ▲ Improved | 98% | 0% |
| case-20 | ✗→✓ | ▲ Improved | 34% | 0% |
| case-05 | ✓→✗ | ▼ Worse | -54% | 0% |
| case-22 | ✓→✗ | ▼ Worse | -29% | 0% |
bashSCRIPTS="$SKILLS_ROOT/cn-stock-data/scripts" # 历史K线(日/周/月) python "$SCRIPTS/cn_stock_data.py" kline --code [CODE] --period [daily/weekly/monthly] --start [YYYYMMDD] --end [YYYYMMDD] # 个股财务指标(用于因子验证) python "$SCRIPTS/cn_stock_data.py" finance --code [CODE] # 实时行情(辅助) python "$SCRIPTS/cn_stock_data.py" quote --code [逗号分隔的代码列表]
回测计算使用 Python pandas,不依赖第三方回测框架。所有计算在 Python 脚本中完成。
明确以下要素(用户未指定则使用默认值):
| 要素 | 说明 | 默认值 | |------|------|--------| | 标的池 | 回测股票范围 | 用户指定(必填) | | 买入规则 | 入场信号 | 用户指定(必填) | | 卖出规则 | 出场信号 | 用户指定(必填) | | 持仓周期 | 最小持仓天数 | 不限(T+1 至少隔日) | | 调仓频率 | 多久重新评估 | 月度调仓 | | 仓位管理 | 单只上限/总仓位 | 等权重,单只不超过 20% | | 回测区间 | 起止日期 | 近 3 年 | | 基准 | 对标指数 | 沪深300 (000300) | | 初始资金 | 起始金额 | 100 万元 | | 交易成本 | 佣金+印花税+滑点 | 佣金万2.5 + 印花税千1(卖出) + 滑点0.1% |
常见策略模板:
pythonimport pandas as pd # 示例:加载K线数据后的基本处理 df['return'] = df['close'].pct_change() df['cum_return'] = (1 + df['return']).cumprod() - 1
按规则模拟交易,逐日/逐期计算:
python# A股特殊处理 # T+1: 当日买入次日才能卖出 # 涨跌停: 涨停无法买入,跌停无法卖出 # 停牌: 停牌期间无法交易 # 手续费: 佣金(双向) + 印花税(卖出千1) + 滑点
计算以下核心指标(详见 references/backtest-guide.md):
| 指标 | 公式/说明 | |------|----------| | 总收益率 | (期末净值 - 1) 100% | | 年化收益率 | (期末净值)^(252/交易天数) - 1 | | 夏普比率 | (年化收益 - 无风险利率) / 年化波动率 | | 最大回撤 | max(1 - 净值/历史最高净值) | | 胜率 | 盈利交易次数 / 总交易次数 | | 盈亏比 | 平均盈利 / 平均亏损 | | Calmar 比率 | 年化收益 / 最大回撤 | | Sortino 比率 | (年化收益 - 无风险利率) / 下行波动率 | | 年化波动率 | 日收益标准差 sqrt(252) | | 交易次数 | 总买卖次数 | | 平均持仓天数 | 所有交易的平均持仓时长 |
必须与基准对比:同期基准的收益率、最大回撤、夏普比率,计算超额收益。
根据风格要求输出,必须包含:
| 维度 | formal(研报风格) | brief(快速结果) | |------|-------------------|--------------------| | 篇幅 | 3-5 页 | 1 页 | | 策略说明 | 详述策略逻辑、参数选择理由 | 一句话策略概述 | | 绩效表 | 完整(10+ 指标) | 精简(5-6 核心指标) | | 分年度 | 逐年收益表 + 月度热力图描述 | 仅逐年收益 | | 交易明细 | 列出部分典型交易 | 不列出 | | 风险分析 | 详细回撤分析 + 参数敏感性 | 仅标注最大回撤 | | 免责声明 | 需要(历史不代表未来) | 简短提示 |
| 指标 | 策略 | 基准(沪深300) | 超额 | |------|------|-------------|------| | 年化收益率 | xx% | xx% | xx% | | 夏普比率 | x.xx | x.xx | — | | 最大回撤 | xx% | xx% | — | | 胜率 | xx% | — | — | | 盈亏比 | x.xx | — | — | | Calmar 比率 | x.xx | x.xx | — | | 年化波动率 | xx% | xx% | — | | 交易次数 | N 次 | — | — |
| 年份 | 策略收益 | 基准收益 | 超额收益 | |------|---------|---------|---------|
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-14 | fail→pass | 11,118 | 4,363 | -61% | 1 | 1 | 0% | 2,206 | 2,839 | +29% | 0 | 0 | — |
case-01 | fail→fail | 23,435 | 12,267 | -48% | 1 | 1 | 0% | 3,998 | 2,807 | -30% | 0 | 0 | — |
case-02 | fail→fail | 25,920 | 7,895 | -70% | 1 | 1 | 0% | 3,721 | 2,423 | -35% | 0 | 0 | — |
case-03 | fail→fail | 29,241 | 12,420 | -58% | 1 | 1 | 0% | 5,125 | 2,852 | -44% | 0 | 0 | — |
case-04 | fail→fail | 22,128 | 9,744 | -56% | 1 | 1 | 0% | 3,648 | 2,502 | -31% | 0 | 0 | — |
case-05 | pass→fail | 35,998 | 15,768 | -56% | 1 | 1 | 0% | 6,343 | 2,899 | -54% | 0 | 0 | — |
case-06 | pass→pass | 34,509 | 26,452 | -23% | 1 | 1 | 0% | 5,404 | 6,144 | +14% | 0 | 0 | — |
case-07 | fail→fail | 26,858 | 9,862 | -63% | 1 | 1 | 0% | 4,895 | 2,526 | -48% | 0 | 0 | — |
case-08 | fail→fail | 21,761 | 15,559 | -29% | 1 | 1 | 0% | 3,776 | 2,796 | -26% | 0 | 0 | — |
case-09 | fail→fail | 15,783 | 13,015 | -18% | 1 | 1 | 0% | 2,518 | 2,802 | +11% | 0 | 0 | — |
case-10 | pass→pass | 20,376 | 30,145 | +48% | 1 | 1 | 0% | 3,225 | 5,816 | +80% | 0 | 0 | — |
case-11 | fail→fail | 23,336 | 18,222 | -22% | 1 | 1 | 0% | 3,247 | 3,118 | -4% | 0 | 0 | — |
case-12 | fail→fail | 23,521 | 10,965 | -53% | 1 | 1 | 0% | 3,143 | 2,573 | -18% | 0 | 0 | — |
case-13 | fail→fail | 11,063 | 12,535 | +13% | 1 | 1 | 0% | 1,954 | 2,935 | +50% | 0 | 0 | — |
case-22 | pass→fail | 16,078 | 8,834 | -45% | 1 | 1 | 0% | 3,277 | 2,333 | -29% | 0 | 0 | — |
case-15 | fail→pass | 31,086 | 5,805 | -81% | 1 | 1 | 0% | 1,494 | 2,962 | +98% | 0 | 0 | — |
case-16 | fail→fail | 28,177 | 10,182 | -64% | 1 | 1 | 0% | 5,390 | 2,579 | -52% | 0 | 0 | — |
case-17 | pass→fail | 18,482 | 11,189 | -39% | 1 | 1 | 0% | 3,109 | 2,818 | -9% | 0 | 0 | — |
case-18 | fail→fail | 18,299 | 10,762 | -41% | 1 | 1 | 0% | 3,210 | 2,643 | -18% | 0 | 0 | — |
case-19 | pass→fail | 19,804 | 10,501 | -47% | 1 | 1 | 0% | 3,441 | 2,260 | -34% | 0 | 0 | — |
case-20 | fail→pass | 39,902 | 36,630 | -8% | 1 | 1 | 0% | 6,554 | 8,771 | +34% | 0 | 0 | — |
case-21 | fail→fail | 34,004 | 10,263 | -70% | 1 | 1 | 0% | 5,581 | 2,578 | -54% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 4 counted toward the lift figure. The other 18 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of -5 percentage points is the difference between those two pass rates over the 4 comparable cases. 10 cases got worse with the skill loaded, and they are included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
| Model | Method | Date | Lift |
|---|---|---|---|
| gemini-3.6-flash | verified | 8/28/2026 | +13% |
Other measured skills in the registry, with their headline benchmark lift.