Skip to content

Commit ed928e6

Browse files
committed
Fix current win rate calculation
1 parent 82c8a0c commit ed928e6

File tree

1 file changed

+5
-5
lines changed
  • investing_algorithm_framework/services/metrics

1 file changed

+5
-5
lines changed

investing_algorithm_framework/services/metrics/win_rate.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def get_current_win_rate(trades: List[Trade]) -> float:
8585
if not trades:
8686
return 0.0
8787

88-
positive_trades = sum(1 for trade in trades if trade.net_gain > 0)
88+
positive_trades = sum(1 for trade in trades if trade.net_gain_absolute > 0)
8989
total_trades = len(trades)
9090

9191
return positive_trades / total_trades
@@ -159,16 +159,16 @@ def get_current_win_loss_ratio(trades: List[Trade]) -> float:
159159
return 0.0
160160

161161
# Separate winning and losing trades
162-
winning_trades = [t for t in trades if t.net_gain > 0]
163-
losing_trades = [t for t in trades if t.net_gain < 0]
162+
winning_trades = [t for t in trades if t.net_gain_absolute > 0]
163+
losing_trades = [t for t in trades if t.net_gain_absolute < 0]
164164

165165
if not winning_trades or not losing_trades:
166166
return 0.0
167167

168168
# Compute averages
169-
avg_win = sum(t.net_gain for t in winning_trades) / len(winning_trades)
169+
avg_win = sum(t.net_gain_absolute for t in winning_trades) / len(winning_trades)
170170
avg_loss = abs(
171-
sum(t.net_gain for t in losing_trades) / len(losing_trades))
171+
sum(t.net_gain_absolute for t in losing_trades) / len(losing_trades))
172172

173173
# Avoid division by zero
174174
if avg_loss == 0:

0 commit comments

Comments
 (0)