Pārlūkot izejas kodu

Refactor performance calculation logic in PerformanceCalculator class. Updated profit factor and expectancy calculations to use sums of winning and losing trades for improved accuracy. This change enhances the reliability of performance metrics in trading analysis.

Carles Sentis 3 nedēļas atpakaļ
vecāks
revīzija
8bf1fb3d21
2 mainītis faili ar 9 papildinājumiem un 5 dzēšanām
  1. 8 4
      src/stats/performance_calculator.py
  2. 1 1
      trading_bot.py

+ 8 - 4
src/stats/performance_calculator.py

@@ -121,12 +121,16 @@ class PerformanceCalculator:
             
             
             # Calculate win rate and profit factor
             # Calculate win rate and profit factor
             win_rate = (total_wins / total_trades * 100) if total_trades > 0 else 0
             win_rate = (total_wins / total_trades * 100) if total_trades > 0 else 0
-            profit_factor = (total_pnl / abs(total_losses)) if total_losses < 0 else float('inf') if total_pnl > 0 else 0
+            
+            # Calculate sum of winning and losing trades
+            sum_winning = sum(token.get('sum_of_winning_pnl', 0) for token in token_stats)
+            sum_losing = abs(sum(token.get('sum_of_losing_pnl', 0) for token in token_stats))
+            profit_factor = (sum_winning / sum_losing) if sum_losing > 0 else float('inf') if sum_winning > 0 else 0
             
             
             # Calculate expectancy
             # Calculate expectancy
-            avg_win = total_pnl / total_wins if total_wins > 0 else 0
-            avg_loss = total_losses / total_losses if total_losses > 0 else 0
-            expectancy = (avg_win * (win_rate/100)) - (abs(avg_loss) * (1 - win_rate/100))
+            avg_win = sum_winning / total_wins if total_wins > 0 else 0
+            avg_loss = sum_losing / total_losses if total_losses > 0 else 0
+            expectancy = (avg_win * (win_rate/100)) - (avg_loss * (1 - win_rate/100))
             
             
             # Get max drawdown
             # Get max drawdown
             max_drawdown, max_drawdown_pct = self.get_live_max_drawdown()
             max_drawdown, max_drawdown_pct = self.get_live_max_drawdown()

+ 1 - 1
trading_bot.py

@@ -14,7 +14,7 @@ from datetime import datetime
 from pathlib import Path
 from pathlib import Path
 
 
 # Bot version
 # Bot version
-BOT_VERSION = "2.4.212"
+BOT_VERSION = "2.4.213"
 
 
 # Add src directory to Python path
 # Add src directory to Python path
 sys.path.insert(0, str(Path(__file__).parent / "src"))
 sys.path.insert(0, str(Path(__file__).parent / "src"))