For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

anaylzer-vwr may have something error



  • when I optimize a strategy,the vwr analyzer occur something error,it mainly in :

      File "C:\Anaconda3\lib\site-packages\backtrader\strategy.py", line 486, in _stop
        analyzer._stop()
      File "C:\Anaconda3\lib\site-packages\backtrader\analyzer.py", line 200, in _stop
        self.stop()
      File "C:\Anaconda3\lib\site-packages\backtrader\analyzers\vwr.py", line 154, in stop
        dt = pn / (pi * math.exp(ravg * n)) - 1.0
    ZeroDivisionError: float division by zero
    

    so,this value about pi * math.exp(ravg * n) may be zero, maybe we should change the code to :

    def stop(self):
            super(VWR, self).stop()
            # Check if no value has been seen after the last 'dt_over'
            # If so, there is one 'pi' out of place and a None 'pn'. Purge
            if self._pns[-1] is None:
                self._pis.pop()
                self._pns.pop()
    
            # Get results from children
            rs = self._returns.get_analysis()
            ravg = rs['ravg']
            rnorm100 = rs['rnorm100']
    
            # make n 1 based in enumerate (number of periods and not index)
            # skip initial placeholders for synchronization
            dts = []
            for n, pipn in enumerate(zip(self._pis, self._pns), 1):
                pi, pn = pipn
                # add a more assert 
                if pi * math.exp(ravg * n)!=0:
                    dt = pn / (pi * math.exp(ravg * n)) - 1.0
                else:
                    dt = np.NaN 
                dts.append(dt)
    
            sdev_p = standarddev(dts, bessel=True)
    
            vwr = rnorm100 * (1.0 - pow(sdev_p / self.p.sdev_max, self.p.tau))
            self.rets['vwr'] = vwr
    

Log in to reply
 

});