@@ -27,7 +27,7 @@ def get_positive_trades(
2727 ]
2828
2929 positive_trades = [
30- trade for trade in closed_trades if trade .net_gain > 0
30+ trade for trade in closed_trades if trade .net_gain_absolute > 0
3131 ]
3232 number_of_positive_trades = len (positive_trades )
3333 percentage_positive_trades = (
@@ -60,7 +60,7 @@ def get_negative_trades(
6060 ]
6161
6262 negative_trades = [
63- trade for trade in closed_trades if trade .net_gain < 0
63+ trade for trade in closed_trades if trade .net_gain_absolute < 0
6464 ]
6565 number_of_negative_trades = len (negative_trades )
6666 percentage_negative_trades = (
@@ -241,11 +241,11 @@ def get_average_trade_return(trades: List[Trade]) -> Tuple[float, float]:
241241 if not closed_trades :
242242 return 0.0 , 0.0
243243
244- total_return = sum (t .net_gain for t in closed_trades )
244+ total_return = sum (t .net_gain_absolute for t in closed_trades )
245245 average_return = total_return / len (closed_trades )
246246
247247 percentage_returns = [
248- (t .net_gain / t .cost ) for t in closed_trades if t .cost > 0
248+ (t .net_gain_absolute / t .cost ) for t in closed_trades if t .cost > 0
249249 ]
250250 average_return_percentage = (
251251 sum (percentage_returns ) / len (percentage_returns )
@@ -274,11 +274,11 @@ def get_current_average_trade_return(
274274 "Trades list is empty, cannot compute average return."
275275 )
276276
277- total_return = sum (t .net_gain for t in trades )
277+ total_return = sum (t .net_gain_absolute for t in trades )
278278 average_return = total_return / len (trades )
279279
280280 percentage_returns = [
281- (t .net_gain / t .cost ) for t in trades if t .cost > 0
281+ (t .net_gain_absolute / t .cost ) for t in trades if t .cost > 0
282282 ]
283283 average_return_percentage = (
284284 sum (percentage_returns ) / len (percentage_returns )
@@ -306,8 +306,8 @@ def get_average_trade_gain(trades: List[Trade]) -> Tuple[float, float]:
306306 "Trades list is empty or None, cannot calculate average gain."
307307 )
308308
309- gains = [t .net_gain for t in trades if t .net_gain > 0 ]
310- cost = sum (t .cost for t in trades if t .net_gain > 0 )
309+ gains = [t .net_gain_absolute for t in trades if t .net_gain_absolute > 0 ]
310+ cost = sum (t .cost for t in trades if t .net_gain_absolute > 0 )
311311
312312 if not gains :
313313 return 0.0 , 0.0
@@ -337,8 +337,8 @@ def get_current_average_trade_gain(
337337 "Trades list is empty or None, cannot calculate average gain."
338338 )
339339
340- gains = [t .net_gain for t in trades if t .net_gain > 0 ]
341- cost = sum (t .cost for t in trades if t .net_gain > 0 )
340+ gains = [t .net_gain_absolute for t in trades if t .net_gain_absolute > 0 ]
341+ cost = sum (t .cost for t in trades if t .net_gain_absolute > 0 )
342342
343343 if not gains :
344344 return 0.0 , 0.0
@@ -371,10 +371,10 @@ def get_average_trade_loss(trades: List[Trade]) -> Tuple[float, float]:
371371 if not losing_trades or len (losing_trades ) == 0 :
372372 return 0.0 , 0.0
373373
374- losses = [t .net_gain for t in losing_trades ]
374+ losses = [t .net_gain_absolute for t in losing_trades ]
375375 average_loss = sum (losses ) / len (losses )
376376 percentage_returns = [
377- (t .net_gain / t .cost ) for t in losing_trades if t .cost > 0
377+ (t .net_gain_absolute / t .cost ) for t in losing_trades if t .cost > 0
378378 ]
379379 average_return_percentage = (
380380 sum (percentage_returns ) / len (percentage_returns )
@@ -404,15 +404,15 @@ def get_current_average_trade_loss(
404404 "Trades list is empty or None, cannot calculate average loss."
405405 )
406406
407- losing_trades = [t for t in trades if t .net_gain < 0 ]
407+ losing_trades = [t for t in trades if t .net_gain_absolute < 0 ]
408408
409409 if not losing_trades or len (losing_trades ) == 0 :
410410 return 0.0 , 0.0
411411
412- losses = [t .net_gain for t in losing_trades ]
412+ losses = [t .net_gain_absolute for t in losing_trades ]
413413 average_loss = sum (losses ) / len (losses )
414414 percentage_returns = [
415- (t .net_gain / t .cost ) for t in losing_trades if t .cost > 0
415+ (t .net_gain_absolute / t .cost ) for t in losing_trades if t .cost > 0
416416 ]
417417 average_return_percentage = (
418418 sum (percentage_returns ) / len (percentage_returns )
@@ -438,7 +438,7 @@ def get_median_trade_return(trades: List[Trade]) -> Tuple[float, float]:
438438 if not trades :
439439 return 0.0 , 0.0
440440
441- sorted_returns = sorted (t .net_gain for t in trades )
441+ sorted_returns = sorted (t .net_gain_absolute for t in trades )
442442 n = len (sorted_returns )
443443 mid = n // 2
444444
@@ -466,7 +466,7 @@ def get_best_trade(trades: List[Trade]) -> Trade:
466466 if not trades :
467467 return None
468468
469- return max (trades , key = lambda t : t .net_gain )
469+ return max (trades , key = lambda t : t .net_gain_absolute )
470470
471471
472472def get_worst_trade (trades : List [Trade ]) -> Trade :
0 commit comments