Skip to content

Commit f248da9

Browse files
authored
BUG: Fix bug in Sharpe ratio with non-zero risk-free rate (kernc#904)
1 parent 638f5e9 commit f248da9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

backtesting/_stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _round_timedelta(value, _period=_data_period(index)):
126126

127127
# Our Sharpe mismatches `empyrical.sharpe_ratio()` because they use arithmetic mean return
128128
# and simple standard deviation
129-
s.loc['Sharpe Ratio'] = (s.loc['Return (Ann.) [%]'] - risk_free_rate) / (s.loc['Volatility (Ann.) [%]'] or np.nan) # noqa: E501
129+
s.loc['Sharpe Ratio'] = (s.loc['Return (Ann.) [%]'] - risk_free_rate * 100) / (s.loc['Volatility (Ann.) [%]'] or np.nan) # noqa: E501
130130
# Our Sortino mismatches `empyrical.sortino_ratio()` because they use arithmetic mean return
131131
s.loc['Sortino Ratio'] = (annualized_return - risk_free_rate) / (np.sqrt(np.mean(day_returns.clip(-np.inf, 0)**2)) * np.sqrt(annual_trading_days)) # noqa: E501
132132
max_dd = -np.nan_to_num(dd.max())

0 commit comments

Comments
 (0)