Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# app.py (Updated to V8.
|
| 2 |
import os
|
| 3 |
import traceback
|
| 4 |
import signal
|
|
@@ -270,7 +270,7 @@ async def process_batch_parallel(batch, ml_processor, batch_num, total_batches,
|
|
| 270 |
|
| 271 |
async def run_3_layer_analysis_explorer() -> List[Dict[str, Any]]:
|
| 272 |
"""
|
| 273 |
-
(معدل V8.
|
| 274 |
"""
|
| 275 |
layer1_candidates = []
|
| 276 |
layer2_candidates = []
|
|
@@ -446,6 +446,23 @@ async def run_3_layer_analysis_explorer() -> List[Dict[str, Any]]:
|
|
| 446 |
candidate.get('ohlcv')
|
| 447 |
)
|
| 448 |
if advanced_mc_results and advanced_mc_results.get('simulation_model') == 'Phase2_GARCH_LGBM':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
candidate['monte_carlo_distribution'] = advanced_mc_results
|
| 450 |
candidate['monte_carlo_probability'] = advanced_mc_results.get('probability_of_gain', 0)
|
| 451 |
candidate['advanced_mc_run'] = True
|
|
@@ -549,7 +566,7 @@ async def run_3_layer_analysis_explorer() -> List[Dict[str, Any]]:
|
|
| 549 |
|
| 550 |
|
| 551 |
async def re_analyze_open_trade_async(trade_data):
|
| 552 |
-
"""(V8.
|
| 553 |
symbol = trade_data.get('symbol')
|
| 554 |
try:
|
| 555 |
async with state_manager.trade_analysis_lock:
|
|
@@ -595,6 +612,23 @@ async def re_analyze_open_trade_async(trade_data):
|
|
| 595 |
if not processed_data: return None
|
| 596 |
|
| 597 |
if advanced_mc_results:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
processed_data['monte_carlo_distribution'] = advanced_mc_results
|
| 599 |
processed_data['monte_carlo_probability'] = advanced_mc_results.get('probability_of_gain', 0)
|
| 600 |
|
|
|
|
| 1 |
+
# app.py (Updated to V8.7 - MC Expected Return Fix)
|
| 2 |
import os
|
| 3 |
import traceback
|
| 4 |
import signal
|
|
|
|
| 270 |
|
| 271 |
async def run_3_layer_analysis_explorer() -> List[Dict[str, Any]]:
|
| 272 |
"""
|
| 273 |
+
(معدل V8.7) - إصلاح العائد المتوقع (Expected Return)
|
| 274 |
"""
|
| 275 |
layer1_candidates = []
|
| 276 |
layer2_candidates = []
|
|
|
|
| 446 |
candidate.get('ohlcv')
|
| 447 |
)
|
| 448 |
if advanced_mc_results and advanced_mc_results.get('simulation_model') == 'Phase2_GARCH_LGBM':
|
| 449 |
+
|
| 450 |
+
# 🔴 --- START OF CHANGE (V8.7 - MC Expected Return Fix) --- 🔴
|
| 451 |
+
# (إصلاح: حساب العائد المتوقع يدوياً إذا كان مفقوداً)
|
| 452 |
+
if 'expected_return_pct' not in advanced_mc_results:
|
| 453 |
+
try:
|
| 454 |
+
mean_price = advanced_mc_results.get('distribution_summary', {}).get('mean_price', 0)
|
| 455 |
+
current_price = advanced_mc_results.get('current_price', 0)
|
| 456 |
+
if mean_price > 0 and current_price > 0:
|
| 457 |
+
expected_return_pct = (mean_price - current_price) / current_price
|
| 458 |
+
advanced_mc_results['expected_return_pct'] = expected_return_pct
|
| 459 |
+
print(f" [MC Patch] {symbol}: Calculated Expected Return: {expected_return_pct:+.2%}")
|
| 460 |
+
else:
|
| 461 |
+
advanced_mc_results['expected_return_pct'] = 0.0
|
| 462 |
+
except Exception:
|
| 463 |
+
advanced_mc_results['expected_return_pct'] = 0.0
|
| 464 |
+
# 🔴 --- END OF CHANGE --- 🔴
|
| 465 |
+
|
| 466 |
candidate['monte_carlo_distribution'] = advanced_mc_results
|
| 467 |
candidate['monte_carlo_probability'] = advanced_mc_results.get('probability_of_gain', 0)
|
| 468 |
candidate['advanced_mc_run'] = True
|
|
|
|
| 566 |
|
| 567 |
|
| 568 |
async def re_analyze_open_trade_async(trade_data):
|
| 569 |
+
"""(V8.7) إضافة إصلاح ndarray + إصلاح العائد المتوقع"""
|
| 570 |
symbol = trade_data.get('symbol')
|
| 571 |
try:
|
| 572 |
async with state_manager.trade_analysis_lock:
|
|
|
|
| 612 |
if not processed_data: return None
|
| 613 |
|
| 614 |
if advanced_mc_results:
|
| 615 |
+
|
| 616 |
+
# 🔴 --- START OF CHANGE (V8.7 - MC Expected Return Fix) --- 🔴
|
| 617 |
+
# (إصلاح: حساب العائد المتوقع يدوياً إذا كان مفقوداً)
|
| 618 |
+
if 'expected_return_pct' not in advanced_mc_results:
|
| 619 |
+
try:
|
| 620 |
+
mean_price = advanced_mc_results.get('distribution_summary', {}).get('mean_price', 0)
|
| 621 |
+
current_price = advanced_mc_results.get('current_price', 0)
|
| 622 |
+
if mean_price > 0 and current_price > 0:
|
| 623 |
+
expected_return_pct = (mean_price - current_price) / current_price
|
| 624 |
+
advanced_mc_results['expected_return_pct'] = expected_return_pct
|
| 625 |
+
print(f" [MC Patch] {symbol}: Calculated Expected Return: {expected_return_pct:+.2%}")
|
| 626 |
+
else:
|
| 627 |
+
advanced_mc_results['expected_return_pct'] = 0.0
|
| 628 |
+
except Exception:
|
| 629 |
+
advanced_mc_results['expected_return_pct'] = 0.0
|
| 630 |
+
# 🔴 --- END OF CHANGE --- 🔴
|
| 631 |
+
|
| 632 |
processed_data['monte_carlo_distribution'] = advanced_mc_results
|
| 633 |
processed_data['monte_carlo_probability'] = advanced_mc_results.get('probability_of_gain', 0)
|
| 634 |
|