def wma_obv(self): df2 = self.df df2.rename(columns={'obv': 'close'}) try: self.wma_obv = abstract.WMA(df2, 233) except: pprint(sys.exc_info())
def WMA(ohlcv, kw): """ :return Weighted Moving Average (wma) """ params = {'timeperiod': 30} timeperiod = _get_params(kw, params, ['timeperiod'])[0] result = talib.WMA(ohlcv, timeperiod) return { 'wma': result }
def technical_index(self): df = self.max_min_price() df2 = self.institutional_investors() df['RSI'] = abstract.RSI(df) / 100 df['CMO'] =(abstract.CMO(df)+100) / (2 *100) df['MACD'] =(abstract.MACD(df)['macd']+abstract.MACD(df)['macd'].max()) / (2 *abstract.MACD(df)['macd'].max()) df['WILLR'] =(abstract.WILLR(df)+100) / (2 *100) df['WMA'] =abstract.WMA(df) / abstract.WMA(df).max() df['PPO'] =(abstract.PPO(df)+abstract.PPO(df).max()) / (2 *abstract.PPO(df).max()) df['EMA'] =abstract.EMA(df) / abstract.EMA(df).max() df['ROC'] =(abstract.ROC(df)+abstract.ROC(df).max()) / (2 *abstract.ROC(df).max()) df['SMA'] =abstract.SMA(df) / abstract.SMA(df).max() df['TEMA'] =abstract.TEMA(df) / abstract.TEMA(df).max() df['CCI'] =(abstract.CCI(df)+abstract.CCI(df).max()) / (2 *abstract.CCI(df).max()) df['investment_trust'] = (df2['investment_trust'] + df2['investment_trust'].max()) / (2*df2['investment_trust'].max()) df['foreign_investor'] = (df2['foreign_investor'] + df2['foreign_investor'].max()) / (2*df2['foreign_investor'].max()) df = df.drop(columns=['volume', 'open', 'high', 'low', 'close', 'close_max', 'close_min']) df = df.dropna() return df
def scan_wma_obv_sloping_up(self): self.df["both_sloping_up"] = 0 wma = abstract.WMA(self.df, 233) df2 = self.df df2.rename(columns={'obv': 'close'}) wma_obv = abstract.WMA(df2, 233) for i in range(0, len(wma_obv)): try: a = wma_obv[i - 1] b = wma_obv[i] c = wma[i - 1] d = wma[i] if a < b and c < d: self.df['both_sloping_up'][i] = 1 except: pass return self.df
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
def wma(self): real = tb.WMA(self.close, timeperiod=30) return real
def cal_wma(self): self.analysis_data['wma5'] = ta.WMA(self.close, timeperiod=5) self.analysis_data['wma20'] = ta.WMA(self.close, timeperiod=20) self.analysis_data['wma60'] = ta.WMA(self.close, timeperiod=60) self.analysis_data['wma120'] = ta.WMA(self.close, timeperiod=120)
def VMA(self): real = tb.WMA(self.close, timeperiod=30)