-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfeatures_config.py
More file actions
200 lines (168 loc) · 7.22 KB
/
Copy pathfeatures_config.py
File metadata and controls
200 lines (168 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
"""
Features Configuration
Список индикаторов и их параметры для автоматического определения количества фичей
"""
from typing import Dict, List, Tuple
from dataclasses import dataclass
@dataclass
class IndicatorConfig:
"""Конфигурация индикатора"""
name: str
enabled: bool = True
params: Dict = None
description: str = ""
def __post_init__(self):
if self.params is None:
self.params = {}
class FeaturesConfig:
"""Конфигурация фичей - список индикаторов"""
# Основные ценовые фичи
PRICE_FEATURES = [
IndicatorConfig("normalized_price", True, {}, "Нормализованная цена"),
IndicatorConfig("returns", True, {}, "Возвраты/изменения цены"),
]
# Моментум индикаторы
MOMENTUM_INDICATORS = [
IndicatorConfig("rsi", True, {"period": 14}, "Relative Strength Index"),
IndicatorConfig("macd", True, {"fast": 12, "slow": 26, "signal": 9}, "MACD линия"),
IndicatorConfig("macd_signal", True, {"fast": 12, "slow": 26, "signal": 9}, "MACD сигнал"),
IndicatorConfig("stoch_k", True, {"k": 14, "d": 3, "smoothing": 3}, "Stochastic %K"),
IndicatorConfig("willr", True, {"period": 14}, "Williams %R"),
IndicatorConfig("cci", True, {"period": 14, "constant": 0.015}, "Commodity Channel Index"),
IndicatorConfig("mfi", True, {"period": 14}, "Money Flow Index"),
IndicatorConfig("roc", True, {"period": 10}, "Rate of Change"),
IndicatorConfig("tsi", True, {}, "True Strength Index"),
]
# Тренд индикаторы
TREND_INDICATORS = [
IndicatorConfig("adx", True, {"period": 14}, "Average Directional Index"),
IndicatorConfig("supertrend", True, {"period": 10, "multiplier": 3.0}, "Supertrend"),
IndicatorConfig("ichimoku_position", True, {}, "Ichimoku Cloud position"),
IndicatorConfig("psar_signal", True, {}, "Parabolic SAR signal"),
IndicatorConfig("hma", True, {"period": 20}, "Hull Moving Average"),
IndicatorConfig("aroon_up", True, {}, "Aroon up"),
IndicatorConfig("aroon_down", True, {}, "Aroon down"),
IndicatorConfig("aroon_diff", True, {}, "Aroon up/down difference"),
IndicatorConfig("aroon_osc", True, {}, "Aroon oscillator"),
IndicatorConfig("vortex_signal", True, {}, "Vortex indicator signal"),
]
# Волатильность индикаторы
VOLATILITY_INDICATORS = [
IndicatorConfig("bb_width", True, {"period": 20, "std": 2.0}, "Bollinger Bands width"),
IndicatorConfig("atr", True, {"period": 14}, "Average True Range"),
IndicatorConfig("keltner_position", True, {}, "Keltner Channels position"),
]
# Объем индикаторы
VOLUME_INDICATORS = [
IndicatorConfig("volume_ratio", True, {"period": 20}, "Volume ratio"),
]
@classmethod
def get_all_enabled_indicators(cls) -> List[IndicatorConfig]:
"""Получить все включенные индикаторы"""
all_indicators = []
all_indicators.extend(cls.PRICE_FEATURES)
all_indicators.extend(cls.MOMENTUM_INDICATORS)
all_indicators.extend(cls.TREND_INDICATORS)
all_indicators.extend(cls.VOLATILITY_INDICATORS)
all_indicators.extend(cls.VOLUME_INDICATORS)
# Фильтруем только включенные
return [ind for ind in all_indicators if ind.enabled]
@classmethod
def get_num_features(cls) -> int:
"""Получить общее количество фичей"""
return len(cls.get_all_enabled_indicators())
@classmethod
def get_feature_names(cls) -> List[str]:
"""Получить названия всех фичей"""
return [ind.name for ind in cls.get_all_enabled_indicators()]
@classmethod
def get_feature_descriptions(cls) -> Dict[str, str]:
"""Получить описания всех фичей"""
return {ind.name: ind.description for ind in cls.get_all_enabled_indicators()}
# Уровни фичей для простого переключения
class FeatureLevels:
"""Предустановленные уровни фичей"""
MINIMAL = [
"normalized_price",
"returns",
"rsi",
"macd",
"bb_width",
]
BASIC = [
"normalized_price",
"returns",
"rsi",
"macd",
"macd_signal",
"bb_width",
"volume_ratio",
]
ENHANCED = [
"normalized_price",
"returns",
"rsi",
"macd",
"macd_signal",
"bb_width",
"adx",
"roc",
"willr",
"cci",
"mfi",
"supertrend",
"atr",
"stoch_k",
"volume_ratio",
]
SUPER_ENHANCED = None # None означает использовать все включенные индикаторы
def set_feature_level(level: str) -> None:
"""Установить уровень фичей"""
if level == "minimal":
indicators_to_enable = FeatureLevels.MINIMAL
elif level == "basic":
indicators_to_enable = FeatureLevels.BASIC
elif level == "enhanced":
indicators_to_enable = FeatureLevels.ENHANCED
elif level == "super_enhanced":
indicators_to_enable = FeatureLevels.SUPER_ENHANCED
else:
raise ValueError(f"Unknown feature level: {level}")
if indicators_to_enable is not None:
# Отключаем все индикаторы
for category in [
FeaturesConfig.PRICE_FEATURES,
FeaturesConfig.MOMENTUM_INDICATORS,
FeaturesConfig.TREND_INDICATORS,
FeaturesConfig.VOLATILITY_INDICATORS,
FeaturesConfig.VOLUME_INDICATORS,
]:
for ind in category:
ind.enabled = False
# Включаем только нужные
all_indicators = {}
for category in [
FeaturesConfig.PRICE_FEATURES,
FeaturesConfig.MOMENTUM_INDICATORS,
FeaturesConfig.TREND_INDICATORS,
FeaturesConfig.VOLATILITY_INDICATORS,
FeaturesConfig.VOLUME_INDICATORS,
]:
for ind in category:
all_indicators[ind.name] = ind
for ind_name in indicators_to_enable:
if ind_name in all_indicators:
all_indicators[ind_name].enabled = True
if __name__ == "__main__":
# Демонстрация использования
print("🔧 Features Configuration")
print(f"Total features: {FeaturesConfig.get_num_features()}")
print("\nEnabled indicators:")
for i, ind in enumerate(FeaturesConfig.get_all_enabled_indicators(), 1):
print(f" {i:2d}. {ind.name:20s} - {ind.description}")
print(f"\nFeature names: {FeaturesConfig.get_feature_names()}")
# Тест переключения уровней
print("\n--- Testing feature levels ---")
for level in ["minimal", "basic", "enhanced", "super_enhanced"]:
set_feature_level(level)
print(f"{level:13s}: {FeaturesConfig.get_num_features()} features")