Skip to main content

High-performance quantitative trading framework based on Rust and Python

Project description

AKQuant

PyPI Version Python Versions License

AKQuant

AKQuant 是一个基于 RustPython 构建的高性能量化投研框架。它结合了 Rust 的极致性能和 Python 的易用性,为量化交易者提供强大的回测、风控及机器学习支持。

相比传统框架(如 Backtrader),AKQuant 拥有 20倍+ 的回测性能提升,并原生支持 Walk-forward Validation(滚动训练)和 Zero-Copy 数据访问。

👉 阅读完整文档 | English Documentation

安装说明

AKQuant 已发布至 PyPI,无需安装 Rust 环境即可直接使用。

pip install akquant

快速开始

以下是一个简单的策略示例:

import akshare as ak
import akquant as aq
from akquant import Strategy

# 1. 准备数据
# 使用 akshare 获取 A 股历史数据 (需安装: pip install akshare)
df = ak.stock_zh_a_daily(symbol="sh600000", start_date="20230101", end_date="20231231")

class MyStrategy(Strategy):
    def on_bar(self, bar):
        # 简单策略示例:
        # 当收盘价 > 开盘价 (阳线) -> 买入
        # 当收盘价 < 开盘价 (阴线) -> 卖出

        # 获取当前持仓
        current_pos = self.get_position(bar.symbol)

        if current_pos == 0 and bar.close > bar.open:
            self.buy(bar.symbol, 100)
            print(f"[{bar.timestamp_str}] Buy 100 at {bar.close:.2f}")

        elif current_pos > 0 and bar.close < bar.open:
            self.close_position(bar.symbol)
            print(f"[{bar.timestamp_str}] Sell 100 at {bar.close:.2f}")

# 运行回测
result = aq.run_backtest(
    data=df,
    strategy=MyStrategy,
    symbol="sh600000"
)

# 打印回测结果
print("\n=== Backtest Result ===")
print(result.metrics_df)

运行结果示例:

=== Backtest Result ===
                            Backtest
annualized_return          -0.000575
end_market_value       999433.064610
equity_r2                   0.981178
initial_market_value  1000000.000000
max_drawdown                0.000567
max_drawdown_pct            0.056694
sharpe_ratio               -6.331191
sortino_ratio              -6.845218
std_error                  22.986004
total_return               -0.000567
total_return_pct           -0.056694
ulcer_index                 0.000306
upi                        -1.878765
volatility                  0.000091
win_rate                    0.339286

文档索引

License

MIT License

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

akquant-0.1.14.tar.gz (223.3 kB view details)

Uploaded Source

Built Distribution

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

akquant-0.1.14-cp310-abi3-win_amd64.whl (641.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

File details

Details for the file akquant-0.1.14.tar.gz.

File metadata

  • Download URL: akquant-0.1.14.tar.gz
  • Upload date:
  • Size: 223.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for akquant-0.1.14.tar.gz
Algorithm Hash digest
SHA256 c014a71e7e9254e66efcfdc8c59736fc053c1a0f1ead8af15a29a1bf809fdaab
MD5 fe2b02219df296a922983357120bbcd9
BLAKE2b-256 98a9218ed9a0633b803cfeb7e476db11e32f988f580553f3d6dd7f32736e66d4

See more details on using hashes here.

File details

Details for the file akquant-0.1.14-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: akquant-0.1.14-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 641.3 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for akquant-0.1.14-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 36697c94eebb12d71667745510a209ac67dc5caf8b786fc3eaa1589276070dad
MD5 f872d7b42149b858eb36a2dd352c372d
BLAKE2b-256 8c30ff7b6fe4ab83d492306d22cade00514535504c1856ad504fd6d9f793c439

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