akquant 0.1.0__cp39-abi3-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of akquant might be problematic. Click here for more details.
- akquant/__init__.py +81 -0
- akquant/__pycache__/__init__.cpython-312.pyc +0 -0
- akquant/__pycache__/__init__.cpython-313.pyc +0 -0
- akquant/__pycache__/analyzer.cpython-312.pyc +0 -0
- akquant/__pycache__/analyzer.cpython-313.pyc +0 -0
- akquant/__pycache__/backtest.cpython-312.pyc +0 -0
- akquant/__pycache__/backtest.cpython-313.pyc +0 -0
- akquant/__pycache__/config.cpython-312.pyc +0 -0
- akquant/__pycache__/config.cpython-313.pyc +0 -0
- akquant/__pycache__/data.cpython-312.pyc +0 -0
- akquant/__pycache__/data.cpython-313.pyc +0 -0
- akquant/__pycache__/indicator.cpython-312.pyc +0 -0
- akquant/__pycache__/indicator.cpython-313.pyc +0 -0
- akquant/__pycache__/log.cpython-312.pyc +0 -0
- akquant/__pycache__/log.cpython-313.pyc +0 -0
- akquant/__pycache__/sizer.cpython-312.pyc +0 -0
- akquant/__pycache__/sizer.cpython-313.pyc +0 -0
- akquant/__pycache__/strategy.cpython-312.pyc +0 -0
- akquant/__pycache__/strategy.cpython-313.pyc +0 -0
- akquant/__pycache__/utils.cpython-312.pyc +0 -0
- akquant/__pycache__/utils.cpython-313.pyc +0 -0
- akquant/akquant.pyd +0 -0
- akquant/akquant.pyi +518 -0
- akquant/backtest.py +414 -0
- akquant/config.py +36 -0
- akquant/data.py +122 -0
- akquant/indicator.py +56 -0
- akquant/log.py +135 -0
- akquant/sizer.py +82 -0
- akquant/strategy.py +516 -0
- akquant/utils.py +167 -0
- akquant-0.1.0.dist-info/METADATA +149 -0
- akquant-0.1.0.dist-info/RECORD +35 -0
- akquant-0.1.0.dist-info/WHEEL +4 -0
- akquant-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: akquant
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Classifier: Programming Language :: Rust
|
|
5
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Requires-Dist: pandas>=1.0.0
|
|
10
|
+
Requires-Dist: numpy>=1.0.0
|
|
11
|
+
Requires-Dist: akshare>=1.0.0
|
|
12
|
+
Requires-Dist: matplotlib>=3.0.0
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Summary: High-performance quantitative trading framework based on Rust and Python
|
|
15
|
+
Author: Akquant Developers
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
18
|
+
|
|
19
|
+
# akquant
|
|
20
|
+
|
|
21
|
+
**akquant** 是一个基于 **Rust** 和 **Python** 构建的高性能量化投研框架。它旨在结合 Rust 的极致性能和 Python 的易用性,为量化交易者提供强大的回测和研究工具。
|
|
22
|
+
|
|
23
|
+
最新版本参考了 [NautilusTrader](https://github.com/nautechsystems/nautilus_trader) 和 [PyBroker](https://github.com/edtechre/pybroker) 的架构理念,引入了模块化设计、独立的投资组合管理、高级订单类型支持以及便捷的数据加载与缓存机制。
|
|
24
|
+
|
|
25
|
+
📖 **[设计与开发指南 (DESIGN.md)](DESIGN.md)**: 如果你想深入了解内部架构、学习如何设计此类系统或进行二次开发,请阅读此文档。
|
|
26
|
+
|
|
27
|
+
## 核心特性
|
|
28
|
+
|
|
29
|
+
* **极致性能**: 核心回测引擎采用 Rust 编写,通过 PyO3 提供 Python 接口。
|
|
30
|
+
* **基准测试**: 在 200k K线数据的 SMA 策略回测中,akquant 耗时仅 **1.31s** (吞吐量 ~152k bars/sec),相比 Backtrader (26.55s) 和 PyBroker (23.61s) 快约 **20倍**。
|
|
31
|
+
* **模块化架构**:
|
|
32
|
+
* **Engine**: 事件驱动的核心撮合引擎,采用二进制堆 (BinaryHeap) 管理事件队列。
|
|
33
|
+
* **Clock**: 参考 NautilusTrader 设计的交易时钟,精确管理交易时段 (TradingSession) 和时间流逝。
|
|
34
|
+
* **Portfolio**: 独立的投资组合管理,支持实时权益计算。
|
|
35
|
+
* **MarketModel**: 可插拔的市场模型,内置 A 股 T+1 和期货 T+0 规则。
|
|
36
|
+
* **事件系统**:
|
|
37
|
+
* **Timer**: 支持 `schedule(timestamp, payload)` 注册定时事件,触发 `on_timer` 回调,实现复杂的盘中定时逻辑。
|
|
38
|
+
* **数据生态**:
|
|
39
|
+
* **AKShare 集成**: 内置 `DataLoader`,无缝支持 [AKShare](https://github.com/akfamily/akshare) 数据加载。
|
|
40
|
+
* **智能缓存**: 支持数据本地缓存 (Pickle),避免重复下载,加速策略迭代。
|
|
41
|
+
* **自动降级**: 如果默认缓存目录 (`~/.akquant`) 不可写,自动降级到当前目录 (`.akquant_cache`)。
|
|
42
|
+
* **多资产支持**:
|
|
43
|
+
* **股票 (Stock)**: 默认支持 T+1,买入 100 股一手限制,印花税/过户费。
|
|
44
|
+
* **基金 (Fund)**: 支持基金特有费率配置。
|
|
45
|
+
* **期货 (Futures)**: 支持 T+0,保证金交易,合约乘数。
|
|
46
|
+
* **期权 (Option)**: 支持 Call/Put,行权价,按张收费模式。
|
|
47
|
+
* **灵活配置**:
|
|
48
|
+
* **StrategyConfig**: 全局策略配置 (类似 PyBroker),支持资金管理、费率模式等设置。
|
|
49
|
+
* **ExecutionMode**: 支持 `CurrentClose` (信号当根K线收盘成交) 和 `NextOpen` (次日开盘成交) 模式。
|
|
50
|
+
* **丰富的分析工具**:
|
|
51
|
+
* **PerformanceMetrics**:
|
|
52
|
+
* **收益**: Total Return, Annualized Return, Alpha.
|
|
53
|
+
* **风险**: Max Drawdown, Sharpe Ratio, Sortino Ratio, Ulcer Index, UPI (Ulcer Performance Index).
|
|
54
|
+
* **拟合**: Equity R² (线性回归拟合度).
|
|
55
|
+
* **TradeAnalyzer**: 包含胜率、盈亏比、最大连续盈亏等详细交易统计,支持未结盈亏 (Unrealized PnL) 计算。
|
|
56
|
+
|
|
57
|
+
## 为什么选择 akquant?
|
|
58
|
+
|
|
59
|
+
传统的 Python 回测框架(如 backtrader)在处理大规模数据或复杂逻辑时往往面临性能瓶颈。纯 C++/Rust 框架虽然性能优越,但开发和调试门槛较高。
|
|
60
|
+
|
|
61
|
+
**akquant** 试图在两者之间找到平衡点:
|
|
62
|
+
|
|
63
|
+
1. **性能**: Rust 核心保证了回测速度,特别适合大规模参数优化。
|
|
64
|
+
2. **易用**: 策略编写完全使用 Python,提供类似 PyBroker 的简洁 API。
|
|
65
|
+
3. **专业**: 严格遵守中国市场交易规则(T+1、印花税、最低佣金等)。
|
|
66
|
+
|
|
67
|
+
## 前置要求
|
|
68
|
+
|
|
69
|
+
- **Rust**: [安装 Rust](https://www.rust-lang.org/tools/install)
|
|
70
|
+
- **Python**: 3.9+
|
|
71
|
+
- **Maturin**: `pip install maturin`
|
|
72
|
+
|
|
73
|
+
## 安装说明
|
|
74
|
+
|
|
75
|
+
### 开发模式(推荐)
|
|
76
|
+
|
|
77
|
+
如果你正在开发该项目并希望更改即时生效:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
maturin develop
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 快速开始
|
|
84
|
+
|
|
85
|
+
### 1. 使用 helper 快速回测 (推荐)
|
|
86
|
+
|
|
87
|
+
`akquant` 提供了一个类似 Zipline 的便捷入口 `run_backtest`,可以快速运行策略。
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import akquant
|
|
91
|
+
from akquant.backtest import run_backtest
|
|
92
|
+
from akquant import Strategy
|
|
93
|
+
|
|
94
|
+
# 1. 定义策略
|
|
95
|
+
class MyStrategy(Strategy):
|
|
96
|
+
def on_bar(self, bar):
|
|
97
|
+
# 简单的双均线逻辑 (示例)
|
|
98
|
+
# 实际回测推荐使用 IndicatorSet 进行向量化计算
|
|
99
|
+
if self.ctx.position.size == 0:
|
|
100
|
+
self.buy(symbol=bar.symbol, quantity=100)
|
|
101
|
+
elif bar.close > self.ctx.position.avg_price * 1.1:
|
|
102
|
+
self.sell(symbol=bar.symbol, quantity=100)
|
|
103
|
+
|
|
104
|
+
# 2. 运行回测
|
|
105
|
+
# 自动加载数据、设置资金、费率等
|
|
106
|
+
result = run_backtest(
|
|
107
|
+
strategy=MyStrategy, # 传递类或实例
|
|
108
|
+
symbol="600000", # 浦发银行
|
|
109
|
+
start_date="20230101",
|
|
110
|
+
end_date="20231231",
|
|
111
|
+
cash=500_000.0, # 初始资金
|
|
112
|
+
commission=0.0003 # 万三佣金
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# 3. 查看结果
|
|
116
|
+
print(f"Total Return: {result.metrics.total_return:.2%}")
|
|
117
|
+
print(f"Sharpe Ratio: {result.metrics.sharpe_ratio:.2f}")
|
|
118
|
+
print(f"Max Drawdown: {result.metrics.max_drawdown:.2%}")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 2. 函数式 API (Zipline 风格)
|
|
122
|
+
|
|
123
|
+
如果你习惯 Zipline 或 Backtrader 的函数式写法,也可以直接使用:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from akquant.backtest import run_backtest
|
|
127
|
+
|
|
128
|
+
def initialize(ctx):
|
|
129
|
+
ctx.stop_loss_pct = 0.05
|
|
130
|
+
|
|
131
|
+
def on_bar(ctx, bar):
|
|
132
|
+
if ctx.position.size == 0:
|
|
133
|
+
ctx.buy(symbol=bar.symbol, quantity=100)
|
|
134
|
+
elif bar.close < ctx.position.avg_price * (1 - ctx.stop_loss_pct):
|
|
135
|
+
ctx.sell(symbol=bar.symbol, quantity=100)
|
|
136
|
+
|
|
137
|
+
run_backtest(
|
|
138
|
+
strategy=on_bar,
|
|
139
|
+
initialize=initialize,
|
|
140
|
+
symbol="600000",
|
|
141
|
+
start_date="20230101",
|
|
142
|
+
end_date="20231231"
|
|
143
|
+
)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
更多示例请参考 `examples/` 目录。
|
|
147
|
+
|
|
148
|
+
## 快速链接
|
|
149
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
akquant\__init__.py,sha256=q5Yjc_0v0o9Xld9fAA7C8ksIV-FjWu1BAZCQSCoySss,2203
|
|
2
|
+
akquant\__pycache__\__init__.cpython-312.pyc,sha256=YWms10gTD3yYdOOvUXwxQj_y10pPA3bsx-BCaS-mFOA,2126
|
|
3
|
+
akquant\__pycache__\__init__.cpython-313.pyc,sha256=v4MCgnsG52O98N448snfO3xnlYsoJ9UH8cHPi85isWM,2121
|
|
4
|
+
akquant\__pycache__\analyzer.cpython-312.pyc,sha256=z4h5ftrbl1YIk1IJz5aQyWWqoYEMgOMQWvvHhnK8UYk,3011
|
|
5
|
+
akquant\__pycache__\analyzer.cpython-313.pyc,sha256=-0FTarlWoYezqbsirUI2U_5jGbYo3vDZZvtbO3LaZuY,3137
|
|
6
|
+
akquant\__pycache__\backtest.cpython-312.pyc,sha256=VhHDmuIkPUFU6fHxB0j7TDeNo_iU6CABOJAEDUhURqk,15709
|
|
7
|
+
akquant\__pycache__\backtest.cpython-313.pyc,sha256=Dw7EHnhzg0JqivzGQ5In4PIBWQyExWeVWKfzXJBaqMo,15882
|
|
8
|
+
akquant\__pycache__\config.cpython-312.pyc,sha256=R_IQEOFv2U1O9D259fZ0VVZCZjFi3NvBw0VqjhB6InA,1231
|
|
9
|
+
akquant\__pycache__\config.cpython-313.pyc,sha256=-tZ007Zm4MyobUkZ8ikkiJPmy1YEtPGya9hnQ8oyWHk,1279
|
|
10
|
+
akquant\__pycache__\data.cpython-312.pyc,sha256=iSt_iTCUIOLp3R1cWUBi0xyVo-asKE510LXsDGbUEe0,5467
|
|
11
|
+
akquant\__pycache__\data.cpython-313.pyc,sha256=BIUPGsGeo3R5ONZmsJ1xyn7SOewGLabzkFgycC5Vv9E,5464
|
|
12
|
+
akquant\__pycache__\indicator.cpython-312.pyc,sha256=U4t3jUeaiaYumYPkTbIDkySDkyfZdFV_GFbdf8kcJWg,2779
|
|
13
|
+
akquant\__pycache__\indicator.cpython-313.pyc,sha256=WPcS7dhCvhSsfTJzPxONtmS3e4-eaph2vghuaLQVFzg,2846
|
|
14
|
+
akquant\__pycache__\log.cpython-312.pyc,sha256=7e_nRezkTwhP_mCL77srk-6_H5flGugqaldcUr2V7ZY,5556
|
|
15
|
+
akquant\__pycache__\log.cpython-313.pyc,sha256=0twGvHlF_8P8iZbCivD0lf5QhMcFwKF8Ge6xLTgpAi8,5454
|
|
16
|
+
akquant\__pycache__\sizer.cpython-312.pyc,sha256=ns0ElwpWHUakXmN7YyMFaa8hiXMw7gErYqTZqH4zIs0,3243
|
|
17
|
+
akquant\__pycache__\sizer.cpython-313.pyc,sha256=m-f_y6GqoDB_Dw5ENp1ZLiwK_BNrGIKK3xlrWn0BBpc,3243
|
|
18
|
+
akquant\__pycache__\strategy.cpython-312.pyc,sha256=DCCTjDlMokK5GSc3V6irhgVV63ZpSFstAyC9cVsaiHY,19778
|
|
19
|
+
akquant\__pycache__\strategy.cpython-313.pyc,sha256=C-Hff41rO57evwscEVevKXXwEETUfHt-_sNt2aPqSbM,19291
|
|
20
|
+
akquant\__pycache__\utils.cpython-312.pyc,sha256=QlooggAC7DNDL3sMaykQmJu3amobMo1pBVPEuzknOGI,6554
|
|
21
|
+
akquant\__pycache__\utils.cpython-313.pyc,sha256=68I7EWrMtpHI4sfog43dlm6_M5BJxpzFzEqFTGWgU0Y,6537
|
|
22
|
+
akquant\akquant.pyd,sha256=f4do4dmxCU3ljECac5yjijstSIwKQZgnpG-POSW-2G8,1060352
|
|
23
|
+
akquant\akquant.pyi,sha256=72VUghJhb12hkv6loZhPGaS5WOZxAc4xf3guKhV4Y6Y,12903
|
|
24
|
+
akquant\backtest.py,sha256=PvlvSHKJ6X7xDIsf2UEKB4tvuFsFXoTxm3gY2oHzRzg,14261
|
|
25
|
+
akquant\config.py,sha256=BwxYxQezZWtqUfq4HGmMOWjhDuXxBMr4Hv0dj1q3Z8o,863
|
|
26
|
+
akquant\data.py,sha256=41sXOa2nOjYq8-blSum-Cer93xT8DdPlE7lOphzASSQ,3964
|
|
27
|
+
akquant\indicator.py,sha256=1XaZL56nNi6OQOZVqw3q2TIWc6CcniebEHjXDq_lcSY,1792
|
|
28
|
+
akquant\log.py,sha256=O7nkqRhzRmjgGjyW6_2QEJLLC5KwoCiqqTs4xNkXHkI,3676
|
|
29
|
+
akquant\sizer.py,sha256=upnZcZAmvEt09HvXSDqIGAaVmBFemTvKc96b_yj8st0,1900
|
|
30
|
+
akquant\strategy.py,sha256=DHRIyXApXmwwRoUF1EAwAyn_fwVdCttq8l3HWoovbLg,16963
|
|
31
|
+
akquant\utils.py,sha256=exLet8XLa1ui2s-YeFKxaxkobtb3_Gnph5pZK9uf1q0,5438
|
|
32
|
+
akquant-0.1.0.dist-info\METADATA,sha256=2jTKMtbtiv6oBYa3iA_cCYfR9I2Nc9mAMX2PhOw9-ig,6347
|
|
33
|
+
akquant-0.1.0.dist-info\WHEEL,sha256=OD0Is1kLHE07aD7XukSVDFU8ymUMI4Fdg0tKYWce3N0,95
|
|
34
|
+
akquant-0.1.0.dist-info\licenses\LICENSE,sha256=dg6QB5xlcf1KRtzePAEKp6AryK3SF2Li6eRsRtErtzs,1075
|
|
35
|
+
akquant-0.1.0.dist-info\RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 akquant developers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|