akquant 0.1.4__cp310-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 +98 -0
- akquant/akquant.pyd +0 -0
- akquant/akquant.pyi +683 -0
- akquant/backtest.py +659 -0
- akquant/config.py +65 -0
- akquant/data.py +136 -0
- akquant/indicator.py +81 -0
- akquant/log.py +135 -0
- akquant/ml/__init__.py +3 -0
- akquant/ml/model.py +234 -0
- akquant/py.typed +0 -0
- akquant/risk.py +40 -0
- akquant/sizer.py +96 -0
- akquant/strategy.py +824 -0
- akquant/utils.py +386 -0
- akquant-0.1.4.dist-info/METADATA +219 -0
- akquant-0.1.4.dist-info/RECORD +19 -0
- akquant-0.1.4.dist-info/WHEEL +4 -0
- akquant-0.1.4.dist-info/licenses/LICENSE +21 -0
akquant/akquant.pyi
ADDED
|
@@ -0,0 +1,683 @@
|
|
|
1
|
+
# This file is automatically generated by pyo3_stub_gen
|
|
2
|
+
# ruff: noqa: E501, F401
|
|
3
|
+
|
|
4
|
+
import typing
|
|
5
|
+
|
|
6
|
+
import numpy
|
|
7
|
+
import numpy.typing
|
|
8
|
+
|
|
9
|
+
# Enums
|
|
10
|
+
class AssetType:
|
|
11
|
+
Stock: "AssetType"
|
|
12
|
+
Fund: "AssetType"
|
|
13
|
+
Futures: "AssetType"
|
|
14
|
+
Option: "AssetType"
|
|
15
|
+
|
|
16
|
+
class OptionType:
|
|
17
|
+
Call: "OptionType"
|
|
18
|
+
Put: "OptionType"
|
|
19
|
+
|
|
20
|
+
class OrderType:
|
|
21
|
+
Market: "OrderType"
|
|
22
|
+
Limit: "OrderType"
|
|
23
|
+
StopMarket: "OrderType"
|
|
24
|
+
StopLimit: "OrderType"
|
|
25
|
+
|
|
26
|
+
class OrderSide:
|
|
27
|
+
Buy: "OrderSide"
|
|
28
|
+
Sell: "OrderSide"
|
|
29
|
+
|
|
30
|
+
class OrderStatus:
|
|
31
|
+
New: "OrderStatus"
|
|
32
|
+
Submitted: "OrderStatus"
|
|
33
|
+
Filled: "OrderStatus"
|
|
34
|
+
Cancelled: "OrderStatus"
|
|
35
|
+
Rejected: "OrderStatus"
|
|
36
|
+
Expired: "OrderStatus"
|
|
37
|
+
|
|
38
|
+
class TimeInForce:
|
|
39
|
+
GTC: "TimeInForce"
|
|
40
|
+
IOC: "TimeInForce"
|
|
41
|
+
FOK: "TimeInForce"
|
|
42
|
+
Day: "TimeInForce"
|
|
43
|
+
|
|
44
|
+
class ExecutionMode:
|
|
45
|
+
CurrentClose: "ExecutionMode"
|
|
46
|
+
NextOpen: "ExecutionMode"
|
|
47
|
+
|
|
48
|
+
class TradingSession:
|
|
49
|
+
PreOpen: "TradingSession"
|
|
50
|
+
Continuous: "TradingSession"
|
|
51
|
+
CallAuction: "TradingSession"
|
|
52
|
+
Break: "TradingSession"
|
|
53
|
+
Closed: "TradingSession"
|
|
54
|
+
PostClose: "TradingSession"
|
|
55
|
+
|
|
56
|
+
class ATR:
|
|
57
|
+
r"""Average True Range."""
|
|
58
|
+
|
|
59
|
+
value: typing.Optional[float]
|
|
60
|
+
def __new__(cls, period: int) -> "ATR": ...
|
|
61
|
+
def update(
|
|
62
|
+
self, high: float, low: float, close: float
|
|
63
|
+
) -> typing.Optional[float]: ...
|
|
64
|
+
|
|
65
|
+
class BacktestResult:
|
|
66
|
+
r"""回测结果."""
|
|
67
|
+
|
|
68
|
+
equity_curve: list[tuple[int, float]]
|
|
69
|
+
metrics: "PerformanceMetrics"
|
|
70
|
+
trade_metrics: "TradePnL"
|
|
71
|
+
trades: list["ClosedTrade"]
|
|
72
|
+
daily_positions: list[tuple[int, dict[str, float]]]
|
|
73
|
+
|
|
74
|
+
class Bar:
|
|
75
|
+
r"""
|
|
76
|
+
K线数据结构.
|
|
77
|
+
|
|
78
|
+
:ivar timestamp: Unix 时间戳 (纳秒)
|
|
79
|
+
:ivar open: 开盘价
|
|
80
|
+
:ivar high: 最高价
|
|
81
|
+
:ivar low: 最低价
|
|
82
|
+
:ivar close: 收盘价
|
|
83
|
+
:ivar volume: 成交量
|
|
84
|
+
:ivar symbol: 标的代码
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
timestamp: int
|
|
88
|
+
symbol: str
|
|
89
|
+
extra: dict[str, float]
|
|
90
|
+
open: float
|
|
91
|
+
high: float
|
|
92
|
+
low: float
|
|
93
|
+
close: float
|
|
94
|
+
volume: float
|
|
95
|
+
def __new__(
|
|
96
|
+
cls,
|
|
97
|
+
timestamp: int,
|
|
98
|
+
open: float,
|
|
99
|
+
high: float,
|
|
100
|
+
low: float,
|
|
101
|
+
close: float,
|
|
102
|
+
volume: float,
|
|
103
|
+
symbol: str,
|
|
104
|
+
extra: typing.Optional[dict[str, float]] = ...,
|
|
105
|
+
) -> "Bar": ...
|
|
106
|
+
def set_open(self, value: typing.Any) -> None: ...
|
|
107
|
+
def set_high(self, value: typing.Any) -> None: ...
|
|
108
|
+
def set_low(self, value: typing.Any) -> None: ...
|
|
109
|
+
def set_close(self, value: typing.Any) -> None: ...
|
|
110
|
+
def set_volume(self, value: typing.Any) -> None: ...
|
|
111
|
+
def __repr__(self) -> str: ...
|
|
112
|
+
|
|
113
|
+
class BollingerBands:
|
|
114
|
+
r"""Bollinger Bands."""
|
|
115
|
+
|
|
116
|
+
value: typing.Optional[tuple[float, float, float]]
|
|
117
|
+
def __new__(cls, period: int, multiplier: float) -> "BollingerBands": ...
|
|
118
|
+
def update(self, value: float) -> typing.Optional[tuple[float, float, float]]:
|
|
119
|
+
r"""Return (upper, middle, lower)."""
|
|
120
|
+
...
|
|
121
|
+
|
|
122
|
+
class ClosedTrade:
|
|
123
|
+
r"""平仓交易记录."""
|
|
124
|
+
|
|
125
|
+
symbol: str
|
|
126
|
+
entry_time: int
|
|
127
|
+
exit_time: int
|
|
128
|
+
entry_price: float
|
|
129
|
+
exit_price: float
|
|
130
|
+
quantity: float
|
|
131
|
+
direction: str
|
|
132
|
+
pnl: float
|
|
133
|
+
net_pnl: float
|
|
134
|
+
return_pct: float
|
|
135
|
+
commission: float
|
|
136
|
+
duration_bars: int
|
|
137
|
+
|
|
138
|
+
class DataFeed:
|
|
139
|
+
def sort(self) -> None: ...
|
|
140
|
+
def add_bars(self, bars: typing.Sequence[Bar]) -> None: ...
|
|
141
|
+
|
|
142
|
+
class EMA:
|
|
143
|
+
r"""Exponential Moving Average."""
|
|
144
|
+
|
|
145
|
+
value: typing.Optional[float]
|
|
146
|
+
is_ready: bool
|
|
147
|
+
period: int
|
|
148
|
+
def __new__(cls, period: int) -> "EMA": ...
|
|
149
|
+
def update(self, value: float) -> typing.Optional[float]: ...
|
|
150
|
+
|
|
151
|
+
class Engine:
|
|
152
|
+
r"""
|
|
153
|
+
主回测引擎.
|
|
154
|
+
|
|
155
|
+
:ivar feed: 数据源
|
|
156
|
+
:ivar portfolio: 投资组合
|
|
157
|
+
:ivar orders: 订单列表
|
|
158
|
+
:ivar trades: 成交列表
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
portfolio: "Portfolio"
|
|
162
|
+
orders: list["Order"]
|
|
163
|
+
trades: list["Trade"]
|
|
164
|
+
risk_manager: "RiskManager"
|
|
165
|
+
def __new__(
|
|
166
|
+
cls,
|
|
167
|
+
) -> "Engine": ...
|
|
168
|
+
def set_history_depth(self, depth: int) -> None:
|
|
169
|
+
r"""
|
|
170
|
+
设置历史数据长度.
|
|
171
|
+
|
|
172
|
+
:param depth: 历史数据长度
|
|
173
|
+
"""
|
|
174
|
+
...
|
|
175
|
+
|
|
176
|
+
def set_timezone(self, offset: int) -> None:
|
|
177
|
+
r"""
|
|
178
|
+
设置时区偏移 (秒).
|
|
179
|
+
|
|
180
|
+
:param offset: 偏移秒数 (例如 UTC+8 为 28800)
|
|
181
|
+
"""
|
|
182
|
+
...
|
|
183
|
+
|
|
184
|
+
def use_simulated_execution(self) -> None:
|
|
185
|
+
r"""
|
|
186
|
+
启用模拟执行 (回测模式).
|
|
187
|
+
|
|
188
|
+
默认模式。在内存中撮合订单。
|
|
189
|
+
"""
|
|
190
|
+
...
|
|
191
|
+
|
|
192
|
+
def use_realtime_execution(self) -> None:
|
|
193
|
+
r"""
|
|
194
|
+
启用实盘执行 (CTP/Broker 模式).
|
|
195
|
+
|
|
196
|
+
模拟对接 CTP 或其他 Broker API。
|
|
197
|
+
在此模式下,订单会被标记为 Submitted 并等待回调 (目前仅模拟发送)。
|
|
198
|
+
"""
|
|
199
|
+
...
|
|
200
|
+
|
|
201
|
+
def set_execution_mode(self, mode: "ExecutionMode") -> None:
|
|
202
|
+
r"""
|
|
203
|
+
设置撮合模式.
|
|
204
|
+
|
|
205
|
+
:param mode: 撮合模式 (ExecutionMode.CurrentClose 或 ExecutionMode.NextOpen)
|
|
206
|
+
:type mode: ExecutionMode
|
|
207
|
+
"""
|
|
208
|
+
...
|
|
209
|
+
|
|
210
|
+
def use_simple_market(self, commission_rate: float) -> None:
|
|
211
|
+
r"""
|
|
212
|
+
启用 SimpleMarket (7x24小时, T+0, 无税, 简单佣金).
|
|
213
|
+
|
|
214
|
+
:param commission_rate: 佣金率
|
|
215
|
+
"""
|
|
216
|
+
...
|
|
217
|
+
|
|
218
|
+
def use_china_market(self) -> None:
|
|
219
|
+
r"""启用 ChinaMarket (支持 T+1/T+0, 印花税, 过户费, 交易时段等)."""
|
|
220
|
+
...
|
|
221
|
+
|
|
222
|
+
def use_china_futures_market(self) -> None:
|
|
223
|
+
r"""
|
|
224
|
+
启用中国期货市场默认配置.
|
|
225
|
+
|
|
226
|
+
- 切换到 ChinaMarket
|
|
227
|
+
- 设置 T+0
|
|
228
|
+
- 保持当前交易时段配置 (需手动设置 set_market_sessions 以匹配特定品种)
|
|
229
|
+
"""
|
|
230
|
+
...
|
|
231
|
+
|
|
232
|
+
def set_t_plus_one(self, enabled: bool) -> None:
|
|
233
|
+
r"""
|
|
234
|
+
启用/禁用 T+1 交易规则 (仅针对 ChinaMarket).
|
|
235
|
+
|
|
236
|
+
:param enabled: 是否启用 T+1
|
|
237
|
+
:type enabled: bool
|
|
238
|
+
"""
|
|
239
|
+
...
|
|
240
|
+
|
|
241
|
+
def set_force_session_continuous(self, enabled: bool) -> None: ...
|
|
242
|
+
def set_stock_fee_rules(
|
|
243
|
+
self,
|
|
244
|
+
commission_rate: float,
|
|
245
|
+
stamp_tax: float,
|
|
246
|
+
transfer_fee: float,
|
|
247
|
+
min_commission: float,
|
|
248
|
+
) -> None: ...
|
|
249
|
+
def set_future_fee_rules(self, commission_rate: float) -> None: ...
|
|
250
|
+
def set_fund_fee_rules(
|
|
251
|
+
self, commission_rate: float, transfer_fee: float, min_commission: float
|
|
252
|
+
) -> None: ...
|
|
253
|
+
def set_option_fee_rules(self, commission_per_contract: float) -> None: ...
|
|
254
|
+
def set_slippage(self, type_: str, value: float) -> None:
|
|
255
|
+
r"""
|
|
256
|
+
设置滑点模型.
|
|
257
|
+
|
|
258
|
+
:param type: 滑点类型 ("fixed" 或 "percent")
|
|
259
|
+
:param value: 滑点值 (固定金额 或 百分比如 0.001)
|
|
260
|
+
"""
|
|
261
|
+
...
|
|
262
|
+
|
|
263
|
+
def set_volume_limit(self, limit: float) -> None:
|
|
264
|
+
r"""
|
|
265
|
+
设置成交量限制.
|
|
266
|
+
|
|
267
|
+
:param limit: 限制比例 (0.0-1.0), 0.0 为不限制
|
|
268
|
+
"""
|
|
269
|
+
...
|
|
270
|
+
|
|
271
|
+
def set_market_sessions(
|
|
272
|
+
self, sessions: typing.Sequence[tuple[str, str, "TradingSession"]]
|
|
273
|
+
) -> None: ...
|
|
274
|
+
def add_instrument(self, instrument: "Instrument") -> None:
|
|
275
|
+
r"""
|
|
276
|
+
添加交易标的.
|
|
277
|
+
|
|
278
|
+
:param instrument: 交易标的对象
|
|
279
|
+
:type instrument: Instrument
|
|
280
|
+
"""
|
|
281
|
+
...
|
|
282
|
+
|
|
283
|
+
def set_cash(self, cash: float) -> None:
|
|
284
|
+
r"""
|
|
285
|
+
设置初始资金.
|
|
286
|
+
|
|
287
|
+
:param cash: 初始资金数额
|
|
288
|
+
:type cash: float
|
|
289
|
+
"""
|
|
290
|
+
...
|
|
291
|
+
|
|
292
|
+
def add_data(self, feed: DataFeed) -> None:
|
|
293
|
+
r"""
|
|
294
|
+
添加数据源.
|
|
295
|
+
|
|
296
|
+
:param feed: 数据源对象
|
|
297
|
+
:type feed: DataFeed
|
|
298
|
+
"""
|
|
299
|
+
...
|
|
300
|
+
|
|
301
|
+
def add_bars(self, bars: typing.Sequence[Bar]) -> None:
|
|
302
|
+
r"""
|
|
303
|
+
批量添加 K 线数据.
|
|
304
|
+
|
|
305
|
+
:param bars: K 线列表
|
|
306
|
+
"""
|
|
307
|
+
...
|
|
308
|
+
|
|
309
|
+
def run(self, strategy: typing.Any, show_progress: bool) -> str:
|
|
310
|
+
r"""
|
|
311
|
+
运行回测.
|
|
312
|
+
|
|
313
|
+
:param strategy: 策略对象
|
|
314
|
+
:param show_progress: 是否显示进度条
|
|
315
|
+
:type strategy: object
|
|
316
|
+
:type show_progress: bool
|
|
317
|
+
:return: 回测结果摘要
|
|
318
|
+
:rtype: str
|
|
319
|
+
"""
|
|
320
|
+
...
|
|
321
|
+
|
|
322
|
+
def get_results(self) -> "BacktestResult":
|
|
323
|
+
r"""
|
|
324
|
+
获取回测结果.
|
|
325
|
+
|
|
326
|
+
:return: BacktestResult
|
|
327
|
+
"""
|
|
328
|
+
...
|
|
329
|
+
|
|
330
|
+
def create_context(
|
|
331
|
+
self, active_orders: typing.Sequence["Order"]
|
|
332
|
+
) -> "StrategyContext": ...
|
|
333
|
+
|
|
334
|
+
class Instrument:
|
|
335
|
+
r"""
|
|
336
|
+
交易标的.
|
|
337
|
+
|
|
338
|
+
:ivar symbol: 代码
|
|
339
|
+
:ivar asset_type: 资产类型
|
|
340
|
+
:ivar multiplier: 合约乘数
|
|
341
|
+
:ivar margin_ratio: 保证金比率
|
|
342
|
+
:ivar tick_size: 最小变动价位
|
|
343
|
+
"""
|
|
344
|
+
|
|
345
|
+
symbol: str
|
|
346
|
+
asset_type: "AssetType"
|
|
347
|
+
multiplier: float
|
|
348
|
+
margin_ratio: float
|
|
349
|
+
tick_size: float
|
|
350
|
+
def __new__(
|
|
351
|
+
cls,
|
|
352
|
+
symbol: str,
|
|
353
|
+
asset_type: "AssetType",
|
|
354
|
+
multiplier: typing.Any,
|
|
355
|
+
margin_ratio: typing.Any,
|
|
356
|
+
tick_size: typing.Any,
|
|
357
|
+
option_type: typing.Optional["OptionType"],
|
|
358
|
+
strike_price: typing.Optional[typing.Any],
|
|
359
|
+
expiry_date: typing.Optional[int],
|
|
360
|
+
lot_size: typing.Optional[typing.Any],
|
|
361
|
+
) -> "Instrument": ...
|
|
362
|
+
|
|
363
|
+
class MACD:
|
|
364
|
+
r"""Moving Average Convergence Divergence."""
|
|
365
|
+
|
|
366
|
+
value: typing.Optional[tuple[float, float, float]]
|
|
367
|
+
def __new__(
|
|
368
|
+
cls, fast_period: int, slow_period: int, signal_period: int
|
|
369
|
+
) -> "MACD": ...
|
|
370
|
+
def update(self, value: float) -> typing.Optional[tuple[float, float, float]]:
|
|
371
|
+
r"""Return (macd_line, signal_line, histogram)."""
|
|
372
|
+
...
|
|
373
|
+
|
|
374
|
+
class Order:
|
|
375
|
+
r"""
|
|
376
|
+
订单.
|
|
377
|
+
|
|
378
|
+
:ivar id: 订单ID
|
|
379
|
+
:ivar symbol: 标的代码
|
|
380
|
+
:ivar side: 交易方向
|
|
381
|
+
:ivar order_type: 订单类型
|
|
382
|
+
:ivar quantity: 数量
|
|
383
|
+
:ivar price: 价格 (限价单有效)
|
|
384
|
+
:ivar time_in_force: 订单有效期
|
|
385
|
+
:ivar trigger_price: 触发价格 (止损/止盈单)
|
|
386
|
+
:ivar status: 订单状态
|
|
387
|
+
:ivar filled_quantity: 已成交数量
|
|
388
|
+
:ivar average_filled_price: 成交均价
|
|
389
|
+
"""
|
|
390
|
+
|
|
391
|
+
id: str
|
|
392
|
+
symbol: str
|
|
393
|
+
side: "OrderSide"
|
|
394
|
+
order_type: "OrderType"
|
|
395
|
+
time_in_force: "TimeInForce"
|
|
396
|
+
status: "OrderStatus"
|
|
397
|
+
quantity: float
|
|
398
|
+
price: typing.Optional[float]
|
|
399
|
+
trigger_price: typing.Optional[float]
|
|
400
|
+
filled_quantity: float
|
|
401
|
+
average_filled_price: typing.Optional[float]
|
|
402
|
+
def __new__(
|
|
403
|
+
cls,
|
|
404
|
+
id: str,
|
|
405
|
+
symbol: str,
|
|
406
|
+
side: "OrderSide",
|
|
407
|
+
order_type: "OrderType",
|
|
408
|
+
quantity: float,
|
|
409
|
+
price: typing.Optional[float] = ...,
|
|
410
|
+
time_in_force: "TimeInForce" = ...,
|
|
411
|
+
trigger_price: typing.Optional[float] = ...,
|
|
412
|
+
) -> "Order": ...
|
|
413
|
+
def __repr__(self) -> str: ...
|
|
414
|
+
|
|
415
|
+
class PerformanceMetrics:
|
|
416
|
+
r"""绩效指标."""
|
|
417
|
+
|
|
418
|
+
total_return: float
|
|
419
|
+
annualized_return: float
|
|
420
|
+
max_drawdown: float
|
|
421
|
+
max_drawdown_pct: float
|
|
422
|
+
sharpe_ratio: float
|
|
423
|
+
sortino_ratio: float
|
|
424
|
+
volatility: float
|
|
425
|
+
ulcer_index: float
|
|
426
|
+
upi: float
|
|
427
|
+
equity_r2: float
|
|
428
|
+
std_error: float
|
|
429
|
+
win_rate: float
|
|
430
|
+
initial_market_value: float
|
|
431
|
+
end_market_value: float
|
|
432
|
+
total_return_pct: float
|
|
433
|
+
|
|
434
|
+
class Portfolio:
|
|
435
|
+
r"""
|
|
436
|
+
投资组合管理.
|
|
437
|
+
|
|
438
|
+
:ivar cash: 当前现金余额
|
|
439
|
+
:ivar positions: 当前持仓 (symbol -> quantity)
|
|
440
|
+
:ivar available_positions: 可用持仓 (symbol -> quantity)
|
|
441
|
+
"""
|
|
442
|
+
|
|
443
|
+
cash: float
|
|
444
|
+
positions: dict[str, float]
|
|
445
|
+
available_positions: dict[str, float]
|
|
446
|
+
def __new__(cls, cash: typing.Any) -> "Portfolio": ...
|
|
447
|
+
def get_position(self, symbol: str) -> float: ...
|
|
448
|
+
def get_available_position(self, symbol: str) -> float: ...
|
|
449
|
+
def __repr__(self) -> str: ...
|
|
450
|
+
|
|
451
|
+
class RSI:
|
|
452
|
+
r"""Relative Strength Index."""
|
|
453
|
+
|
|
454
|
+
value: typing.Optional[float]
|
|
455
|
+
def __new__(cls, period: int) -> "RSI": ...
|
|
456
|
+
def update(self, value: float) -> typing.Optional[float]: ...
|
|
457
|
+
|
|
458
|
+
class RiskConfig:
|
|
459
|
+
r"""
|
|
460
|
+
风控配置.
|
|
461
|
+
|
|
462
|
+
:ivar max_order_size: 单笔最大下单数量
|
|
463
|
+
:ivar max_order_value: 单笔最大下单金额
|
|
464
|
+
:ivar max_position_size: 最大持仓数量 (绝对值)
|
|
465
|
+
:ivar restricted_list: 限制交易标的列表
|
|
466
|
+
:ivar active: 是否启用风控
|
|
467
|
+
"""
|
|
468
|
+
|
|
469
|
+
max_order_size: typing.Optional[float]
|
|
470
|
+
max_order_value: typing.Optional[float]
|
|
471
|
+
max_position_size: typing.Optional[float]
|
|
472
|
+
restricted_list: list[str]
|
|
473
|
+
active: bool
|
|
474
|
+
def __new__(cls) -> "RiskConfig": ...
|
|
475
|
+
|
|
476
|
+
class RiskManager:
|
|
477
|
+
r"""
|
|
478
|
+
风控管理器.
|
|
479
|
+
|
|
480
|
+
:ivar config: 风控配置
|
|
481
|
+
"""
|
|
482
|
+
|
|
483
|
+
config: RiskConfig
|
|
484
|
+
def check(
|
|
485
|
+
self,
|
|
486
|
+
order: "Order",
|
|
487
|
+
portfolio: "Portfolio",
|
|
488
|
+
instruments: dict[str, "Instrument"],
|
|
489
|
+
active_orders: list["Order"],
|
|
490
|
+
) -> typing.Optional[str]: ...
|
|
491
|
+
|
|
492
|
+
class SMA:
|
|
493
|
+
r"""Simple Moving Average."""
|
|
494
|
+
|
|
495
|
+
value: typing.Optional[float]
|
|
496
|
+
is_ready: bool
|
|
497
|
+
def __new__(cls, period: int) -> "SMA": ...
|
|
498
|
+
def update(self, value: float) -> typing.Optional[float]: ...
|
|
499
|
+
|
|
500
|
+
class StrategyContext:
|
|
501
|
+
r"""
|
|
502
|
+
策略上下文.
|
|
503
|
+
|
|
504
|
+
:ivar orders: 订单列表 (内部使用)
|
|
505
|
+
:ivar cash: 当前现金
|
|
506
|
+
:ivar positions: 当前持仓
|
|
507
|
+
:ivar available_positions: 可用持仓
|
|
508
|
+
:ivar session: 当前交易时段
|
|
509
|
+
"""
|
|
510
|
+
|
|
511
|
+
orders: list[Order]
|
|
512
|
+
canceled_order_ids: list[str]
|
|
513
|
+
active_orders: list[Order]
|
|
514
|
+
session: "TradingSession"
|
|
515
|
+
last_closed_trade: typing.Optional[ClosedTrade]
|
|
516
|
+
closed_trades: list[ClosedTrade]
|
|
517
|
+
cash: float
|
|
518
|
+
positions: dict[str, float]
|
|
519
|
+
available_positions: dict[str, float]
|
|
520
|
+
def __new__(
|
|
521
|
+
cls,
|
|
522
|
+
cash: typing.Any,
|
|
523
|
+
positions: typing.Mapping[str, float],
|
|
524
|
+
available_positions: typing.Mapping[str, float],
|
|
525
|
+
session: typing.Optional["TradingSession"],
|
|
526
|
+
active_orders: typing.Optional[typing.Sequence[Order]],
|
|
527
|
+
closed_trades: typing.Optional[typing.Sequence[ClosedTrade]],
|
|
528
|
+
) -> "StrategyContext": ...
|
|
529
|
+
def history(
|
|
530
|
+
self, symbol: str, field: str, count: int
|
|
531
|
+
) -> typing.Optional[numpy.typing.NDArray[numpy.float64]]:
|
|
532
|
+
r"""
|
|
533
|
+
获取历史数据.
|
|
534
|
+
|
|
535
|
+
:param symbol: 标的代码
|
|
536
|
+
:param field: 字段名 (open, high, low, close, volume)
|
|
537
|
+
:param count: 获取的数据长度
|
|
538
|
+
:return: numpy array or None
|
|
539
|
+
"""
|
|
540
|
+
...
|
|
541
|
+
|
|
542
|
+
def schedule(self, timestamp: int, payload: str) -> None:
|
|
543
|
+
r"""
|
|
544
|
+
注册定时器.
|
|
545
|
+
|
|
546
|
+
:param timestamp: 触发时间戳 (纳秒)
|
|
547
|
+
:param payload: 携带的数据 (如回调函数名)
|
|
548
|
+
"""
|
|
549
|
+
...
|
|
550
|
+
|
|
551
|
+
def cancel_order(self, order_id: str) -> None:
|
|
552
|
+
r"""
|
|
553
|
+
取消订单.
|
|
554
|
+
|
|
555
|
+
:param order_id: 订单 ID
|
|
556
|
+
"""
|
|
557
|
+
...
|
|
558
|
+
|
|
559
|
+
def buy(
|
|
560
|
+
self,
|
|
561
|
+
symbol: str,
|
|
562
|
+
quantity: float,
|
|
563
|
+
price: typing.Optional[float] = ...,
|
|
564
|
+
time_in_force: typing.Optional["TimeInForce"] = ...,
|
|
565
|
+
trigger_price: typing.Optional[float] = ...,
|
|
566
|
+
) -> None: ...
|
|
567
|
+
def sell(
|
|
568
|
+
self,
|
|
569
|
+
symbol: str,
|
|
570
|
+
quantity: float,
|
|
571
|
+
price: typing.Optional[float] = ...,
|
|
572
|
+
time_in_force: typing.Optional["TimeInForce"] = ...,
|
|
573
|
+
trigger_price: typing.Optional[float] = ...,
|
|
574
|
+
) -> None: ...
|
|
575
|
+
def get_position(self, symbol: str) -> float: ...
|
|
576
|
+
def get_available_position(self, symbol: str) -> float: ...
|
|
577
|
+
|
|
578
|
+
class Tick:
|
|
579
|
+
r"""
|
|
580
|
+
Tick 数据结构.
|
|
581
|
+
|
|
582
|
+
:ivar timestamp: Unix 时间戳 (纳秒)
|
|
583
|
+
:ivar price: 最新价
|
|
584
|
+
:ivar volume: 成交量
|
|
585
|
+
:ivar symbol: 标的代码
|
|
586
|
+
"""
|
|
587
|
+
|
|
588
|
+
timestamp: int
|
|
589
|
+
symbol: str
|
|
590
|
+
price: float
|
|
591
|
+
volume: float
|
|
592
|
+
def __new__(
|
|
593
|
+
cls, timestamp: typing.Any, price: typing.Any, volume: typing.Any, symbol: str
|
|
594
|
+
) -> "Tick": ...
|
|
595
|
+
def set_price(self, value: typing.Any) -> None: ...
|
|
596
|
+
def set_volume(self, value: typing.Any) -> None: ...
|
|
597
|
+
def __repr__(self) -> str: ...
|
|
598
|
+
|
|
599
|
+
class Trade:
|
|
600
|
+
r"""
|
|
601
|
+
成交记录.
|
|
602
|
+
|
|
603
|
+
:ivar id: 成交ID
|
|
604
|
+
:ivar order_id: 订单ID
|
|
605
|
+
:ivar symbol: 标的代码
|
|
606
|
+
:ivar side: 交易方向
|
|
607
|
+
:ivar quantity: 成交数量
|
|
608
|
+
:ivar price: 成交价格
|
|
609
|
+
:ivar commission: 手续费
|
|
610
|
+
:ivar timestamp: Unix 时间戳 (纳秒)
|
|
611
|
+
"""
|
|
612
|
+
|
|
613
|
+
id: str
|
|
614
|
+
order_id: str
|
|
615
|
+
symbol: str
|
|
616
|
+
side: "OrderSide"
|
|
617
|
+
timestamp: int
|
|
618
|
+
bar_index: int
|
|
619
|
+
quantity: float
|
|
620
|
+
price: float
|
|
621
|
+
commission: float
|
|
622
|
+
def __new__(
|
|
623
|
+
cls,
|
|
624
|
+
id: str,
|
|
625
|
+
order_id: str,
|
|
626
|
+
symbol: str,
|
|
627
|
+
side: "OrderSide",
|
|
628
|
+
quantity: typing.Any,
|
|
629
|
+
price: typing.Any,
|
|
630
|
+
commission: typing.Any,
|
|
631
|
+
timestamp: int,
|
|
632
|
+
bar_index: int,
|
|
633
|
+
) -> "Trade": ...
|
|
634
|
+
def __repr__(self) -> str: ...
|
|
635
|
+
|
|
636
|
+
class TradePnL:
|
|
637
|
+
r"""交易盈亏统计 (FIFO)."""
|
|
638
|
+
|
|
639
|
+
gross_pnl: float
|
|
640
|
+
net_pnl: float
|
|
641
|
+
total_commission: float
|
|
642
|
+
total_closed_trades: int
|
|
643
|
+
won_count: int
|
|
644
|
+
lost_count: int
|
|
645
|
+
won_pnl: float
|
|
646
|
+
lost_pnl: float
|
|
647
|
+
win_rate: float
|
|
648
|
+
loss_rate: float
|
|
649
|
+
unrealized_pnl: float
|
|
650
|
+
avg_pnl: float
|
|
651
|
+
avg_return_pct: float
|
|
652
|
+
avg_trade_bars: float
|
|
653
|
+
avg_profit: float
|
|
654
|
+
avg_profit_pct: float
|
|
655
|
+
avg_winning_trade_bars: float
|
|
656
|
+
avg_loss: float
|
|
657
|
+
avg_loss_pct: float
|
|
658
|
+
avg_losing_trade_bars: float
|
|
659
|
+
largest_win: float
|
|
660
|
+
largest_win_pct: float
|
|
661
|
+
largest_win_bars: float
|
|
662
|
+
largest_loss: float
|
|
663
|
+
largest_loss_pct: float
|
|
664
|
+
largest_loss_bars: float
|
|
665
|
+
max_wins: int
|
|
666
|
+
max_losses: int
|
|
667
|
+
profit_factor: float
|
|
668
|
+
total_profit: float
|
|
669
|
+
total_loss: float
|
|
670
|
+
|
|
671
|
+
def from_arrays(
|
|
672
|
+
timestamps: typing.Any,
|
|
673
|
+
opens: typing.Any,
|
|
674
|
+
highs: typing.Any,
|
|
675
|
+
lows: typing.Any,
|
|
676
|
+
closes: typing.Any,
|
|
677
|
+
volumes: typing.Any,
|
|
678
|
+
symbol: typing.Optional[str],
|
|
679
|
+
symbols: typing.Optional[typing.Sequence[str]],
|
|
680
|
+
extra: typing.Optional[typing.Mapping[str, typing.Any]],
|
|
681
|
+
) -> list[Bar]:
|
|
682
|
+
r"""从数组批量创建 Bar 列表 (Python 优化用 - Zero Copy)."""
|
|
683
|
+
...
|