一键导入
生成 akquant 框架的可执行量化策略代码,涵盖数据接口、事件驱动、风控与优化;当用户需要开发 akquant量化策略 时使用
npx skills add https://github.com/lzwme/finance-quant-skills --skill akquant复制此命令并粘贴到 Claude Code 中以安装该技能
生成 akquant 框架的可执行量化策略代码,涵盖数据接口、事件驱动、风控与优化;当用户需要开发 akquant量化策略 时使用
npx skills add https://github.com/lzwme/finance-quant-skills --skill akquant复制此命令并粘贴到 Claude Code 中以安装该技能
QMT(迅投极速策略交易系统)Python 策略开发完整指南。涵盖策略编写、回测、实盘交易、API参考和代码示例。当需要开发QMT量化策略或查询QMT API时使用本技能。
AKShare 开源金融数据接口库,提供股票、期货、期权、基金、外汇、债券、指数、加密货币等全品类金融数据;当用户需要获取各类金融市场数据时使用
BaoStock A股数据平台,免费开源,支持股票行情、K线、财务数据、行业分类、指数成分股查询;当用户需要获取A股历史行情、财务报表、交易日历等数据时使用
MiniQMT 迅投量化交易接口,基于 XtQuant Python 库,支持 A 股/期货/期权的行情数据获取(K线、分笔、财务数据等)和交易下单(报单、撤单、查询资产/委托/持仓)。当用户需要获取miniqmt实时/历史行情、进行量化交易、回测数据时使用
通达信量化数据获取技能。当用户提及 tdxquant、通达信、TdxQuant、tqcenter,并且需要获取A股数据(行情快照、K线、财务、板块、可转债、新股、交易数据等)、查询交易日历、执行通达信公式、订阅行情、交易下单时使用
聚宽A股行情、历史K线、财务数据、指标数据等证券财经信息获取;当用户提及聚宽、jqdata、jqdatasdk,并且需要获取A股数据时使用
| name | akquant |
| description | 生成 akquant 框架的可执行量化策略代码,涵盖数据接口、事件驱动、风控与优化;当用户需要开发 akquant量化策略 时使用 |
| metadata | {"clawdbot":{"emoji":"📈","requires":{"bins":["python","uv"],"os":"win32"}}} |
本 Skill 用于辅助 AI 编程智能体生成符合 akquant 框架规范的可执行量化策略代码。能力包括策略设计、回测配置、订单管理、风控规则、参数优化与横截面策略实现。
当用户表达以下意图时触发:
参考 strategy-patterns.md 选择范式:
关键决策点:
使用 assets/strategy-template.py 作为起点:
from akquant import Strategy, Bar
class MyStrategy(Strategy):
warmup_period = 20 # 预热数据长度
def __init__(self, param1=10):
self.param1 = param1
def on_start(self):
self.subscribe("600000")
def on_bar(self, bar: Bar):
# 核心交易逻辑
history = self.get_history(self.param1, bar.symbol, "close")
if len(history) < self.param1:
return
import numpy as np
ma = np.mean(history)
pos = self.get_position(bar.symbol)
if bar.close > ma and pos == 0:
self.buy(bar.symbol, 100)
elif bar.close < ma and pos > 0:
self.sell(bar.symbol, 100)
参考 api-reference.md 设置参数:
from akquant import run_backtest
result = run_backtest(
strategy=MyStrategy,
data=df,
symbol="600000",
initial_cash=500_000.0,
commission_rate=0.0003,
stamp_tax_rate=0.001,
t_plus_one=True, # A 股 T+1 规则
warmup_period=20,
execution_mode="NextOpen",
)
参考 risk-management.md 配置:
from akquant.config import RiskConfig
result = run_backtest(
...,
risk_config=RiskConfig(
max_position_pct=0.10, # 单标的持仓不超过 10%
max_account_drawdown=0.20, # 最大回撤 20%
max_daily_loss=0.05, # 单日亏损 5%
),
)
参考 optimization.md 执行:
from akquant import run_grid_search, run_walk_forward
# 网格搜索
results = run_grid_search(
strategy=MyStrategy,
param_grid={"param1": [10, 20, 30]},
data=df,
sort_by="sharpe_ratio",
)
# 滚动优化(推荐)
wfo_results = run_walk_forward(
strategy=MyStrategy,
param_grid={"param1": [10, 20, 30]},
data=df,
train_period=250,
test_period=60,
metric="sharpe_ratio",
)
参考 cross-section-guide.md 实现多标的轮动:
推荐范式:使用 on_timer 统一触发调仓
class CrossSectionStrategy(Strategy):
def __init__(self):
self.universe = ["sh600519", "sz000858", "sh601318"]
def on_start(self):
self.add_daily_timer("14:55:00", "rebalance")
def on_timer(self, payload):
if payload != "rebalance":
return
# 计算所有标分数
scores = {}
for symbol in self.universe:
history = self.get_history(20, symbol, "close")
scores[symbol] = (history[-1] - history[0]) / history[0]
# 选出最佳标的并调仓
best = max(scores, key=scores.get)
self.order_target_percent(0.95, symbol=best)
| 资源 | 用途 | 何时读取 |
|---|---|---|
| api-reference.md | API 速查 | 查询函数签名与参数 |
| strategy-patterns.md | 策略范式 | 设计策略结构 |
| risk-management.md | 风控配置 | 设置风控规则 |
| optimization.md | 参数优化 | 调优策略参数 |
| cross-section-guide.md | 横截面策略 | 实现多标的轮动 |
| strategy-template.py | 策略模板 | 快速生成代码骨架 |
由于 akquant 依赖 pandas>=3.0.0,全局安装可能与现有项目存在版本冲突。推荐使用 uv 创建隔离环境:
# macOS
brew install uv
# Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# 创建项目目录
mkdir my-quant-strategy
cd my-quant-strategy
# 初始化项目(创建 pyproject.toml)
uv init
# 创建虚拟环境并安装依赖
uv venv
uv add akquant pandas numpy
# 方式一:使用 uv run(推荐)
uv run python my_strategy.py
# 方式二:激活虚拟环境后运行
source .venv/bin/activate # macOS/Linux
# .venv\Scripts\activate # Windows
python my_strategy.py
uv 会自动生成 uv.lock 文件,确保团队依赖一致:
# 安装精确版本(从 lock 文件)
uv sync
# 添加新依赖
uv add scipy # 自动更新 lock 文件
my-quant-strategy/
├── .venv/ # 虚拟环境(uv 自动创建)
├── pyproject.toml # 项目配置
├── uv.lock # 依赖锁定文件
├── strategies/ # 策略脚本
│ ├── ma_strategy.py
│ └── cross_section.py
└── data/ # 数据文件
└── stock_data.csv
# 一键创建并运行策略项目
mkdir quant-project && cd quant-project
uv init
uv venv
uv add akquant pandas numpy
# 创建策略文件(使用模板)
cat > strategy.py << 'EOF'
from akquant import Strategy, Bar, run_backtest
import pandas as pd
import numpy as np
class MyStrategy(Strategy):
warmup_period = 20
def on_bar(self, bar: Bar):
closes = self.get_history(20, bar.symbol, "close")
if len(closes) < 20:
return
ma = np.mean(closes)
pos = self.get_position(bar.symbol)
if bar.close > ma and pos == 0:
self.buy(bar.symbol, 100)
elif bar.close < ma and pos > 0:
self.sell(bar.symbol, pos)
# 准备数据并运行回测
# result = run_backtest(strategy=MyStrategy, data=df, symbol="600000")
EOF
# 运行策略
uv run python strategy.py
from akquant import Strategy, Bar
import numpy as np
class DualMAStrategy(Strategy):
warmup_period = 30
def __init__(self, fast=10, slow=20):
self.fast = fast
self.slow = slow
self.warmup_period = slow + 1
def on_bar(self, bar: Bar):
fast_ma = np.mean(self.get_history(self.fast, bar.symbol, "close"))
slow_ma = np.mean(self.get_history(self.slow, bar.symbol, "close"))
pos = self.get_position(bar.symbol)
if fast_ma > slow_ma and pos == 0:
self.buy(bar.symbol, 100)
elif fast_ma < slow_ma and pos > 0:
self.sell(bar.symbol, pos)
from akquant import Strategy, Bar, run_backtest
from akquant.config import RiskConfig
import numpy as np
class TrendStrategy(Strategy):
warmup_period = 20
def __init__(self, ma_window=20, stop_loss=0.05):
self.ma_window = ma_window
self.stop_loss = stop_loss
def on_bar(self, bar: Bar):
ma = np.mean(self.get_history(self.ma_window, bar.symbol, "close"))
pos = self.get_position(bar.symbol)
if bar.close > ma * 1.02 and pos == 0:
self.buy(bar.symbol, 100)
elif bar.close < ma * 0.98 and pos > 0:
self.sell(bar.symbol, pos)
# 运行回测
result = run_backtest(
strategy=TrendStrategy,
data=df,
symbol="600000",
initial_cash=1_000_000.0,
risk_config=RiskConfig(
max_position_pct=0.20,
max_account_drawdown=0.15,
stop_loss_threshold=0.85,
),
)
from akquant import Strategy, run_backtest
import numpy as np
class MomentumRotation(Strategy):
def __init__(self, lookback=20):
self.lookback = lookback
self.universe = ["sh600519", "sz000858", "sh601318"]
self.warmup_period = lookback + 1
def on_start(self):
for symbol in self.universe:
self.subscribe(symbol)
self.add_daily_timer("14:55:00", "rebalance")
def on_timer(self, payload):
if payload != "rebalance":
return
scores = {}
for symbol in self.universe:
closes = self.get_history(self.lookback, symbol, "close")
if len(closes) < self.lookback:
return
scores[symbol] = (closes[-1] - closes[0]) / closes[0]
# 选出最佳标的,持仓 95%
best = max(scores, key=scores.get)
self.order_target_percent(0.95, symbol=best)