From 10b2937917da887c31f5bf7de9c78bf2dec45bb1 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Feb 2023 20:21:51 -0500 Subject: [PATCH] fix bug in sharpe ratio --- backtesting/_stats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backtesting/_stats.py b/backtesting/_stats.py index f2bb4f7c..ce264286 100644 --- a/backtesting/_stats.py +++ b/backtesting/_stats.py @@ -118,7 +118,7 @@ def _round_timedelta(value, _period=_data_period(index)): # Our Sharpe mismatches `empyrical.sharpe_ratio()` because they use arithmetic mean return # and simple standard deviation - s.loc['Sharpe Ratio'] = (s.loc['Return (Ann.) [%]'] - risk_free_rate) / (s.loc['Volatility (Ann.) [%]'] or np.nan) # noqa: E501 + s.loc['Sharpe Ratio'] = (s.loc['Return (Ann.) [%]'] - risk_free_rate * 100) / (s.loc['Volatility (Ann.) [%]'] or np.nan) # noqa: E501 # Our Sortino mismatches `empyrical.sortino_ratio()` because they use arithmetic mean return 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 max_dd = -np.nan_to_num(dd.max())