backtesting-frameworks
它能做什么
这个工具可以帮你搭建投资策略的测试系统。它会避免一些常见错误,确保测试公平,不会让策略看起来比实际表现更好。
适用场景
- ✓为你的投资想法编写测试时。
- ✓搭建策略测试的基础设施时。
- ✓验证某个投资策略是否真的表现良好时。
技能链接
https://github.com/wshobson/agents/blob/main/plugins/quantitative-trading/skills/backtesting-frameworks/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我想测试自己的股票交易策略,并确保测试结果是可靠的。”
每周 5 个新技能,1 分钟读完。
工作原理
它会智能地使用历史数据,把数据分成用于训练和用于测试的部分。这样可以避免策略“偷看未来”,也能防止因数据不完整而导致测试结果产生误导。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Backtesting Frameworks
Build robust, production-grade backtesting systems that avoid common pitfalls and produce reliable strategy performance estimates.
When to Use This Skill
- Developing trading strategy backtests
- Building backtesting infrastructure
- Validating strategy performance
- Avoiding common backtesting biases
- Implementing walk-forward analysis
- Comparing strategy alternatives
Core Concepts
1. Backtesting Biases
| Bias | Description | Mitigation |
|---|---|---|
| Look-ahead | Using future information | Point-in-time data |
| Survivorship | Only testing on survivors | Use delisted securities |
| Overfitting | Curve-fitting to history | Out-of-sample testing |
| Selection | Cherry-picking strategies | Pre-registration |
| Transaction | Ignoring trading costs | Realistic cost models |
2. Proper Backtest Structure
Historical Data
│
▼
┌─────────────────────────────────────────┐
│ Training Set │
│ (Strategy Development & Optimization) │
└─────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ Validation Set │
│ (Parameter Selection, No Peeking) │
└─────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ Test Set │
│ (Final Performance Evaluation) │
└─────────────────────────────────────────┘
3. Walk-Forward Analysis
Window 1: [Train──────][Test]
Window 2: [Train──────][Test]
Window 3: [Train──────][Test]
Window 4: [Train──────][Test]
─────▶ Time
Detailed worked examples and patterns
Detailed sections (starting with ## Implementation Patterns) live in references/details.md. Read that file when the navigation summary above is insufficient.
Best Practices
Do's
- Use point-in-time data - Avoid look-ahead bias
- Include transaction costs - Realistic estimates
- Test out-of-sample - Always reserve data
- Use walk-forward - Not just train/test
- Monte Carlo analysis - Understand uncertainty
Don'ts
- Don't overfit - Limit parameters
- Don't ignore survivorship - Include delisted
- Don't use adjusted data carelessly - Understand adjustments
- Don't optimize on full history - Reserve test set
- Don't ignore capacity - Market impact matters
常见问题
什么是“前视偏差”(look-ahead bias)?
指测试中使用了只有事后才能获得的信息,使策略看起来比现实中更赚钱。
什么是“幸存者偏差”(survivorship bias)?
指测试只考虑了“幸存”下来的投资标的(没有失败或被退市的),忽略了那些失败的标的,从而让结果产生偏差。
什么是“交易成本”?
指买入和卖出资产时产生的实际费用,比如手续费和税费。测试中需要把这些成本计算进去,结果才会更贴近现实。
详情
作者的原始描述
Build robust backtesting systems for trading strategies with proper handling of look-ahead bias, survivorship bias, and transaction costs. Use when developing trading algorithms, validating strategies, or building backtesting infrastructure.
repo: wshobson/agents
热度
- GitHub 星标
- 41k
- 排名
- #6771
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …