Skip to content

Commit 0436e56

Browse files
authored
ENH: Profit Factor statistic (#85)
* Add profit factor to stats * add mock profit factor value in test result * add correct profit factor value to assertion * suppress lint warning
1 parent b460092 commit 0436e56

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

backtesting/backtesting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ def _round_timedelta(value, _period=_data_period(df)):
945945
s.loc['Avg. Trade [%]'] = mean_return * 100
946946
s.loc['Max. Trade Duration'] = _round_timedelta(durations.max())
947947
s.loc['Avg. Trade Duration'] = _round_timedelta(durations.mean())
948+
s.loc['Profit Factor'] = returns[returns > 0].sum() / (abs(returns[returns < 0].sum()) or np.nan) # noqa: E501
948949
s.loc['Expectancy [%]'] = ((returns[returns > 0].mean() * win_rate -
949950
returns[returns < 0].mean() * (100 - win_rate)))
950951
pl = pl.dropna()

backtesting/test/_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def test_compute_stats(self):
256256
'Max. Drawdown Duration': pd.Timedelta('584 days 00:00:00'),
257257
'Max. Drawdown [%]': -48.15069053929621,
258258
'Max. Trade Duration': pd.Timedelta('183 days 00:00:00'),
259+
'Profit Factor': 2.060450149412349,
259260
'Return [%]': 426.2429346696951,
260261
'SQN': 0.91553210127173,
261262
'Sharpe Ratio': 0.23169782960690408,

0 commit comments

Comments
 (0)