__init__.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Informed-Finance-Canary 作者: Darthone 项目源码 文件源码
def calculate_adx(self, window=14, window_adx=14):
        """ Average Directional Index Discover if trend is developing
                Sum((+DI-(-DI))/(+DI+(-DI))/n
        """
        self.set_max_win(window)
        i = 0  
        UpI = []  
        DoI = []  
        while i + 1 <= self.df.index[-1]:  
            UpMove = self.df.get_value(i + 1, 'High') - self.df.get_value(i, 'High')  
            DoMove = self.df.get_value(i, 'Low') - self.df.get_value(i + 1, 'Low')  
            if UpMove > DoMove and UpMove > 0:  
                UpD = UpMove  
            else: UpD = 0  
            UpI.append(UpD)  
            if DoMove > UpMove and DoMove > 0:  
                DoD = DoMove  
            else: DoD = 0  
            DoI.append(DoD)  
            i = i + 1  
        atr_name = "atr_%s" % (window)
        self.calculate_atr(window)
        PosDI = pd.ewma(pd.Series(UpI), span=window, min_periods=window-1) / self.df[atr_name]
        NegDI = pd.ewma(pd.Series(DoI), span=window, min_periods=window-1) / self.df[atr_name]
        name = "adx_%s_%s" % (window, window_adx)
        self.df[name] = pd.Series(pd.ewma(abs(PosDI - NegDI) / (PosDI + NegDI), span=window_adx, min_periods=window_adx-1))
        return name
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号