Skip to content

Commit

Permalink
REF: Use geometric mean return in Sharpe/Sortino stats computation
Browse files Browse the repository at this point in the history
  • Loading branch information
kernc committed Jul 13, 2020
1 parent 086247f commit e56f758
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backtesting/backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ def _round_timedelta(value, _period=_data_period(index)):
s.loc['Win Rate [%]'] = win_rate = np.nan if not n_trades else (pl > 0).sum() / n_trades * 100 # noqa: E501
s.loc['Best Trade [%]'] = returns.max() * 100
s.loc['Worst Trade [%]'] = returns.min() * 100
mean_return = returns.mean()
mean_return = np.exp(np.log(1 + returns).sum() / (len(returns) or np.nan)) - 1
s.loc['Avg. Trade [%]'] = mean_return * 100
s.loc['Max. Trade Duration'] = _round_timedelta(durations.max())
s.loc['Avg. Trade Duration'] = _round_timedelta(durations.mean())
Expand Down
8 changes: 4 additions & 4 deletions backtesting/test/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ def test_compute_stats(self):
'Avg. Drawdown Duration': pd.Timedelta('41 days 00:00:00'),
'Avg. Drawdown [%]': -5.925851581948801,
'Avg. Trade Duration': pd.Timedelta('46 days 00:00:00'),
'Avg. Trade [%]': 3.097629974370268,
'Avg. Trade [%]': 2.3537113951143773,
'Best Trade [%]': 53.59595229490424,
'Buy & Hold Return [%]': 703.4582419772772,
'Calmar Ratio': 0.06456068720154355,
'Calmar Ratio': 0.049055964204885415,
'Duration': pd.Timedelta('3116 days 00:00:00'),
'End': pd.Timestamp('2013-03-01 00:00:00'),
'Equity Final [$]': 51959.94999999997,
Expand All @@ -269,8 +269,8 @@ def test_compute_stats(self):
'Profit Factor': 2.0880175388920286,
'Return [%]': 419.59949999999964,
'SQN': 0.916892986080858,
'Sharpe Ratio': 0.2357610034211845,
'Sortino Ratio': 0.7355072888872161,
'Sharpe Ratio': 0.17914126763602636,
'Sortino Ratio': 0.5588698138148217,
'Start': pd.Timestamp('2004-08-19 00:00:00'),
'Win Rate [%]': 46.15384615384615,
'Worst Trade [%]': -18.39887353835481,
Expand Down

0 comments on commit e56f758

Please sign in to comment.