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
akquant/__init__.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from .akquant import *
|
|
2
|
+
from .utils import load_akshare_bar, prepare_dataframe
|
|
3
|
+
from .sizer import Sizer, FixedSize, PercentSizer, AllInSizer
|
|
4
|
+
from .strategy import Strategy
|
|
5
|
+
from .data import DataLoader
|
|
6
|
+
from .log import get_logger, register_logger
|
|
7
|
+
from .config import strategy_config
|
|
8
|
+
from .indicator import Indicator, IndicatorSet
|
|
9
|
+
from .backtest import run_backtest, plot_result
|
|
10
|
+
|
|
11
|
+
__doc__ = akquant.__doc__
|
|
12
|
+
if hasattr(akquant, "__all__"):
|
|
13
|
+
__all__ = akquant.__all__ + [
|
|
14
|
+
"load_akshare_bar",
|
|
15
|
+
"prepare_dataframe",
|
|
16
|
+
"Sizer",
|
|
17
|
+
"FixedSize",
|
|
18
|
+
"PercentSizer",
|
|
19
|
+
"AllInSizer",
|
|
20
|
+
"Strategy",
|
|
21
|
+
"DataLoader",
|
|
22
|
+
"get_logger",
|
|
23
|
+
"register_logger",
|
|
24
|
+
"strategy_config",
|
|
25
|
+
"Indicator",
|
|
26
|
+
"IndicatorSet",
|
|
27
|
+
"run_backtest",
|
|
28
|
+
"plot_result",
|
|
29
|
+
]
|
|
30
|
+
else:
|
|
31
|
+
__all__ = [
|
|
32
|
+
"load_akshare_bar",
|
|
33
|
+
"prepare_dataframe",
|
|
34
|
+
"Sizer",
|
|
35
|
+
"FixedSize",
|
|
36
|
+
"PercentSizer",
|
|
37
|
+
"AllInSizer",
|
|
38
|
+
"Strategy",
|
|
39
|
+
"DataLoader",
|
|
40
|
+
"get_logger",
|
|
41
|
+
"register_logger",
|
|
42
|
+
"strategy_config",
|
|
43
|
+
"Indicator",
|
|
44
|
+
"IndicatorSet",
|
|
45
|
+
"run_backtest",
|
|
46
|
+
"plot_result",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def create_bar(timestamp, open_px, high_px, low_px, close_px, volume, symbol):
|
|
51
|
+
"""创建 Bar 对象的辅助函数"""
|
|
52
|
+
return Bar(timestamp, open_px, high_px, low_px, close_px, volume, symbol)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _engine_set_timezone_name(self, tz_name: str):
|
|
56
|
+
"""
|
|
57
|
+
通过时区名称设置引擎时区
|
|
58
|
+
|
|
59
|
+
:param tz_name: 时区名称,例如 "Asia/Shanghai", "UTC", "US/Eastern"
|
|
60
|
+
"""
|
|
61
|
+
import datetime
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
import zoneinfo
|
|
65
|
+
|
|
66
|
+
tz = zoneinfo.ZoneInfo(tz_name)
|
|
67
|
+
except ImportError:
|
|
68
|
+
import pytz
|
|
69
|
+
|
|
70
|
+
tz = pytz.timezone(tz_name)
|
|
71
|
+
|
|
72
|
+
# Get offset for current time (approximate is usually fine for constant offset zones,
|
|
73
|
+
# but for DST aware zones, we might want a specific date.
|
|
74
|
+
# For simplicity and standard market hours, we use current date or a fixed date)
|
|
75
|
+
now = datetime.datetime.now(tz)
|
|
76
|
+
offset = int(now.utcoffset().total_seconds())
|
|
77
|
+
self.set_timezone(offset)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# Patch Engine class
|
|
81
|
+
Engine.set_timezone_name = _engine_set_timezone_name
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
akquant/akquant.pyd
ADDED
|
Binary file
|
akquant/akquant.pyi
ADDED
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
# This file is automatically generated by pyo3_stub_gen
|
|
2
|
+
# ruff: noqa: E501, F401
|
|
3
|
+
|
|
4
|
+
import akquant
|
|
5
|
+
import typing
|
|
6
|
+
|
|
7
|
+
class AssetType:
|
|
8
|
+
Stock: typing.ClassVar["AssetType"]
|
|
9
|
+
Futures: typing.ClassVar["AssetType"]
|
|
10
|
+
def __init__(self, *args, **kwargs): ...
|
|
11
|
+
|
|
12
|
+
class OrderSide:
|
|
13
|
+
Buy: typing.ClassVar["OrderSide"]
|
|
14
|
+
Sell: typing.ClassVar["OrderSide"]
|
|
15
|
+
def __init__(self, *args, **kwargs): ...
|
|
16
|
+
|
|
17
|
+
class OrderType:
|
|
18
|
+
Market: typing.ClassVar["OrderType"]
|
|
19
|
+
Limit: typing.ClassVar["OrderType"]
|
|
20
|
+
def __init__(self, *args, **kwargs): ...
|
|
21
|
+
|
|
22
|
+
class OrderStatus:
|
|
23
|
+
New: typing.ClassVar["OrderStatus"]
|
|
24
|
+
Submitted: typing.ClassVar["OrderStatus"]
|
|
25
|
+
Filled: typing.ClassVar["OrderStatus"]
|
|
26
|
+
Cancelled: typing.ClassVar["OrderStatus"]
|
|
27
|
+
Rejected: typing.ClassVar["OrderStatus"]
|
|
28
|
+
Expired: typing.ClassVar["OrderStatus"]
|
|
29
|
+
def __init__(self, *args, **kwargs): ...
|
|
30
|
+
|
|
31
|
+
class TimeInForce:
|
|
32
|
+
GTC: typing.ClassVar["TimeInForce"]
|
|
33
|
+
IOC: typing.ClassVar["TimeInForce"]
|
|
34
|
+
FOK: typing.ClassVar["TimeInForce"]
|
|
35
|
+
Day: typing.ClassVar["TimeInForce"]
|
|
36
|
+
def __init__(self, *args, **kwargs): ...
|
|
37
|
+
|
|
38
|
+
class ExecutionMode:
|
|
39
|
+
CurrentClose: typing.ClassVar["ExecutionMode"]
|
|
40
|
+
NextOpen: typing.ClassVar["ExecutionMode"]
|
|
41
|
+
def __init__(self, *args, **kwargs): ...
|
|
42
|
+
|
|
43
|
+
class TradingSession:
|
|
44
|
+
PreOpen: typing.ClassVar["TradingSession"]
|
|
45
|
+
Continuous: typing.ClassVar["TradingSession"]
|
|
46
|
+
CallAuction: typing.ClassVar["TradingSession"]
|
|
47
|
+
Break: typing.ClassVar["TradingSession"]
|
|
48
|
+
Closed: typing.ClassVar["TradingSession"]
|
|
49
|
+
PostClose: typing.ClassVar["TradingSession"]
|
|
50
|
+
def __init__(self, *args, **kwargs): ...
|
|
51
|
+
|
|
52
|
+
class BacktestResult:
|
|
53
|
+
r"""
|
|
54
|
+
回测结果
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
equity_curve: list[tuple[int, float]]
|
|
58
|
+
metrics: PerformanceMetrics
|
|
59
|
+
trade_metrics: TradePnL
|
|
60
|
+
trades: list[ClosedTrade]
|
|
61
|
+
|
|
62
|
+
class ClosedTrade:
|
|
63
|
+
r"""
|
|
64
|
+
平仓交易记录
|
|
65
|
+
|
|
66
|
+
:ivar symbol: 标的代码
|
|
67
|
+
:ivar entry_time: 开仓时间戳
|
|
68
|
+
:ivar exit_time: 平仓时间戳
|
|
69
|
+
:ivar entry_price: 开仓价格
|
|
70
|
+
:ivar exit_price: 平仓价格
|
|
71
|
+
:ivar quantity: 交易数量
|
|
72
|
+
:ivar direction: 交易方向 ("Long" or "Short")
|
|
73
|
+
:ivar pnl: 毛利 (Gross PnL),不包含佣金 (aligned with Backtrader)
|
|
74
|
+
:ivar net_pnl: 净利 (Net PnL),包含佣金 (pnl - commission)
|
|
75
|
+
:ivar return_pct: 收益率
|
|
76
|
+
:ivar commission: 交易佣金
|
|
77
|
+
:ivar duration_bars: 持仓周期数
|
|
78
|
+
"""
|
|
79
|
+
symbol: str
|
|
80
|
+
entry_time: int
|
|
81
|
+
exit_time: int
|
|
82
|
+
entry_price: float
|
|
83
|
+
exit_price: float
|
|
84
|
+
quantity: float
|
|
85
|
+
direction: str
|
|
86
|
+
pnl: float
|
|
87
|
+
net_pnl: float
|
|
88
|
+
return_pct: float
|
|
89
|
+
commission: float
|
|
90
|
+
duration_bars: int
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class Bar:
|
|
94
|
+
r"""
|
|
95
|
+
K线数据结构
|
|
96
|
+
|
|
97
|
+
:ivar timestamp: Unix 时间戳 (纳秒)
|
|
98
|
+
:ivar open: 开盘价
|
|
99
|
+
:ivar high: 最高价
|
|
100
|
+
:ivar low: 最低价
|
|
101
|
+
:ivar close: 收盘价
|
|
102
|
+
:ivar volume: 成交量
|
|
103
|
+
:ivar symbol: 标的代码
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
timestamp: int
|
|
107
|
+
symbol: str
|
|
108
|
+
open: float
|
|
109
|
+
high: float
|
|
110
|
+
low: float
|
|
111
|
+
close: float
|
|
112
|
+
volume: float
|
|
113
|
+
def __new__(
|
|
114
|
+
cls,
|
|
115
|
+
timestamp: typing.Any,
|
|
116
|
+
open: typing.Any,
|
|
117
|
+
high: typing.Any,
|
|
118
|
+
low: typing.Any,
|
|
119
|
+
close: typing.Any,
|
|
120
|
+
volume: typing.Any,
|
|
121
|
+
symbol: str,
|
|
122
|
+
): ...
|
|
123
|
+
def set_open(self, value: typing.Any) -> None: ...
|
|
124
|
+
def set_high(self, value: typing.Any) -> None: ...
|
|
125
|
+
def set_low(self, value: typing.Any) -> None: ...
|
|
126
|
+
def set_close(self, value: typing.Any) -> None: ...
|
|
127
|
+
def set_volume(self, value: typing.Any) -> None: ...
|
|
128
|
+
def __repr__(self) -> str: ...
|
|
129
|
+
|
|
130
|
+
class DataFeed: ...
|
|
131
|
+
|
|
132
|
+
class Engine:
|
|
133
|
+
r"""
|
|
134
|
+
主回测引擎
|
|
135
|
+
|
|
136
|
+
:ivar feed: 数据源
|
|
137
|
+
:ivar portfolio: 投资组合
|
|
138
|
+
:ivar orders: 订单列表
|
|
139
|
+
:ivar trades: 成交列表
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
portfolio: Portfolio
|
|
143
|
+
orders: list[Order]
|
|
144
|
+
trades: list[Trade]
|
|
145
|
+
def __new__(
|
|
146
|
+
cls,
|
|
147
|
+
): ...
|
|
148
|
+
def set_execution_mode(self, mode: akquant.ExecutionMode) -> None:
|
|
149
|
+
r"""
|
|
150
|
+
设置撮合模式
|
|
151
|
+
|
|
152
|
+
:param mode: 撮合模式 (ExecutionMode.CurrentClose 或 ExecutionMode.NextOpen)
|
|
153
|
+
:type mode: ExecutionMode
|
|
154
|
+
"""
|
|
155
|
+
...
|
|
156
|
+
|
|
157
|
+
def set_timezone(self, offset: int) -> None: ...
|
|
158
|
+
def use_simple_market(self, commission_rate: float) -> None:
|
|
159
|
+
r"""
|
|
160
|
+
启用 SimpleMarket (7x24小时, T+0, 无税, 简单佣金)
|
|
161
|
+
|
|
162
|
+
:param commission_rate: 佣金率
|
|
163
|
+
"""
|
|
164
|
+
...
|
|
165
|
+
|
|
166
|
+
def use_china_market(self) -> None:
|
|
167
|
+
r"""
|
|
168
|
+
启用 ChinaMarket (支持 T+1/T+0, 印花税, 过户费, 交易时段等)
|
|
169
|
+
"""
|
|
170
|
+
...
|
|
171
|
+
|
|
172
|
+
def use_china_futures_market(self) -> None:
|
|
173
|
+
r"""
|
|
174
|
+
启用中国期货市场默认配置
|
|
175
|
+
- 切换到 ChinaMarket
|
|
176
|
+
- 设置 T+0
|
|
177
|
+
- 保持当前交易时段配置 (需手动设置 set_market_sessions 以匹配特定品种)
|
|
178
|
+
"""
|
|
179
|
+
...
|
|
180
|
+
|
|
181
|
+
def set_t_plus_one(self, enabled: bool) -> None:
|
|
182
|
+
r"""
|
|
183
|
+
启用/禁用 T+1 交易规则 (仅针对 ChinaMarket)
|
|
184
|
+
|
|
185
|
+
:param enabled: 是否启用 T+1
|
|
186
|
+
:type enabled: bool
|
|
187
|
+
"""
|
|
188
|
+
...
|
|
189
|
+
|
|
190
|
+
def set_force_session_continuous(self, enabled: bool) -> None: ...
|
|
191
|
+
def set_stock_fee_rules(
|
|
192
|
+
self,
|
|
193
|
+
commission_rate: float,
|
|
194
|
+
stamp_tax: float,
|
|
195
|
+
transfer_fee: float,
|
|
196
|
+
min_commission: float,
|
|
197
|
+
) -> None: ...
|
|
198
|
+
def set_future_fee_rules(self, commission_rate: float) -> None: ...
|
|
199
|
+
def set_market_sessions(
|
|
200
|
+
self, sessions: typing.Sequence[tuple[str, str, akquant.TradingSession]]
|
|
201
|
+
) -> None: ...
|
|
202
|
+
def add_instrument(self, instrument: Instrument) -> None:
|
|
203
|
+
r"""
|
|
204
|
+
添加交易标的
|
|
205
|
+
|
|
206
|
+
:param instrument: 交易标的对象
|
|
207
|
+
:type instrument: Instrument
|
|
208
|
+
"""
|
|
209
|
+
...
|
|
210
|
+
|
|
211
|
+
def set_cash(self, cash: float) -> None:
|
|
212
|
+
r"""
|
|
213
|
+
设置初始资金
|
|
214
|
+
|
|
215
|
+
:param cash: 初始资金数额
|
|
216
|
+
:type cash: float
|
|
217
|
+
"""
|
|
218
|
+
...
|
|
219
|
+
|
|
220
|
+
def add_data(self, feed: DataFeed) -> None:
|
|
221
|
+
r"""
|
|
222
|
+
添加数据源
|
|
223
|
+
|
|
224
|
+
:param feed: 数据源对象
|
|
225
|
+
:type feed: DataFeed
|
|
226
|
+
"""
|
|
227
|
+
...
|
|
228
|
+
|
|
229
|
+
def add_bars(self, bars: typing.Sequence[Bar]) -> None:
|
|
230
|
+
r"""
|
|
231
|
+
批量添加 K 线数据
|
|
232
|
+
|
|
233
|
+
:param bars: K 线列表
|
|
234
|
+
"""
|
|
235
|
+
...
|
|
236
|
+
|
|
237
|
+
def run(self, strategy: typing.Any) -> str:
|
|
238
|
+
r"""
|
|
239
|
+
运行回测
|
|
240
|
+
|
|
241
|
+
:param strategy: 策略对象
|
|
242
|
+
:type strategy: object
|
|
243
|
+
:return: 回测结果摘要
|
|
244
|
+
:rtype: str
|
|
245
|
+
"""
|
|
246
|
+
...
|
|
247
|
+
|
|
248
|
+
def get_results(self) -> BacktestResult:
|
|
249
|
+
r"""
|
|
250
|
+
获取回测结果
|
|
251
|
+
|
|
252
|
+
:return: BacktestResult
|
|
253
|
+
"""
|
|
254
|
+
...
|
|
255
|
+
|
|
256
|
+
def create_context(
|
|
257
|
+
self, active_orders: typing.Sequence[Order]
|
|
258
|
+
) -> StrategyContext: ...
|
|
259
|
+
|
|
260
|
+
class Instrument:
|
|
261
|
+
r"""
|
|
262
|
+
交易标的
|
|
263
|
+
|
|
264
|
+
:ivar symbol: 代码
|
|
265
|
+
:ivar asset_type: 资产类型
|
|
266
|
+
:ivar multiplier: 合约乘数
|
|
267
|
+
:ivar margin_ratio: 保证金比率
|
|
268
|
+
:ivar tick_size: 最小变动价位
|
|
269
|
+
"""
|
|
270
|
+
|
|
271
|
+
symbol: str
|
|
272
|
+
asset_type: akquant.AssetType
|
|
273
|
+
multiplier: float
|
|
274
|
+
margin_ratio: float
|
|
275
|
+
tick_size: float
|
|
276
|
+
def __new__(
|
|
277
|
+
cls,
|
|
278
|
+
symbol: str,
|
|
279
|
+
asset_type: akquant.AssetType,
|
|
280
|
+
multiplier: typing.Any,
|
|
281
|
+
margin_ratio: typing.Any,
|
|
282
|
+
tick_size: typing.Any,
|
|
283
|
+
): ...
|
|
284
|
+
|
|
285
|
+
class Order:
|
|
286
|
+
r"""
|
|
287
|
+
订单
|
|
288
|
+
|
|
289
|
+
:ivar id: 订单ID
|
|
290
|
+
:ivar symbol: 标的代码
|
|
291
|
+
:ivar side: 交易方向
|
|
292
|
+
:ivar order_type: 订单类型
|
|
293
|
+
:ivar quantity: 数量
|
|
294
|
+
:ivar price: 价格 (限价单有效)
|
|
295
|
+
:ivar time_in_force: 订单有效期
|
|
296
|
+
:ivar trigger_price: 触发价格 (止损/止盈单)
|
|
297
|
+
:ivar status: 订单状态
|
|
298
|
+
:ivar filled_quantity: 已成交数量
|
|
299
|
+
:ivar average_filled_price: 成交均价
|
|
300
|
+
"""
|
|
301
|
+
|
|
302
|
+
id: str
|
|
303
|
+
symbol: str
|
|
304
|
+
side: akquant.OrderSide
|
|
305
|
+
order_type: akquant.OrderType
|
|
306
|
+
time_in_force: akquant.TimeInForce
|
|
307
|
+
status: akquant.OrderStatus
|
|
308
|
+
quantity: float
|
|
309
|
+
price: typing.Optional[float]
|
|
310
|
+
trigger_price: typing.Optional[float]
|
|
311
|
+
filled_quantity: float
|
|
312
|
+
average_filled_price: typing.Optional[float]
|
|
313
|
+
def __new__(
|
|
314
|
+
cls,
|
|
315
|
+
id,
|
|
316
|
+
symbol,
|
|
317
|
+
side,
|
|
318
|
+
order_type,
|
|
319
|
+
quantity,
|
|
320
|
+
price=...,
|
|
321
|
+
time_in_force=...,
|
|
322
|
+
trigger_price=...,
|
|
323
|
+
): ...
|
|
324
|
+
def __repr__(self) -> str: ...
|
|
325
|
+
|
|
326
|
+
class PerformanceMetrics:
|
|
327
|
+
r"""
|
|
328
|
+
绩效指标
|
|
329
|
+
"""
|
|
330
|
+
|
|
331
|
+
total_return: float
|
|
332
|
+
annualized_return: float
|
|
333
|
+
max_drawdown: float
|
|
334
|
+
max_drawdown_pct: float
|
|
335
|
+
sharpe_ratio: float
|
|
336
|
+
sortino_ratio: float
|
|
337
|
+
volatility: float
|
|
338
|
+
ulcer_index: float
|
|
339
|
+
upi: float
|
|
340
|
+
equity_r2: float
|
|
341
|
+
std_error: float
|
|
342
|
+
win_rate: float
|
|
343
|
+
initial_market_value: float
|
|
344
|
+
end_market_value: float
|
|
345
|
+
total_return_pct: float
|
|
346
|
+
|
|
347
|
+
class Portfolio:
|
|
348
|
+
r"""
|
|
349
|
+
投资组合管理
|
|
350
|
+
|
|
351
|
+
:ivar cash: 当前现金余额
|
|
352
|
+
:ivar positions: 当前持仓 (symbol -> quantity)
|
|
353
|
+
:ivar available_positions: 可用持仓 (symbol -> quantity)
|
|
354
|
+
"""
|
|
355
|
+
|
|
356
|
+
...
|
|
357
|
+
|
|
358
|
+
class StrategyContext:
|
|
359
|
+
r"""
|
|
360
|
+
策略上下文
|
|
361
|
+
|
|
362
|
+
:ivar orders: 订单列表 (内部使用)
|
|
363
|
+
:ivar cash: 当前现金
|
|
364
|
+
:ivar positions: 当前持仓
|
|
365
|
+
:ivar available_positions: 可用持仓
|
|
366
|
+
:ivar session: 当前交易时段
|
|
367
|
+
"""
|
|
368
|
+
|
|
369
|
+
orders: list[Order]
|
|
370
|
+
active_orders: list[Order]
|
|
371
|
+
session: akquant.TradingSession
|
|
372
|
+
cash: float
|
|
373
|
+
positions: dict[str, float]
|
|
374
|
+
available_positions: dict[str, float]
|
|
375
|
+
def __new__(
|
|
376
|
+
cls,
|
|
377
|
+
cash: typing.Any,
|
|
378
|
+
positions: typing.Mapping[str, float],
|
|
379
|
+
available_positions: typing.Mapping[str, float],
|
|
380
|
+
session: typing.Optional[akquant.TradingSession],
|
|
381
|
+
active_orders: typing.Optional[typing.Sequence[Order]],
|
|
382
|
+
): ...
|
|
383
|
+
def schedule(self, timestamp: int, payload: str) -> None:
|
|
384
|
+
r"""
|
|
385
|
+
注册定时器
|
|
386
|
+
|
|
387
|
+
:param timestamp: 触发时间戳 (秒)
|
|
388
|
+
:param payload: 携带的数据 (如回调函数名)
|
|
389
|
+
"""
|
|
390
|
+
...
|
|
391
|
+
|
|
392
|
+
def buy(
|
|
393
|
+
self, symbol, quantity, price=..., time_in_force=..., trigger_price=...
|
|
394
|
+
) -> None: ...
|
|
395
|
+
def sell(
|
|
396
|
+
self, symbol, quantity, price=..., time_in_force=..., trigger_price=...
|
|
397
|
+
) -> None: ...
|
|
398
|
+
def get_position(self, symbol: str) -> float: ...
|
|
399
|
+
def get_available_position(self, symbol: str) -> float: ...
|
|
400
|
+
def cancel_order(self, order_id: str) -> None:
|
|
401
|
+
"""
|
|
402
|
+
取消订单
|
|
403
|
+
|
|
404
|
+
:param order_id: 订单 ID
|
|
405
|
+
"""
|
|
406
|
+
...
|
|
407
|
+
|
|
408
|
+
class Tick:
|
|
409
|
+
r"""
|
|
410
|
+
Tick 数据结构
|
|
411
|
+
|
|
412
|
+
:ivar timestamp: Unix 时间戳 (纳秒)
|
|
413
|
+
:ivar price: 最新价
|
|
414
|
+
:ivar volume: 成交量
|
|
415
|
+
:ivar symbol: 标的代码
|
|
416
|
+
"""
|
|
417
|
+
|
|
418
|
+
timestamp: int
|
|
419
|
+
symbol: str
|
|
420
|
+
price: float
|
|
421
|
+
volume: float
|
|
422
|
+
def __new__(
|
|
423
|
+
cls, timestamp: typing.Any, price: typing.Any, volume: typing.Any, symbol: str
|
|
424
|
+
): ...
|
|
425
|
+
def set_price(self, value: typing.Any) -> None: ...
|
|
426
|
+
def set_volume(self, value: typing.Any) -> None: ...
|
|
427
|
+
def __repr__(self) -> str: ...
|
|
428
|
+
|
|
429
|
+
class Trade:
|
|
430
|
+
r"""
|
|
431
|
+
成交记录
|
|
432
|
+
|
|
433
|
+
:ivar id: 成交ID
|
|
434
|
+
:ivar order_id: 订单ID
|
|
435
|
+
:ivar symbol: 标的代码
|
|
436
|
+
:ivar side: 交易方向
|
|
437
|
+
:ivar quantity: 成交数量
|
|
438
|
+
:ivar price: 成交价格
|
|
439
|
+
:ivar commission: 手续费
|
|
440
|
+
:ivar timestamp: Unix 时间戳
|
|
441
|
+
"""
|
|
442
|
+
|
|
443
|
+
id: str
|
|
444
|
+
order_id: str
|
|
445
|
+
symbol: str
|
|
446
|
+
side: akquant.OrderSide
|
|
447
|
+
timestamp: int
|
|
448
|
+
bar_index: int
|
|
449
|
+
quantity: float
|
|
450
|
+
price: float
|
|
451
|
+
commission: float
|
|
452
|
+
def __new__(
|
|
453
|
+
cls,
|
|
454
|
+
id: str,
|
|
455
|
+
order_id: str,
|
|
456
|
+
symbol: str,
|
|
457
|
+
side: akquant.OrderSide,
|
|
458
|
+
quantity: typing.Any,
|
|
459
|
+
price: typing.Any,
|
|
460
|
+
commission: typing.Any,
|
|
461
|
+
timestamp: int,
|
|
462
|
+
bar_index: int,
|
|
463
|
+
): ...
|
|
464
|
+
def __repr__(self) -> str: ...
|
|
465
|
+
|
|
466
|
+
class TradeAnalyzer: ...
|
|
467
|
+
|
|
468
|
+
class TradePnL:
|
|
469
|
+
r"""
|
|
470
|
+
交易盈亏统计 (FIFO)
|
|
471
|
+
"""
|
|
472
|
+
|
|
473
|
+
gross_pnl: float
|
|
474
|
+
net_pnl: float
|
|
475
|
+
total_commission: float
|
|
476
|
+
total_closed_trades: int
|
|
477
|
+
won_count: int
|
|
478
|
+
lost_count: int
|
|
479
|
+
won_pnl: float
|
|
480
|
+
lost_pnl: float
|
|
481
|
+
win_rate: float
|
|
482
|
+
loss_rate: float
|
|
483
|
+
unrealized_pnl: float
|
|
484
|
+
avg_pnl: float
|
|
485
|
+
avg_return_pct: float
|
|
486
|
+
avg_trade_bars: float
|
|
487
|
+
avg_profit: float
|
|
488
|
+
avg_profit_pct: float
|
|
489
|
+
avg_winning_trade_bars: float
|
|
490
|
+
avg_loss: float
|
|
491
|
+
avg_loss_pct: float
|
|
492
|
+
avg_losing_trade_bars: float
|
|
493
|
+
largest_win: float
|
|
494
|
+
largest_win_pct: float
|
|
495
|
+
largest_win_bars: float
|
|
496
|
+
largest_loss: float
|
|
497
|
+
largest_loss_pct: float
|
|
498
|
+
largest_loss_bars: float
|
|
499
|
+
max_wins: int
|
|
500
|
+
max_losses: int
|
|
501
|
+
profit_factor: float
|
|
502
|
+
total_profit: float
|
|
503
|
+
total_loss: float
|
|
504
|
+
|
|
505
|
+
def from_arrays(
|
|
506
|
+
timestamps: typing.Sequence[int],
|
|
507
|
+
opens: typing.Sequence[float],
|
|
508
|
+
highs: typing.Sequence[float],
|
|
509
|
+
lows: typing.Sequence[float],
|
|
510
|
+
closes: typing.Sequence[float],
|
|
511
|
+
volumes: typing.Sequence[float],
|
|
512
|
+
symbol: typing.Optional[str],
|
|
513
|
+
symbols: typing.Optional[typing.Sequence[str]],
|
|
514
|
+
) -> list[Bar]:
|
|
515
|
+
r"""
|
|
516
|
+
从数组批量创建 Bar 列表 (Python 优化用)
|
|
517
|
+
"""
|
|
518
|
+
...
|