Skip to content

Commit e56f758

Browse files
committed
1 parent 086247f commit e56f758

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

backtesting/backtesting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ def _round_timedelta(value, _period=_data_period(index)):
12851285
s.loc['Win Rate [%]'] = win_rate = np.nan if not n_trades else (pl > 0).sum() / n_trades * 100 # noqa: E501
12861286
s.loc['Best Trade [%]'] = returns.max() * 100
12871287
s.loc['Worst Trade [%]'] = returns.min() * 100
1288-
mean_return = returns.mean()
1288+
mean_return = np.exp(np.log(1 + returns).sum() / (len(returns) or np.nan)) - 1
12891289
s.loc['Avg. Trade [%]'] = mean_return * 100
12901290
s.loc['Max. Trade Duration'] = _round_timedelta(durations.max())
12911291
s.loc['Avg. Trade Duration'] = _round_timedelta(durations.mean())

backtesting/test/_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ def test_compute_stats(self):
253253
'Avg. Drawdown Duration': pd.Timedelta('41 days 00:00:00'),
254254
'Avg. Drawdown [%]': -5.925851581948801,
255255
'Avg. Trade Duration': pd.Timedelta('46 days 00:00:00'),
256-
'Avg. Trade [%]': 3.097629974370268,
256+
'Avg. Trade [%]': 2.3537113951143773,
257257
'Best Trade [%]': 53.59595229490424,
258258
'Buy & Hold Return [%]': 703.4582419772772,
259-
'Calmar Ratio': 0.06456068720154355,
259+
'Calmar Ratio': 0.049055964204885415,
260260
'Duration': pd.Timedelta('3116 days 00:00:00'),
261261
'End': pd.Timestamp('2013-03-01 00:00:00'),
262262
'Equity Final [$]': 51959.94999999997,
@@ -269,8 +269,8 @@ def test_compute_stats(self):
269269
'Profit Factor': 2.0880175388920286,
270270
'Return [%]': 419.59949999999964,
271271
'SQN': 0.916892986080858,
272-
'Sharpe Ratio': 0.2357610034211845,
273-
'Sortino Ratio': 0.7355072888872161,
272+
'Sharpe Ratio': 0.17914126763602636,
273+
'Sortino Ratio': 0.5588698138148217,
274274
'Start': pd.Timestamp('2004-08-19 00:00:00'),
275275
'Win Rate [%]': 46.15384615384615,
276276
'Worst Trade [%]': -18.39887353835481,

0 commit comments

Comments
 (0)