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/sizer.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from .akquant import StrategyContext
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Sizer(ABC):
|
|
9
|
+
"""
|
|
10
|
+
仓位管理基类 (Sizer Base Class).
|
|
11
|
+
|
|
12
|
+
用于计算下单数量.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def get_size(
|
|
17
|
+
self, price: float, cash: float, context: "StrategyContext", symbol: str
|
|
18
|
+
) -> float:
|
|
19
|
+
"""
|
|
20
|
+
计算下单数量.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
price (float): 当前价格
|
|
24
|
+
cash (float): 当前可用资金
|
|
25
|
+
context (StrategyContext): 策略上下文
|
|
26
|
+
symbol (str): 标的代码
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
float: 下单数量
|
|
30
|
+
"""
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class FixedSize(Sizer):
|
|
35
|
+
"""
|
|
36
|
+
固定数量 Sizer.
|
|
37
|
+
|
|
38
|
+
每次交易固定数量.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def __init__(self, size: float = 100.0):
|
|
42
|
+
"""
|
|
43
|
+
Initialize FixedSize.
|
|
44
|
+
|
|
45
|
+
:param size: The fixed size for each trade.
|
|
46
|
+
"""
|
|
47
|
+
self.size = size
|
|
48
|
+
|
|
49
|
+
def get_size(
|
|
50
|
+
self, price: float, cash: float, context: "StrategyContext", symbol: str
|
|
51
|
+
) -> float:
|
|
52
|
+
"""Return the fixed size."""
|
|
53
|
+
return self.size
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class PercentSizer(Sizer):
|
|
57
|
+
"""
|
|
58
|
+
百分比 Sizer.
|
|
59
|
+
|
|
60
|
+
使用当前资金的一定百分比买入.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def __init__(self, percents: float = 10.0):
|
|
64
|
+
"""
|
|
65
|
+
Initialize PercentSizer.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
percents (float): 资金百分比 (0-100).
|
|
69
|
+
"""
|
|
70
|
+
self.percents = percents
|
|
71
|
+
|
|
72
|
+
def get_size(
|
|
73
|
+
self, price: float, cash: float, context: "StrategyContext", symbol: str
|
|
74
|
+
) -> float:
|
|
75
|
+
"""Calculate order size based on percentage of cash."""
|
|
76
|
+
if price <= 0:
|
|
77
|
+
return 0.0
|
|
78
|
+
|
|
79
|
+
target_cash = cash * (self.percents / 100.0)
|
|
80
|
+
return int(target_cash / price)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class AllInSizer(Sizer):
|
|
84
|
+
"""
|
|
85
|
+
全仓 Sizer.
|
|
86
|
+
|
|
87
|
+
使用所有可用资金买入.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
def get_size(
|
|
91
|
+
self, price: float, cash: float, context: "StrategyContext", symbol: str
|
|
92
|
+
) -> float:
|
|
93
|
+
"""Calculate order size using all available cash."""
|
|
94
|
+
if price <= 0:
|
|
95
|
+
return 0.0
|
|
96
|
+
return int(cash / price)
|