_stats.py:122: RuntimeWarning: divide by zero encountered in double_scalars
Expected Behavior
/home/mab/Documents/RESEARCH/GARS/.env/lib/python3.9/site-packages/backtesting/_stats.py:122: RuntimeWarning: divide by zero encountered in double_scalars
s.loc['Sortino Ratio'] = np.clip((annualized_return - risk_free_rate) / (np.sqrt(np.mean(day_returns.clip(-np.inf, 0)**2)) * np.sqrt(annual_trading_days)), 0, np.inf) # noqa: E501
Actual Behavior
Steps to Reproduce
- Runnig a code that have 6 sma and time periods changes every time.
n0 = 10
n1 = 20
n2 = 30
n3 = 40
n4 = 50
n5 = 60
def init(self):
close = self.data.Close
self.sma0 = self.I(SMA, close, round(self.n0))
self.sma1 = self.I(SMA, close, round(self.n1))
self.sma2 = self.I(SMA, close, round(self.n2))
self.sma3 = self.I(SMA, close, round(self.n3))
self.sma4 = self.I(SMA, close, round(self.n4))
self.sma5 = self.I(SMA, close, round(self.n5))
Additional info
- Backtesting version: 0.?.?
same issue; any fix?
I have the same warning
Me too.I've same issue and I posted the issue on the github but they still ignoring about that
C:\Users\hoge\AppData\Local\Programs\Python\Python36\lib\site-packages\backtesting_stats.py:122: RuntimeWarning: divide by zero encountered in double_scalars s.loc['Sortino Ratio'] = np.clip((annualized_return - risk_free_rate) / (np.sqrt(np.mean(day_returns.clip(-np.inf, 0)**2)) * np.sqrt(annual_trading_days)), 0, np.inf) # noqa: E501
That's my error code. Thanks in advance
I am getting the same error on v.0.3.3. You can use: np.seterr(divide='ignore')
This won't fix the problem, but it will turn off the error warning. In addition, as I understand it, this only affects the final result of the "'Sortino Ratio" so if you dont use this indicator, then its not so critical
this only affects the final result of the "'Sortino Ratio" so if you dont use this indicator, then its not so critical
Thanks buddy
Thanks!