Skip to content

Commit a9476d7

Browse files
committed
Add current win and current win/loss ratio
1 parent 11d03c1 commit a9476d7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

investing_algorithm_framework/domain/backtesting/backtest_summary_metrics.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ class BacktestSummaryMetrics:
4848
max_drawdown_duration (int): Duration of the maximum drawdown.
4949
trades_per_year (float): Average trades executed per year.
5050
win_rate (float): Percentage of winning trades.
51+
current_win_rate (float): Win rate over recent trades.
5152
win_loss_ratio (float): Ratio of average win to average loss.
53+
current_win_loss_ratio (float): Win/loss ratio over recent trades.
5254
number_of_trades (int): Total number of trades executed.
5355
cumulative_exposure (float): Total exposure over the backtest period.
5456
exposure_ratio (float): Ratio of exposure to available capital.
@@ -81,7 +83,9 @@ class BacktestSummaryMetrics:
8183
max_drawdown_duration: int = None
8284
trades_per_year: float = None
8385
win_rate: float = None
86+
current_win_rate: float = None
8487
win_loss_ratio: float = None
88+
current_win_loss_ratio: float = None
8589
number_of_trades: int = None
8690
number_of_trades_closed: int = None
8791
cumulative_exposure: float = None
@@ -123,7 +127,9 @@ def to_dict(self) -> dict:
123127
"max_drawdown_duration": self.max_drawdown_duration,
124128
"trades_per_year": self.trades_per_year,
125129
"win_rate": self.win_rate,
130+
"current_win_rate": self.current_win_rate,
126131
"win_loss_ratio": self.win_loss_ratio,
132+
"current_win_loss_ratio": self.current_win_loss_ratio,
127133
"number_of_trades": self.number_of_trades,
128134
"number_of_trades_closed": self.number_of_trades_closed,
129135
"cumulative_exposure": self.cumulative_exposure,

investing_algorithm_framework/domain/backtesting/combine_backtests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,18 @@ def generate_backtest_summary_metrics(
184184
[b.win_rate for b in backtest_metrics],
185185
[b.total_number_of_days for b in backtest_metrics]
186186
)
187+
current_win_rate = safe_weighted_mean(
188+
[b.current_win_rate for b in backtest_metrics],
189+
[b.total_number_of_days for b in backtest_metrics]
190+
)
187191
win_loss_ratio = safe_weighted_mean(
188192
[b.win_loss_ratio for b in backtest_metrics],
189193
[b.total_number_of_days for b in backtest_metrics]
190194
)
195+
current_win_loss_ratio = safe_weighted_mean(
196+
[b.current_win_loss_ratio for b in backtest_metrics],
197+
[b.total_number_of_days for b in backtest_metrics]
198+
)
191199
number_of_trades = sum(
192200
b.number_of_trades for b in backtest_metrics
193201
if b.number_of_trades is not None
@@ -251,7 +259,9 @@ def generate_backtest_summary_metrics(
251259
max_drawdown_duration=max_drawdown_duration,
252260
trades_per_year=trades_per_year,
253261
win_rate=win_rate,
262+
current_win_rate=current_win_rate,
254263
win_loss_ratio=win_loss_ratio,
264+
current_win_loss_ratio=current_win_loss_ratio,
255265
number_of_trades=number_of_trades,
256266
number_of_trades_closed=number_of_trades_closed,
257267
cumulative_exposure=cumulative_exposure,

0 commit comments

Comments
 (0)