← 返回 Skills 市场
lamtest556-blip

AKQuant A-Share Backtesting

作者 lamtest556-blip · GitHub ↗ · v1.0.1 · MIT-0
cross-platform ✓ 安全检测通过
219
总下载
0
收藏
1
当前安装
2
版本数
在 OpenClaw 中安装
/install akquant-backtest
功能描述
A-share quantitative trading backtesting using AKQuant (Rust engine) and AKShare data. Use when user asks to "backtest a stock strategy", "test trading algor...
使用说明 (SKILL.md)

AKQuant A-Share Backtesting

High-performance quantitative backtesting for Chinese stocks using Rust-powered AKQuant framework.

When to Use This Skill

Use this skill when you need to:

  • Backtest trading strategies - "Backtest double MA strategy on 平安银行"
  • Analyze stock performance - "How would a momentum strategy perform on 茅台?"
  • Optimize trading parameters - "Find best MA periods for 宁德时代"
  • Validate trading ideas - "Test if RSI works on Chinese tech stocks"
  • Compare strategies - "Which performs better: MA crossover or RSI?"

Quick Examples

Example 1: Quick Backtest

User says: "Backtest double MA strategy on 贵州茅台"

Actions:

python3 scripts/run_backtest.py 600519 10 30

Result: Returns total return, trade count, equity curve

Example 2: Strategy Comparison

User says: "Compare 5-day vs 20-day MA on 平安银行"

Actions:

# Fast MA = 5, Slow MA = 20
python3 scripts/run_backtest.py 000001 5 20

# Compare with default 10/30
python3 scripts/run_backtest.py 000001 10 30

Result: Compare returns to find optimal parameters

Example 3: Research Workflow

User says: "Analyze which tech stocks performed best with momentum strategy in 2024"

Actions:

  1. Test on multiple stocks: python3 scripts/run_backtest.py 300750 10 30 (宁德时代)
  2. Test: python3 scripts/run_backtest.py 002594 10 30 (比亚迪)
  3. Compare results and identify patterns

Step-by-Step Instructions

Step 1: Choose Stock Symbol

Common A-Share Symbols:

Symbol Company Sector
600519 贵州茅台 消费
000001 平安银行 金融
300750 宁德时代 新能源
002594 比亚迪 汽车
000858 五粮液 消费

Find symbol: Use AKShare or search "股票代码 + 公司名称"

Step 2: Select Strategy Parameters

Double MA Strategy (金叉买入,死叉卖出):

python3 scripts/run_backtest.py \x3Csymbol> \x3Cfast_period> \x3Cslow_period>

Recommended combinations:

  • Conservative: 20 / 60 (fewer trades, longer trends)
  • Balanced: 10 / 30 (moderate frequency)
  • Aggressive: 5 / 20 (more trades, shorter trends)

Step 3: Analyze Results

Key metrics to review:

  • 总收益率 - Overall strategy performance
  • 交易次数 - Frequency (lower = less commission)
  • 最大回撤 - Risk measure (if implemented)
  • 胜率 - % of profitable trades

Interpretation:

Return > 0%    → Strategy beats buy-and-hold
Return \x3C 0%    → Strategy underperforms
Trade count > 20 → Consider commission impact

Available Strategies

Built-in Strategy: Double MA

Logic: Fast MA crosses above slow MA → Buy; Crosses below → Sell

Code example:

from double_ma_strategy import run_double_ma_backtest

result = run_double_ma_backtest(
    symbol="000001",
    fast_period=10,
    slow_period=30,
    initial_capital=100000,
    start_date="20240101",
    end_date="20241231"
)

print(f"Return: {result['return_pct']:.2f}%")
print(f"Trades: {len(result['trades'])}")

Custom Strategy Development

RSI Strategy Template:

import akquant as aq

