Akshare Backtest

v1.0.3

A股量化策略回测工具。基于 AkShare 获取历史行情数据,模拟执行强势股轮动策略。 支持自定义初始资金、回测周期、止盈止损参数。输出收益曲线、买卖记录、月度统计。 适用于验证"涨停基因+均线多头+量价配合"等短线策略的历史表现。

0· 317·1 current·1 all-time
byGingin@gracexiaoo·duplicate of @gracexiaoo/backtest

Install

OpenClaw Prompt Flow

Install with OpenClaw

Best for remote or guided setup. Copy the exact prompt, then paste it into OpenClaw for gracexiaoo/akshare-backtest.

Previewing Install & Setup.
Prompt PreviewInstall & Setup
Install the skill "Akshare Backtest" (gracexiaoo/akshare-backtest) from ClawHub.
Skill page: https://clawhub.ai/gracexiaoo/akshare-backtest
Keep the work scoped to this skill only.
After install, inspect the skill metadata and help me finish setup.
Use only the metadata you can verify from ClawHub; do not invent missing requirements.
Ask before making any broader environment changes.

Command Line

CLI Commands

Use the direct CLI path if you want to install manually and keep every step visible.

OpenClaw CLI

Bare skill slug

openclaw skills install akshare-backtest

ClawHub CLI

Package manager switcher

npx clawhub@latest install akshare-backtest
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
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.
Assessment
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.

Like a lobster shell, security has layers — review code before you run it.

latestvk979h3tadkksvw1avntcffmjk5841x1z
317downloads
0stars
1versions
Updated 3w ago
v1.0.3
MIT-0

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交易日/年)
  • 最大回撤:从峰值到谷底的最大跌幅
  • 胜率:盈利交易 / 总卖出次数

风险提示

  1. 历史不代表未来:回测结果仅供参考,不构成投资建议
  2. 滑点成本:实际交易会有滑点,回测可能偏乐观
  3. 流动性风险:小盘股可能无法按回测价格买入
  4. 手续费:未计入佣金和印花税(建议手动扣除)

扩展方向

  • 接入实时行情实现模拟交易
  • 添加大盘择时(沪深300均线过滤)
  • 多策略组合轮动
  • 优化止盈止损参数
  • 接入实盘券商API

Comments

Loading comments...