Skip to main content

QKA(快量化 / Quant Kit for A-shares)- 简洁易用的 A 股量化回测框架

Project description

QKA — 快量化

Quant Kit for A-shares

文档站 PyPI Python License

QKA(快量化 / Quant Kit for A-shares) — 简洁易用的 A 股量化回测框架。

from qka import Data, Strategy, Backtest

class MyStrategy(Strategy):
    def on_bar(self, date):
        close = self.get('close')
        for sym in close.index:
            if sym not in self.broker.positions:
                price = float(close[sym])
                if price > 0:
                    size = self.sizing.percent(0.1, price)
                    if size >= 100:
                        self.broker.buy(sym, price, size)

bt = Backtest(Data(['000001.SZ']), MyStrategy(cash=100_000))
bt.run(benchmark='000300.SH')
bt.report()

安装

pip install qka

需要 Python 3.10+。

快速上手

数据

from qka import Data

data = Data(
    symbols=['000001.SZ', '600000.SH'],
    indicators={'sma_5': ('sma', 5), 'rsi_14': ('rsi', 14)},
)
df = data.get()  # 触发下载,返回宽表 DataFrame

策略

from qka import Strategy

class MyStrategy(Strategy):
    def __init__(self, cash=100_000):
        super().__init__(cash=cash)
        # 自定义状态放这里

    def on_bar(self, date):
        close = self.get('close')
        hist = self.history('close', 20)
        # 写你的交易逻辑

回测

from qka import Backtest

bt = Backtest(data, MyStrategy(cash=100_000))
bt.run(benchmark='000300.SH')
print(bt.summary())    # 输出绩效指标
bt.report()            # 生成 HTML 报告

更多示例

策略 说明
买入持有与定投 买入不动 + 每月定投
均线交叉 5日线上穿/下穿20日线
RSI + ATR 风控 RSI 超卖买入,ATR 止损
动量排序选股 月度动量排序,Top 5 等权
多因子打分 PE/ROE/动量/波动率打分选股

核心能力

  • 多数据源 — baostock(默认)、akshare、QMT,自动缓存
  • 预计算指标 — sma/ema/macd/rsi/bbands/atr + 自定义因子
  • 事件驱动回测 — 按日推进,self.get() 横截面 + self.history() 窗口序列
  • 仓位管理self.sizing.percent() / self.sizing.fixed_amount() / self.sizing.fixed_shares() / self.sizing.atr_risk()
  • 交易模拟 — 佣金万2.5、印花税万5、滑点0.1%,最低佣金5元
  • HTML 报告 — Plotly 交互图表,累计收益、回撤、月度热力图、交易明细
  • 基准对比 — 自动下载沪深300(或指定指数)做对比

文档

完整教程、API 参考、示例代码:

👉 qka.quantai.chat

下一步规划

  • 分钟级数据支持
  • 自适应参数优化
  • 实盘交易(QMT 接口)

许可证

MIT

致谢


⚠️ 量化交易存在风险,请充分了解后再使用本框架。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qka-1.8.1.dev2.tar.gz (68.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qka-1.8.1.dev2-py3-none-any.whl (60.3 kB view details)

Uploaded Python 3

File details

Details for the file qka-1.8.1.dev2.tar.gz.

File metadata

  • Download URL: qka-1.8.1.dev2.tar.gz
  • Upload date:
  • Size: 68.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qka-1.8.1.dev2.tar.gz
Algorithm Hash digest
SHA256 a1aba530e431478b9661cf8ed1ddb160cb2dd4c114f2e27f00d231dafba73e24
MD5 8e6f8e82c247600d42babb3d073b4ec1
BLAKE2b-256 0bfe4167d5735b4301fe69c3460a7211104451e786ebcca5325516a771efd734

See more details on using hashes here.

File details

Details for the file qka-1.8.1.dev2-py3-none-any.whl.

File metadata

  • Download URL: qka-1.8.1.dev2-py3-none-any.whl
  • Upload date:
  • Size: 60.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qka-1.8.1.dev2-py3-none-any.whl
Algorithm Hash digest
SHA256 4e3b67808f9fa77af4fcc204db0ce99a581387a381b1d07b20c8357c703e66b4
MD5 c6eeaa980f1e7cb2bd740ec3faa5a391
BLAKE2b-256 601dcc64300e39bebbb9c177f4a2d3259a4c9b3ed9e3e2875f7e72b9dad46c99

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page