def calculate_trix(self, window=15):
""" Triple Exponential Moving Average Smooth the insignificant movements
TR(t) / TR(t-1) where
TR(t) = EMA(EMA(EMA(Price(t)))) over n days period
"""
self.set_max_win(window)
#ignore produced warnings for now #TODO
ema = pd.ewma(self.df['Adj_Close'], span=window, min_periods=window-1)
ema = pd.ewma(ema, span=window, min_periods=window-1)
ema = pd.ewma(ema, span=window, min_periods=window-1)
roc_l = [0]
for i in range(1, len(self.df.index) - 1):
roc_l.append((ema[i + 1] - ema[i]) / ema[i])
name = "trix_%s" % (window)
self.df[name] = pd.Series(roc_l)
return name
评论列表
文章目录