def DEMA(ohlcv, kw): """ :return Double Exponential Moving Average (dema) """ params = {'timeperiod': 30} timeperiod = _get_params(kw, params, ['timeperiod'])[0] result = talib.DEMA(ohlcv, timeperiod) return { 'dema': result }
def get_overlap_studies(self): # https://mrjbq7.github.io/ta-lib/func_groups/overlap_studies.html if self.verbose: print self.ticker, 'get_overlap_studies' _a = ['open', 'high', 'low', 'close', 'volume'] inputs = {_a[i]: self.data[_a[i]].values for i in range(len(_a))} # simple moving average self.data['os_sma_20'] = abstract.SMA(inputs, timeperiod=20) self.data['os_sma_50'] = abstract.SMA(inputs, timeperiod=50) self.data['os_sma_200'] = abstract.SMA(inputs, timeperiod=200) # bollinger bands self.data['os_bbu_20'], self.data['os_bbm_20'], self.data[ 'os_bbl_20'] = abstract.BBANDS(inputs, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0) # double exponential moving average self.data['os_dema_20'] = abstract.DEMA(inputs, timeperiod=20) # exponential moving average self.data['os_ema_20'] = abstract.EMA(inputs, timeperiod=20) # midpoint over period self.data['os_mp_14'] = abstract.MIDPOINT(inputs, timeperiod=14) # parabolic SAR self.data['os_sar'] = abstract.SAR(inputs, acceleration=0, maximum=0) # triple exponential moving average self.data['os_tema_5'] = abstract.TEMA(inputs, timeperiod=5) # triangular moving average self.data['os_trima_30'] = abstract.TRIMA(inputs, timeperiod=30) # weighted moving average self.data['os_wma_30'] = abstract.WMA(inputs, timeperiod=30)
def PMAX(dataframe, period=4, multiplier=0.1, length=4, MAtype=7, src=1): import talib.abstract as ta df = dataframe.copy() mavalue = 'MA_' + str(MAtype) + '_' + str(length) atr = 'ATR_' + str(period) df[atr] = ta.ATR(df, timeperiod=period) pm = 'pm_' + str(period) + '_' + str(multiplier) + '_' + str(length) + '_' + str(MAtype) pmx = 'pmX_' + str(period) + '_' + str(multiplier) + '_' + str(length) + '_' + str(MAtype) if src == 1: masrc = df["close"] elif src == 2: masrc = (df["high"] + df["low"]) / 2 elif src == 3: masrc = (df["high"] + df["low"] + df["close"] + df["open"]) / 4 if MAtype == 1: df[mavalue] = ta.EMA(masrc, timeperiod=length) elif MAtype == 2: df[mavalue] = ta.DEMA(masrc, timeperiod=length) elif MAtype == 3: df[mavalue] = ta.T3(masrc, timeperiod=length) elif MAtype == 4: df[mavalue] = ta.SMA(masrc, timeperiod=length) elif MAtype == 5: df[mavalue] = VIDYA(df, length=length) elif MAtype == 6: df[mavalue] = ta.TEMA(masrc, timeperiod=length) elif MAtype == 7: df[mavalue] = ta.WMA(df, timeperiod=length) elif MAtype == 8: df[mavalue] = vwma(df, length) elif MAtype == 9: df[mavalue] = zema(df, period=length) # Compute basic upper and lower bands df['basic_ub'] = df[mavalue] + (multiplier * df[atr]) df['basic_lb'] = df[mavalue] - (multiplier * df[atr]) # Compute final upper and lower bands df['final_ub'] = 0.00 df['final_lb'] = 0.00 for i in range(period, len(df)): df['final_ub'].iat[i] = df['basic_ub'].iat[i] if ( df['basic_ub'].iat[i] < df['final_ub'].iat[i - 1] or df[mavalue].iat[i - 1] > df['final_ub'].iat[i - 1]) else df['final_ub'].iat[i - 1] df['final_lb'].iat[i] = df['basic_lb'].iat[i] if ( df['basic_lb'].iat[i] > df['final_lb'].iat[i - 1] or df[mavalue].iat[i - 1] < df['final_lb'].iat[i - 1]) else df['final_lb'].iat[i - 1] df[pm] = 0.00 for i in range(period, len(df)): df[pm].iat[i] = ( df['final_ub'].iat[i] if (df[pm].iat[i - 1] == df['final_ub'].iat[i - 1] and df[mavalue].iat[i] <= df['final_ub'].iat[i]) else df['final_lb'].iat[i] if ( df[pm].iat[i - 1] == df['final_ub'].iat[i - 1] and df[mavalue].iat[i] > df['final_ub'].iat[i]) else df['final_lb'].iat[i] if (df[pm].iat[i - 1] == df['final_lb'].iat[i - 1] and df[mavalue].iat[i] >= df['final_lb'].iat[i]) else df['final_ub'].iat[i] if (df[pm].iat[i - 1] == df['final_lb'].iat[i - 1] and df[mavalue].iat[i] < df['final_lb'].iat[i]) else 0.00) # up/down belirteçi / main logic df[pmx] = np.where((df[pm] > 0.00), np.where((df[mavalue] < df[pm]), 'down', 'up'), np.NaN) df.drop(['basic_ub', 'basic_lb', 'final_ub', 'final_lb'], inplace=True, axis=1) df.fillna(0, inplace=True) return df