class RsiStrategy:
    def __init__(self, period=14, oversold=30, overbought=70):
        self.rsi = aq.RSI(period)
        self.oversold = oversold
        self.overbought = overbought
        
    def on_bar(self, bar):
        self.rsi.update(bar['close'])
        
        if self.rsi.value \x3C self.oversold:
            return 'BUY'  # 超卖买入
        elif self.rsi.value > self.overbought:
            return 'SELL'  # 超买卖出
        return 'HOLD'

Technical Indicators Reference

Indicator Usage Signal
aq.SMA(n) Trend following Price > SMA → uptrend
aq.EMA(n) Faster trend More responsive than SMA
aq.RSI(n) Momentum \x3C30 oversold, >70 overbought
aq.MACD() Trend + momentum Crossover signals
aq.BollingerBands(n, k) Volatility Price touches bands
aq.ATR(n) Risk sizing Position sizing based on volatility

Example:

import akquant as aq

# Multi-indicator strategy
sma = aq.SMA(20)
rsi = aq.RSI(14)

for price in prices:
    sma.update(price)
    rsi.update(price)
    
    # Buy: Price > SMA AND RSI \x3C 40 (uptrend but not overbought)
    if price > sma.value and rsi.value \x3C 40:
        signal = 'BUY'

Data Access via AKShare

Stock Historical Data

import akshare as ak

# Daily price data (qfq = 前复权)
df = ak.stock_zh_a_hist(
    symbol="000001",
    period="daily",
    start_date="20240101",
    end_date="20241231",
    adjust="qfq"
)

# Columns: 日期, 开盘, 收盘, 最高, 最低, 成交量

Real-time Quote

# Current prices
df = ak.stock_zh_a_spot_em()

Troubleshooting

Error: "ModuleNotFoundError: No module named 'akquant'"

Cause: Dependencies not installed Solution:

source /root/.openclaw/venv/bin/activate
pip install akquant akshare pandas numpy

Error: "Stock symbol not found"

Cause: Wrong symbol format Solution:

  • A-shares use 6-digit codes: 000001 (SZ), 600519 (SH), 300750 (创业板)
  • Don't include exchange prefix (use 000001 not SZ000001)

Error: "No data returned"

Causes:

  1. Invalid date range - Check start_date \x3C end_date
  2. Stock suspended - Some stocks have trading halts
  3. Delisted stock - Verify stock is still trading
  4. Network issue - AKShare requires internet connection

Strategy returns -100% (total loss)

Causes:

  1. Wrong parameter order - fast_period should be \x3C slow_period
    # Wrong: fast > slow
    python3 scripts/run_backtest.py 000001 30 10
    
    # Correct: fast \x3C slow
    python3 scripts/run_backtest.py 000001 10 30
    
  2. Too many trades - High commission costs
  3. Wrong signal logic - Check buy/sell conditions

Slow performance

Solutions:

  • Reduce date range (test 3 months instead of 1 year)
  • Use fast_period >= 5 to reduce calculation
  • AKQuant is Rust-based and fast; slowness usually comes from data fetching

Results inconsistent between runs

Cause: AKShare data updates (recent days) Solution:

  • Use fixed date ranges for reproducibility
  • Cache data locally if needed

Best Practices

Strategy Development Workflow

  1. Start simple - Test MA crossover before complex strategies
  2. Visualize - Plot equity curve if possible
  3. Walk-forward test - Train on 2023, test on 2024
  4. Transaction costs - Include 0.1% commission + 0.1% slippage
  5. Risk management - Add stop-loss logic

Parameter Optimization

# Test multiple combinations
for fast in 5 10 15; do
  for slow in 20 30 60; do
    echo "Testing $fast/$slow:"
    python3 scripts/run_backtest.py 000001 $fast $slow
  done
done

Avoid Overfitting

  • Don't optimize too many parameters
  • Test on out-of-sample data
  • Simple strategies often outperform complex ones

Limitations & Warnings

  • Data delay: AKShare has 15-minute delay - for backtesting only, not live trading
  • Historical bias: Past performance ≠ future results
  • Execution: Real-world fills may differ from backtest assumptions
  • Survivorship: Delisted stocks not in current data
  • Dividends: Adjusted prices used, but dividend timing affects returns

References

安全使用建议
This skill appears to be what it says: Python backtest scripts that fetch A‑share data from AKShare and run MA/RSI strategies. Before running: (1) inspect bundled files (notably config/holdings.yaml) — it contains personal-looking portfolio data you may not want shared; (2) run in an isolated Python virtualenv or container and avoid running as root; (3) install akquant/akshare from trusted sources (pip) and verify package names/versions; (4) be aware the scripts will access the network to download market data and may read local CSVs under /root/.openclaw/workspace/data; (5) if you plan to use real trading, do not reuse secrets or real broker credentials here — this skill does not implement live trading but only backtesting. Overall: reasonable to install/use after the above checks.
功能分析
Type: OpenClaw Skill Name: akquant-backtest Version: 1.0.1 The skill bundle provides a legitimate framework for backtesting A-share trading strategies using the AKQuant and AKShare libraries. The Python scripts (e.g., scripts/double_ma_strategy.py and scripts/test_trend_filter_tdd.py) implement standard quantitative analysis logic, including moving averages and ADX indicators, without any evidence of malicious intent such as data exfiltration or unauthorized command execution. While config/holdings.yaml contains specific portfolio data, it appears to be a configuration or example file rather than a mechanism for credential theft. The instructions in SKILL.md are well-aligned with the tool's stated purpose and do not contain prompt-injection attacks.
能力评估
Purpose & Capability
Name/description, SKILL.md, README and Python scripts all describe a backtesting tool using akquant and AKShare. The included scripts implement double-MA and trend-filter strategies and call AKShare for data — this matches the stated purpose. One minor mismatch: config/holdings.yaml contains a user portfolio sample (personal-looking holdings) that is not needed for running the backtests; it appears to be example data bundled with the skill.
Instruction Scope
SKILL.md instructs running local Python scripts, installing akquant/akshare/pandas/numpy if missing, and using AKShare for market data. The instructions reference local CSV cache under /root/.openclaw/workspace/data (and venv path) which is consistent with the code (load_stock_data checks that path). There are no instructions to read unrelated system config, to exfiltrate data, or to post results to unexpected external endpoints.
Install Mechanism
There is no automated install spec — the skill is delivered as files and the README/SKILL.md suggest installing Python packages via pip. No downloads from arbitrary URLs or extracted archives are present in the manifest.
Credentials
The skill declares no required environment variables, credentials, or config paths. The code uses local workspace paths and network access to AKShare (expected for historical/real-time data). No broad or unrelated secrets are requested.
Persistence & Privilege
always is false and the skill does not request special persistent privileges. It modifies nothing outside its workspace and does not claim to enable itself or alter other skills.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install akquant-backtest
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /akquant-backtest 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.1
Added README.md documentation
v1.0.0
Initial release of akquant-backtest: - Provides high-performance backtesting for A-share (Chinese stocks) using AKQuant Rust engine with AKShare data. - Supports double MA (moving average), RSI, and custom quantitative strategies. - Includes Python scripts for running backtests, strategy definitions, and test cases. - Offers usage guidance, example commands, and troubleshooting tips. - Documents common stock symbols and strategy parameter presets. - Licensed under MIT.
元数据
Slug akquant-backtest
版本 1.0.1
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 2
常见问题

AKQuant A-Share Backtesting 是什么?

A-share quantitative trading backtesting using AKQuant (Rust engine) and AKShare data. Use when user asks to "backtest a stock strategy", "test trading algor... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 219 次。

如何安装 AKQuant A-Share Backtesting?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install akquant-backtest」即可一键安装,无需额外配置。

AKQuant A-Share Backtesting 是免费的吗?

是的,AKQuant A-Share Backtesting 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

AKQuant A-Share Backtesting 支持哪些平台?

AKQuant A-Share Backtesting 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 AKQuant A-Share Backtesting?

由 lamtest556-blip(@lamtest556-blip)开发并维护,当前版本 v1.0.1。

💬 留言讨论