← Back to Skills Marketplace
299
Downloads
0
Stars
0
Active Installs
3
Versions
Install in OpenClaw
/install backtest
Description
A股量化策略回测工具。基于 AkShare 获取历史行情数据,模拟执行强势股轮动策略。 支持自定义初始资金、回测周期、止盈止损参数。输出收益曲线、买卖记录、月度统计。 适用于验证"涨停基因+均线多头+量价配合"等短线策略的历史表现。
README (SKILL.md)
A股量化策略回测 (AkShare Backtest)
基于 AkShare 免费行情数据,实现 A股量化策略的历史回测。
策略说明
默认策略:强势股轮动
| 条件 | 说明 |
|---|---|
| 涨停基因 | 近5日有涨停,或单日涨幅>7% |
| 均线多头 | 5日均线>10日均线>20日均线 |
| 量价配合 | 今日成交量 > 5日均量 × 1.2 |
买卖规则
| 触发条件 | 操作 |
|---|---|
| +5% | 卖出 1/3 |
| +8% | 再卖出 1/3(剩余1/3继续持有) |
| +10%以上 | 尾盘不涨停则全部清仓 |
| -3% | 无条件止损 |
| 持仓满3天 | 第3天尾盘强制平仓 |
仓位管理
- 初始资金:默认 5 万(可配置)
- 单票仓位:20%-35%
- 同时持仓:最多 3 只
- 每日保留 30% 现金
安装依赖
pip install akshare pandas numpy
使用方法
命令行调用
python {baseDir}/scripts/backtest.py --capital 50000 --start 20240101 --end 20240630
参数说明
| 参数 | 说明 | 默认值 |
|---|---|---|
--capital |
初始资金(元) | 50000 |
--start |
开始日期(YYYYMMDD) | 20240101 |
--end |
结束日期(YYYYMMDD) | 当前日期 |
--output |
输出目录 | miaoxiang/backtest |
--query |
自然语言参数 | 暂不支持 |
示例
# 回测2024年全年
python scripts/backtest.py --capital 100000 --start 20240101 --end 20241231
# 回测2024下半年
python scripts/backtest.py --start 20240701 --end 20241231
输出文件
| 文件 | 说明 |
|---|---|
daily_values.csv |
每日净值曲线(日期、现金、持仓市值、总净值、收益率) |
trades.csv |
全部买卖记录(日期、股票、买卖价、数量、收益率、原因) |
结果解读
回测脚本会输出:
========== 回测结果 ==========
初始资金: 50,000
最终净值: 58,234
总收益率: +16.47%
年化收益率: +32.18%
最大回撤: -12.35%
交易次数: 45
卖出次数: 42
胜率: 58.5%
==============================
关键指标
- 总收益率:回测期间累计收益
- 年化收益率:折算为年化收益(按250交易日/年)
- 最大回撤:从峰值到谷底的最大跌幅
- 胜率:盈利交易 / 总卖出次数
风险提示
- 历史不代表未来:回测结果仅供参考,不构成投资建议
- 滑点成本:实际交易会有滑点,回测可能偏乐观
- 流动性风险:小盘股可能无法按回测价格买入
- 手续费:未计入佣金和印花税(建议手动扣除)
扩展方向
- 接入实时行情实现模拟交易
- 添加大盘择时(沪深300均线过滤)
- 多策略组合轮动
- 优化止盈止损参数
- 接入实盘券商API
Usage Guidance
This skill appears coherent and implements the stated backtest. Before installing: (1) run it in a virtual environment or sandbox to isolate dependencies; (2) pin package versions (e.g., akshare) to avoid unexpected upstream changes; (3) be aware AkShare performs network calls to fetch market data—ensure this is acceptable for your environment and network policy; (4) review and adapt hard-coded assumptions (symbol lists, position sizing) before using results for real trading; (5) treat backtest outputs as informational only—they are not financial advice.
Capability Assessment
Purpose & Capability
The name/description (A股回测 using AkShare) aligns with the contents: a Python script implementing a backtest and the declared pip dependencies (akshare, pandas, numpy). There are no unrelated environment variables, binaries, or config paths requested.
Instruction Scope
SKILL.md only instructs installing the listed Python packages and running scripts/backtest.py with standard CLI args. The instructions and script operate on market data and write CSV outputs to a local output directory; they do not request or read secrets, system configuration, or unrelated files.
Install Mechanism
Install spec is a simple pip install of well-known Python packages (akshare, pandas, numpy). This is a low-risk, standard mechanism. Note: AkShare itself fetches market data over the network (expected for the use case).
Credentials
No environment variables, credentials, or config paths are required. The script does not attempt to access secrets. It does require internet access to fetch market data via AkShare, which is proportionate to its purpose.
Persistence & Privilege
The skill is not forced-always, does not request elevated/persistent privileges, and does not modify other skills or global agent config.
How to Use
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install backtest - After installation, invoke the skill by name or use
/backtest - Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.2
- No user-visible changes in this version.
- No updates to code or documentation detected.
v1.0.1
No user-visible changes in this version.
- Version updated to 1.0.1 with no modifications to code or documentation files detected.
v1.0.0
AkShare A股量化策略回测工具首次发布。
- 支持基于AkShare获取A股历史行情数据,进行强势股轮动策略回测
- 提供自定义初始资金、回测周期、止盈止损等参数
- 输出收益曲线、买卖记录、月度统计等核心回测结果
- 默认实现"涨停基因+均线多头+量价配合"的短线策略
- 详细支持仓位管理、交易规则设定,并输出关键绩效指标
- 提供命令行运行方式及详细参数说明
Metadata
Frequently Asked Questions
What is Akshare Backtest?
A股量化策略回测工具。基于 AkShare 获取历史行情数据,模拟执行强势股轮动策略。 支持自定义初始资金、回测周期、止盈止损参数。输出收益曲线、买卖记录、月度统计。 适用于验证"涨停基因+均线多头+量价配合"等短线策略的历史表现。 It is an AI Agent Skill for Claude Code / OpenClaw, with 299 downloads so far.
How do I install Akshare Backtest?
Run "/install backtest" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Akshare Backtest free?
Yes, Akshare Backtest is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Akshare Backtest support?
Akshare Backtest is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Akshare Backtest?
It is built and maintained by Gingin (@gracexiaoo); the current version is v1.0.2.
More Skills