Akshare Backtest

v1.0.2

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

0· 289·0 current·0 all-time
byGingin@gracexiaoo

Install

OpenClaw Prompt Flow

Install with OpenClaw

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

Previewing Install & Setup.
Prompt PreviewInstall & Setup
Install the skill "Akshare Backtest" (gracexiaoo/backtest) from ClawHub.
Skill page: https://clawhub.ai/gracexiaoo/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 backtest

ClawHub CLI

Package manager switcher

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

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

latestvk974qgmw14cy9e0sn4gtw48ked8401sknewvk974qgmw14cy9e0sn4gtw48ked8401skstablevk974qgmw14cy9e0sn4gtw48ked8401skxiaojinvk974qgmw14cy9e0sn4gtw48ked8401sk
289downloads
0stars
3versions
Updated 3w ago
v1.0.2
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...