Spaces:
Running
Running
Update ml_engine/processor.py
Browse files- ml_engine/processor.py +10 -6
ml_engine/processor.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# ml_engine/processor.py (Updated to
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
from datetime import datetime
|
|
@@ -13,7 +13,6 @@ from .patterns import ChartPatternAnalyzer
|
|
| 13 |
from .strategies import MultiStrategyEngine
|
| 14 |
|
| 15 |
class MLProcessor:
|
| 16 |
-
# 🔴 --- START OF CHANGE --- 🔴
|
| 17 |
def __init__(self, market_context, data_manager, learning_hub): # (Changed from learning_engine)
|
| 18 |
self.market_context = market_context
|
| 19 |
self.data_manager = data_manager
|
|
@@ -25,7 +24,6 @@ class MLProcessor:
|
|
| 25 |
self.monte_carlo_analyzer = MonteCarloAnalyzer()
|
| 26 |
self.pattern_analyzer = ChartPatternAnalyzer()
|
| 27 |
self.whale_data_semaphore = asyncio.Semaphore(2)
|
| 28 |
-
# 🔴 --- END OF CHANGE --- 🔴
|
| 29 |
|
| 30 |
async def process_and_score_symbol_enhanced(self, raw_data, preloaded_whale_data: dict = None):
|
| 31 |
"""
|
|
@@ -114,8 +112,9 @@ class MLProcessor:
|
|
| 114 |
print(f"❌ Error creating DataFrame: {e}")
|
| 115 |
return pd.DataFrame()
|
| 116 |
|
|
|
|
| 117 |
def _calculate_enhanced_final_score(self, analysis):
|
| 118 |
-
|
| 119 |
try:
|
| 120 |
base_score = analysis.get('final_score', 0)
|
| 121 |
pattern_confidence = analysis.get('pattern_analysis', {}).get('pattern_confidence', 0)
|
|
@@ -133,8 +132,12 @@ class MLProcessor:
|
|
| 133 |
normalized_var = var_95_value / current_price
|
| 134 |
risk_penalty = 1.0
|
| 135 |
if normalized_var > 0.05: risk_penalty = 0.5
|
| 136 |
-
elif normalized_var > 0.03: risk_penalty = 0.8
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
else:
|
| 139 |
monte_carlo_score = 0
|
| 140 |
|
|
@@ -163,6 +166,7 @@ class MLProcessor:
|
|
| 163 |
except Exception as e:
|
| 164 |
print(f"❌ Error calculating enhanced score: {e}")
|
| 165 |
return analysis.get('final_score', 0)
|
|
|
|
| 166 |
|
| 167 |
async def process_and_score_symbol(self, raw_data):
|
| 168 |
# (This function remains unchanged)
|
|
|
|
| 1 |
+
# ml_engine/processor.py (Updated to V6.2 - Normalized MC Score)
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
from datetime import datetime
|
|
|
|
| 13 |
from .strategies import MultiStrategyEngine
|
| 14 |
|
| 15 |
class MLProcessor:
|
|
|
|
| 16 |
def __init__(self, market_context, data_manager, learning_hub): # (Changed from learning_engine)
|
| 17 |
self.market_context = market_context
|
| 18 |
self.data_manager = data_manager
|
|
|
|
| 24 |
self.monte_carlo_analyzer = MonteCarloAnalyzer()
|
| 25 |
self.pattern_analyzer = ChartPatternAnalyzer()
|
| 26 |
self.whale_data_semaphore = asyncio.Semaphore(2)
|
|
|
|
| 27 |
|
| 28 |
async def process_and_score_symbol_enhanced(self, raw_data, preloaded_whale_data: dict = None):
|
| 29 |
"""
|
|
|
|
| 112 |
print(f"❌ Error creating DataFrame: {e}")
|
| 113 |
return pd.DataFrame()
|
| 114 |
|
| 115 |
+
# 🔴 --- START OF CHANGE (V6.2 - NORMALIZE MC SCORE) --- 🔴
|
| 116 |
def _calculate_enhanced_final_score(self, analysis):
|
| 117 |
+
"""(محدث V6.2) تطبيع درجة مونت كارلو لمعاقبة النتائج العشوائية."""
|
| 118 |
try:
|
| 119 |
base_score = analysis.get('final_score', 0)
|
| 120 |
pattern_confidence = analysis.get('pattern_analysis', {}).get('pattern_confidence', 0)
|
|
|
|
| 132 |
normalized_var = var_95_value / current_price
|
| 133 |
risk_penalty = 1.0
|
| 134 |
if normalized_var > 0.05: risk_penalty = 0.5
|
| 135 |
+
elif normalized_var > 0.03: risk_penalty = 0.8
|
| 136 |
+
|
| 137 |
+
# (تعديل: تطبيع الاحتمالية)
|
| 138 |
+
# (0.5 -> 0), (0.75 -> 0.5), (1.0 -> 1.0)
|
| 139 |
+
normalized_prob_score = max(0.0, (prob_gain - 0.5) * 2)
|
| 140 |
+
monte_carlo_score = normalized_prob_score * risk_penalty
|
| 141 |
else:
|
| 142 |
monte_carlo_score = 0
|
| 143 |
|
|
|
|
| 166 |
except Exception as e:
|
| 167 |
print(f"❌ Error calculating enhanced score: {e}")
|
| 168 |
return analysis.get('final_score', 0)
|
| 169 |
+
# 🔴 --- END OF CHANGE --- 🔴
|
| 170 |
|
| 171 |
async def process_and_score_symbol(self, raw_data):
|
| 172 |
# (This function remains unchanged)
|