← 返回 Skills 市场
326
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install akshare-backtest
功能描述
A股量化策略回测工具。基于 AkShare 获取历史行情数据,模拟执行强势股轮动策略。 支持自定义初始资金、回测周期、止盈止损参数。输出收益曲线、买卖记录、月度统计。 适用于验证"涨停基因+均线多头+量价配合"等短线策略的历史表现。
使用说明 (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
安全使用建议
This is a straightforward backtest script; before installing/running, consider: 1) Review the script (scripts/backtest.py) yourself — it writes CSV files and fetches data via AkShare. 2) Run in an isolated environment (virtualenv or container) because pip will install third‑party packages. 3) AkShare will make network requests to public market-data endpoints — if you need offline/no-network execution, do not run it. 4) Note minor discrepancies between SKILL.md and the code (max positions and stop-loss values); confirm the script's parameters match your expectations before trusting results. 5) If you plan to connect any real brokerage or live-trading API later, audit that integration separately; this package does not request or store credentials itself.
功能分析
Type: OpenClaw Skill
Name: akshare-backtest
Version: 1.0.3
The skill bundle is a legitimate quantitative backtesting tool for the A-share market. The Python script (scripts/backtest.py) uses the well-known AkShare library to fetch historical market data and implements standard financial logic for strategy evaluation, including position management and performance metrics. There are no indicators of data exfiltration, malicious execution, or prompt injection; all operations are consistent with the stated purpose of simulating stock trading strategies.
能力评估
Purpose & Capability
Name/description describe an A-share backtest and the code + declared pip deps (akshare, pandas, numpy) match that purpose. The dependencies are expected for this task.
Instruction Scope
SKILL.md instructs running scripts/backtest.py with CLI args and describes outputs. The runtime instructions and code are mostly aligned, but there are small mismatches between the README and code (SKILL.md claims '最多 3 只' positions and -3% stop-loss, while the script sets max_positions=2 and stop_loss=-5%). The script creates an output directory and writes CSVs; it also calls AkShare to fetch remote market data (network access). No instructions or code attempt to read unrelated system files or environment variables.
Install Mechanism
Install uses pip packages (akshare, pandas, numpy) — a standard and expected install mechanism. This requires network access to PyPI and will install third-party packages; akshare itself will fetch market data from remote sources. No downloads from untrusted URLs or archive/extract steps are present.
Credentials
The skill requests no environment variables, no credentials, and no config paths. That is proportionate for a historical backtest that pulls public market data.
Persistence & Privilege
The skill is not always-enabled and does not request elevated or persistent platform privileges. It writes outputs to its own output directory only and does not modify other skills or global agent settings.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install akshare-backtest - 安装完成后,直接呼叫该 Skill 的名称或使用
/akshare-backtest触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.3
- 增加详细使用说明与策略介绍,方便用户理解回测流程与买卖规则。
- 明确输出文件格式,新增 daily_values.csv 和 trades.csv 说明。
- 提供完整的命令行调用示例和可配置参数说明。
- 补充风险提示及结果解读,帮助用户正确理解回测数据。
- 列出依赖安装步骤及未来扩展方向。
元数据
常见问题
Akshare Backtest 是什么?
A股量化策略回测工具。基于 AkShare 获取历史行情数据,模拟执行强势股轮动策略。 支持自定义初始资金、回测周期、止盈止损参数。输出收益曲线、买卖记录、月度统计。 适用于验证"涨停基因+均线多头+量价配合"等短线策略的历史表现。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 326 次。
如何安装 Akshare Backtest?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install akshare-backtest」即可一键安装,无需额外配置。
Akshare Backtest 是免费的吗?
是的,Akshare Backtest 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
Akshare Backtest 支持哪些平台?
Akshare Backtest 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Akshare Backtest?
由 Gingin(@gracexiaoo)开发并维护,当前版本 v1.0.3。
推荐 Skills