Spaces:
Paused
Paused
Update ml_engine/indicators.py
Browse files- ml_engine/indicators.py +14 -11
ml_engine/indicators.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# ml_engine/indicators.py (V5.
|
| 2 |
import pandas as pd
|
| 3 |
import pandas_ta as ta
|
| 4 |
import numpy as np
|
|
@@ -163,10 +163,8 @@ class AdvancedTechnicalAnalyzer:
|
|
| 163 |
except Exception as e:
|
| 164 |
print(f"⚠️ خطأ في حساب مؤشرات التقلب: {e}")
|
| 165 |
|
| 166 |
-
#
|
| 167 |
-
# (إصلاح: إعادة 'volatility' بدلاً من 'volume')
|
| 168 |
return {key: value for key, value in volatility.items() if value is not None and not np.isnan(value)}
|
| 169 |
-
# 🔴 --- END OF CHANGE --- 🔴
|
| 170 |
|
| 171 |
def _calculate_volume_indicators(self, dataframe, timeframe):
|
| 172 |
"""حساب مؤشرات الحجم"""
|
|
@@ -189,22 +187,27 @@ class AdvancedTechnicalAnalyzer:
|
|
| 189 |
|
| 190 |
df_vwap.sort_index(inplace=True)
|
| 191 |
|
| 192 |
-
|
|
|
|
|
|
|
| 193 |
|
| 194 |
volume_weighted_average_price = ta.vwap(
|
| 195 |
-
high=
|
| 196 |
-
low=
|
| 197 |
-
close=
|
| 198 |
-
volume=
|
| 199 |
)
|
|
|
|
| 200 |
|
| 201 |
if volume_weighted_average_price is not None and not volume_weighted_average_price.empty and not pd.isna(volume_weighted_average_price.iloc[-1]):
|
| 202 |
volume['vwap'] = float(volume_weighted_average_price.iloc[-1])
|
| 203 |
|
| 204 |
except Exception as vwap_error:
|
| 205 |
-
|
|
|
|
| 206 |
print(f"⚠️ خطأ في حساب VWAP لـ {timeframe}: {vwap_error}")
|
| 207 |
|
|
|
|
| 208 |
if len(dataframe) >= 20:
|
| 209 |
try:
|
| 210 |
typical_price = (dataframe['high'] + dataframe['low'] + dataframe['close']) / 3
|
|
@@ -270,4 +273,4 @@ class AdvancedTechnicalAnalyzer:
|
|
| 270 |
|
| 271 |
return {key: value for key, value in cycle.items() if value is not None and not np.isnan(value)}
|
| 272 |
|
| 273 |
-
print("✅ ML Module: Technical Indicators loaded (V5.
|
|
|
|
| 1 |
+
# ml_engine/indicators.py (V5.3 - Fixed VWAP DatetimeIndex Bug)
|
| 2 |
import pandas as pd
|
| 3 |
import pandas_ta as ta
|
| 4 |
import numpy as np
|
|
|
|
| 163 |
except Exception as e:
|
| 164 |
print(f"⚠️ خطأ في حساب مؤشرات التقلب: {e}")
|
| 165 |
|
| 166 |
+
# (إصلاح V5.2: إعادة 'volatility' بدلاً من 'volume')
|
|
|
|
| 167 |
return {key: value for key, value in volatility.items() if value is not None and not np.isnan(value)}
|
|
|
|
| 168 |
|
| 169 |
def _calculate_volume_indicators(self, dataframe, timeframe):
|
| 170 |
"""حساب مؤشرات الحجم"""
|
|
|
|
| 187 |
|
| 188 |
df_vwap.sort_index(inplace=True)
|
| 189 |
|
| 190 |
+
# 🔴 --- START OF CHANGE (V5.3 - FIX) --- 🔴
|
| 191 |
+
# (إصلاح: إزالة reset_index() للحفاظ على DatetimeIndex لـ ta.vwap)
|
| 192 |
+
# df_vwap_reset = df_vwap.reset_index() # <-- هذا السطر يسبب المشكلة
|
| 193 |
|
| 194 |
volume_weighted_average_price = ta.vwap(
|
| 195 |
+
high=df_vwap['high'], # (استخدام df_vwap مباشرة)
|
| 196 |
+
low=df_vwap['low'], # (استخدام df_vwap مباشرة)
|
| 197 |
+
close=df_vwap['close'], # (استخدام df_vwap مباشرة)
|
| 198 |
+
volume=df_vwap['volume'] # (استخدام df_vwap مباشرة)
|
| 199 |
)
|
| 200 |
+
# 🔴 --- END OF CHANGE --- 🔴
|
| 201 |
|
| 202 |
if volume_weighted_average_price is not None and not volume_weighted_average_price.empty and not pd.isna(volume_weighted_average_price.iloc[-1]):
|
| 203 |
volume['vwap'] = float(volume_weighted_average_price.iloc[-1])
|
| 204 |
|
| 205 |
except Exception as vwap_error:
|
| 206 |
+
# (تم تعديل الشرط لطباعة الخطأ إذا لم يكن التحذير المتوقع)
|
| 207 |
+
if "VWAP requires an ordered DatetimeIndex" not in str(vwap_error) and "Index" not in str(vwap_error):
|
| 208 |
print(f"⚠️ خطأ في حساب VWAP لـ {timeframe}: {vwap_error}")
|
| 209 |
|
| 210 |
+
# (محاولة حساب احتياطي بسيط إذا فشل الحساب المعتمد على الفهرس)
|
| 211 |
if len(dataframe) >= 20:
|
| 212 |
try:
|
| 213 |
typical_price = (dataframe['high'] + dataframe['low'] + dataframe['close']) / 3
|
|
|
|
| 273 |
|
| 274 |
return {key: value for key, value in cycle.items() if value is not None and not np.isnan(value)}
|
| 275 |
|
| 276 |
+
print("✅ ML Module: Technical Indicators loaded (V5.3 - VWAP DatetimeIndex Fix)")
|