Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_stats.py:122: RuntimeWarning: divide by zero encountered in double_scalars #584

Open
mablue opened this issue Jan 27, 2022 · 8 comments
Open
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@mablue
Copy link

mablue commented Jan 27, 2022

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

  1. 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.?.?
@kernc kernc changed the title /home/mab/Documents/RESEARCH/GARS/.env/lib/python3.9/site-packages/backtesting/_stats.py:122: RuntimeWarning: divide by zero encountered in double_scalars _stats.py:122: RuntimeWarning: divide by zero encountered in double_scalars Jan 28, 2022
@sharmaakhil100
Copy link

same issue; any fix?

@samueltg92
Copy link

I have the same warning

@KnudY9
Copy link

KnudY9 commented Nov 26, 2022

Me too.I've same issue and I posted the issue on the github but they still ignoring about that

@KnudY9
Copy link

KnudY9 commented Nov 26, 2022

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

@KnudY9
Copy link

KnudY9 commented Nov 26, 2022

That's my error code.
Thanks in advance

@Lanimel
Copy link

Lanimel commented Jan 3, 2023

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

@kernc kernc added bug Something isn't working good first issue Good for newcomers labels Jan 3, 2023
@KnudY9
Copy link

KnudY9 commented Jan 3, 2023

this only affects the final result of the "'Sortino Ratio" so if you dont use this indicator, then its not so critical

Thanks buddy

@sharmaakhil100
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants