Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    ZeroDivisionError: float division by zero

    General Code/Help
    1
    1
    270
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Sebastian Vetter
      Sebastian Vetter last edited by

      Re: anaylzer-vwr may have something error

      Traceback (most recent call last):
        File "/home/svetter/.local/lib/python3.6/site-packages/django_extensions/management/commands/runjob.py", line 35, in runjob
          job().execute()
        File "/home/svetter/zenvest/analysis/jobs/daily/backtest_technical_analysis.py", line 325, in execute
          result = cerebro.run()
        File "/home/svetter/.local/lib/python3.6/site-packages/backtrader/cerebro.py", line 1127, in run
          runstrat = self.runstrategies(iterstrat)
        File "/home/svetter/.local/lib/python3.6/site-packages/backtrader/cerebro.py", line 1301, in runstrategies
          strat._stop()
        File "/home/svetter/.local/lib/python3.6/site-packages/backtrader/strategy.py", line 486, in _stop
          analyzer._stop()
        File "/home/svetter/.local/lib/python3.6/site-packages/backtrader/analyzer.py", line 200, in _stop
          self.stop()
        File "/home/svetter/.local/lib/python3.6/site-packages/backtrader/analyzers/vwr.py", line 154, in stop
          dt = pn / (pi * math.exp(ravg * n)) - 1.0
      ZeroDivisionError: float division by zero
      

      I just had my script run through a few iterations and actually ran into the same issue. I'm not quite sure how

      (pi * math.exp(ravg*n) - 1.0
      

      can be zero? with the exponential value of pi * (ravg*n) being exactly 1.0?

      Did anyone else run into this? @backtrader what do you think about the suggestion made by the original author to add another check and potentially fill in NaN?

      # add a more assert 
      if pi * math.exp(ravg * n)!=0:
          dt = pn / (pi * math.exp(ravg * n)) - 1.0
      else:
          dt = np.NaN
      
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors