def add_indicators(data: pd.DataFrame) -> pd.DataFrame: """ This method creates technical indicators, based on the OHLC and volume bars :param data: pandas DataFrame, containing open, high, low and close and optional volume columns :return: DataFrame with added technical indicators """ assert 'open' in data.columns, "open column not present or with different name" assert 'high' in data.columns, "high column not present or with different name" assert 'low' in data.columns, "low column not present or with different name" assert 'close' in data.columns, "close column not present or with different name" try: data['RSI'] = ta.rsi(data["close"]) data['TSI'] = ta.tsi(data["close"]) data['UO'] = ta.uo(data["high"], data["low"], data["close"]) data['AO'] = ta.ao(data["high"], data["low"]) data['MACD_diff'] = ta.macd_diff(data["close"]) data['Vortex_pos'] = ta.vortex_indicator_pos(data["high"], data["low"], data["close"]) data['Vortex_neg'] = ta.vortex_indicator_neg(data["high"], data["low"], data["close"]) data['Vortex_diff'] = abs(data['Vortex_pos'] - data['Vortex_neg']) data['Trix'] = ta.trix(data["close"]) data['Mass_index'] = ta.mass_index(data["high"], data["low"]) data['CCI'] = ta.cci(data["high"], data["low"], data["close"]) data['DPO'] = ta.dpo(data["close"]) data['KST'] = ta.kst(data["close"]) data['KST_sig'] = ta.kst_sig(data["close"]) data['KST_diff'] = (data['KST'] - data['KST_sig']) data['Aroon_up'] = ta.aroon_up(data["close"]) data['Aroon_down'] = ta.aroon_down(data["close"]) data['Aroon_ind'] = (data['Aroon_up'] - data['Aroon_down']) data['BBH'] = ta.bollinger_hband(data["close"]) data['BBL'] = ta.bollinger_lband(data["close"]) data['BBM'] = ta.bollinger_mavg(data["close"]) data['BBHI'] = ta.bollinger_hband_indicator(data["close"]) data['BBLI'] = ta.bollinger_lband_indicator(data["close"]) data['KCHI'] = ta.keltner_channel_hband_indicator(data["high"], data["low"], data["close"]) data['KCLI'] = ta.keltner_channel_lband_indicator(data["high"], data["low"], data["close"]) data['DCHI'] = ta.donchian_channel_hband_indicator(data["close"]) data['DCLI'] = ta.donchian_channel_lband_indicator(data["close"]) data['DR'] = ta.daily_return(data["close"]) data['DLR'] = ta.daily_log_return(data["close"]) if 'volume' in data.columns: data['MFI'] = ta.money_flow_index(data["high"], data["low"], data["close"], data["volume"]) data['ADI'] = ta.acc_dist_index(data["high"], data["low"], data["close"], data["volume"]) data['OBV'] = ta.on_balance_volume(data["close"], data["volume"]) data['CMF'] = ta.chaikin_money_flow(data["high"], data["low"], data["close"], data["volume"]) data['FI'] = ta.force_index(data["close"], data["volume"]) data['EM'] = ta.ease_of_movement(data["high"], data["low"], data["close"], data["volume"]) data['VPT'] = ta.volume_price_trend(data["close"], data["volume"]) data['NVI'] = ta.negative_volume_index(data["close"], data["volume"]) data.fillna(method='bfill', inplace=True) return data except (AssertionError, Exception) as error: raise IndicatorsError(error) LOGGER.error(error)
def enrich_sampleset(df): df['OBV'] = ta.on_balance_volume(df['close'], df['volume']) df['ADX'] = ta.adx(df['high'], df['low'], df['close'], n=14) df['VPT'] = ta.volume_price_trend(df['close'], df['volume']) df['ATR'] = ta.average_true_range(df['high'], df['low'], df['close'], n=14) df['MFI'] = ta.money_flow_index(df['high'], df['low'], df['close'], df['volume']) df['KST'] = ta.kst(df['close']) return ta.utils.dropna(df)
def add_indicators(df): df['RSI'] = ta.rsi(df["Close"]) df['MFI'] = ta.money_flow_index(df["High"], df["Low"], df["Close"], df["Volume"]) df['TSI'] = ta.tsi(df["Close"]) df['UO'] = ta.uo(df["High"], df["Low"], df["Close"]) df['AO'] = ta.ao(df["High"], df["Low"]) df['MACD_diff'] = ta.macd_diff(df["Close"]) df['Vortex_pos'] = ta.vortex_indicator_pos(df["High"], df["Low"], df["Close"]) df['Vortex_neg'] = ta.vortex_indicator_neg(df["High"], df["Low"], df["Close"]) df['Vortex_diff'] = abs(df['Vortex_pos'] - df['Vortex_neg']) df['Trix'] = ta.trix(df["Close"]) df['Mass_index'] = ta.mass_index(df["High"], df["Low"]) df['CCI'] = ta.cci(df["High"], df["Low"], df["Close"]) df['DPO'] = ta.dpo(df["Close"]) df['KST'] = ta.kst(df["Close"]) df['KST_sig'] = ta.kst_sig(df["Close"]) df['KST_diff'] = (df['KST'] - df['KST_sig']) df['Aroon_up'] = ta.aroon_up(df["Close"]) df['Aroon_down'] = ta.aroon_down(df["Close"]) df['Aroon_ind'] = (df['Aroon_up'] - df['Aroon_down']) df['BBH'] = ta.bollinger_hband(df["Close"]) df['BBL'] = ta.bollinger_lband(df["Close"]) df['BBM'] = ta.bollinger_mavg(df["Close"]) df['BBHI'] = ta.bollinger_hband_indicator(df["Close"]) df['BBLI'] = ta.bollinger_lband_indicator(df["Close"]) df['KCHI'] = ta.keltner_channel_hband_indicator(df["High"], df["Low"], df["Close"]) df['KCLI'] = ta.keltner_channel_lband_indicator(df["High"], df["Low"], df["Close"]) df['DCHI'] = ta.donchian_channel_hband_indicator(df["Close"]) df['DCLI'] = ta.donchian_channel_lband_indicator(df["Close"]) df['ADI'] = ta.acc_dist_index(df["High"], df["Low"], df["Close"], df["Volume"]) df['OBV'] = ta.on_balance_volume(df["Close"], df["Volume"]) df['CMF'] = ta.chaikin_money_flow(df["High"], df["Low"], df["Close"], df["Volume"]) df['FI'] = ta.force_index(df["Close"], df["Volume"]) df['EM'] = ta.ease_of_movement(df["High"], df["Low"], df["Close"], df["Volume"]) df['VPT'] = ta.volume_price_trend(df["Close"], df["Volume"]) df['NVI'] = ta.negative_volume_index(df["Close"], df["Volume"]) df['DR'] = ta.daily_return(df["Close"]) df['DLR'] = ta.daily_log_return(df["Close"]) df.fillna(method='bfill', inplace=True) return df
def add_candle_indicators(df, l, ck, hk, lk, vk): df[l + 'rsi'] = ta.rsi(df[ck]) df[l + 'mfi'] = ta.money_flow_index(df[hk], df[lk], df[ck], df[vk]) df[l + 'tsi'] = ta.tsi(df[ck]) df[l + 'uo'] = ta.uo(df[hk], df[lk], df[ck]) df[l + 'ao'] = ta.ao(df[hk], df[lk]) df[l + 'macd_diff'] = ta.macd_diff(df[ck]) df[l + 'vortex_pos'] = ta.vortex_indicator_pos(df[hk], df[lk], df[ck]) df[l + 'vortex_neg'] = ta.vortex_indicator_neg(df[hk], df[lk], df[ck]) df[l + 'vortex_diff'] = abs(df[l + 'vortex_pos'] - df[l + 'vortex_neg']) df[l + 'trix'] = ta.trix(df[ck]) df[l + 'mass_index'] = ta.mass_index(df[hk], df[lk]) df[l + 'cci'] = ta.cci(df[hk], df[lk], df[ck]) df[l + 'dpo'] = ta.dpo(df[ck]) df[l + 'kst'] = ta.kst(df[ck]) df[l + 'kst_sig'] = ta.kst_sig(df[ck]) df[l + 'kst_diff'] = (df[l + 'kst'] - df[l + 'kst_sig']) df[l + 'aroon_up'] = ta.aroon_up(df[ck]) df[l + 'aroon_down'] = ta.aroon_down(df[ck]) df[l + 'aroon_ind'] = (df[l + 'aroon_up'] - df[l + 'aroon_down']) df[l + 'bbh'] = ta.bollinger_hband(df[ck]) df[l + 'bbl'] = ta.bollinger_lband(df[ck]) df[l + 'bbm'] = ta.bollinger_mavg(df[ck]) df[l + 'bbhi'] = ta.bollinger_hband_indicator(df[ck]) df[l + 'bbli'] = ta.bollinger_lband_indicator(df[ck]) df[l + 'kchi'] = ta.keltner_channel_hband_indicator(df[hk], df[lk], df[ck]) df[l + 'kcli'] = ta.keltner_channel_lband_indicator(df[hk], df[lk], df[ck]) df[l + 'dchi'] = ta.donchian_channel_hband_indicator(df[ck]) df[l + 'dcli'] = ta.donchian_channel_lband_indicator(df[ck]) df[l + 'adi'] = ta.acc_dist_index(df[hk], df[lk], df[ck], df[vk]) df[l + 'obv'] = ta.on_balance_volume(df[ck], df[vk]) df[l + 'cmf'] = ta.chaikin_money_flow(df[hk], df[lk], df[ck], df[vk]) df[l + 'fi'] = ta.force_index(df[ck], df[vk]) df[l + 'em'] = ta.ease_of_movement(df[hk], df[lk], df[ck], df[vk]) df[l + 'vpt'] = ta.volume_price_trend(df[ck], df[vk]) df[l + 'nvi'] = ta.negative_volume_index(df[ck], df[vk]) df[l + 'dr'] = ta.daily_return(df[ck]) df[l + 'dlr'] = ta.daily_log_return(df[ck]) df[l + 'ma50'] = df[ck].rolling(window=50).mean() df[l + 'ma100'] = df[ck].rolling(window=100).mean() df[l + '26ema'] = df[[ck]].ewm(span=26).mean() df[l + '12ema'] = df[[ck]].ewm(span=12).mean() df[l + 'macd'] = (df[l + '12ema'] - df[l + '26ema']) df[l + '100sd'] = df[[ck]].rolling(100).std() df[l + 'upper_band'] = df[l + 'ma100'] + (df[l + '100sd'] * 2) df[l + 'lower_band'] = df[l + 'ma100'] - (df[l + '100sd'] * 2) df[l + 'ema'] = df[ck].ewm(com=0.5).mean() df[l + 'momentum'] = df[ck] - 1 return df
def ob(): obv = ta.on_balance_volume(close, volume, fillna=False) OBV = obv[-10:] def order(): # For ascending for i in range(len(OBV) - 1): if OBV[i] - OBV[i + 1] > 0: return False return True if order(): vol_status_obv = "Buy" else: vol_status_obv = "Buy" return vol_status_obv
df["Close"]) ta_df['KCLI'] = ta.keltner_channel_lband_indicator(df["High"], df["Low"], df["Close"]) ta_df['DCH'] = ta.donchian_channel_hband( df["Close"]) ta_df['DCL'] = ta.donchian_channel_lband( df["Close"]) ta_df['DCHI'] = ta.donchian_channel_hband_indicator(df["Close"]) ta_df['DCLI'] = ta.donchian_channel_lband_indicator(df["Close"]) ta_df['ADI'] = ta.acc_dist_index(df["High"], df["Low"], df["Close"], df["Volume BTC"]) ta_df['OBV'] = ta.on_balance_volume(df["Close"], df["Volume BTC"]) ta_df['OBVM'] = ta.on_balance_volume_mean( df["Close"], df["Volume BTC"]) ta_df['CMF'] = ta.chaikin_money_flow(df["High"], df["Low"], df["Close"], df["Volume BTC"]) ta_df['FI'] = ta.force_index(df["Close"], df["Volume BTC"]) ta_df['EM'] = ta.ease_of_movement(df["High"], df["Low"], df["Close"], df["Volume BTC"]) ta_df['VPT'] = ta.volume_price_trend(df["Close"], df["Volume BTC"])
price['Adj. Close'], n=20, ndev=2, fillna=True) X['bollinger_lband_indicator'] = ta.bollinger_lband_indicator( price['Adj. Close'], n=20, ndev=2, fillna=True) X['ema_indicator_21'] = ta.ema_indicator(price['Adj. Close'], n=21, fillna=True) X['ema_indicator_50'] = ta.ema_indicator(price['Adj. Close'], n=50, fillna=True) X['ema_indicator_200'] = ta.ema_indicator(price['Adj. Close'], n=200, fillna=True) X['acc_dist_index'] = ta.acc_dist_index(price['High'], price['Low'], price['Adj. Close'], price['Volume']) X['on_balance_volume'] = ta.on_balance_volume(price['Adj. Close'], price['Volume'], fillna=True) X['chaikin_money_flow'] = ta.chaikin_money_flow(price['High'], price['Low'], price['Adj. Close'], price['Volume'], n=20, fillna=True) X['force_index'] = ta.force_index(price['Adj. Close'], price['Volume'], n=2, fillna=True) X['ease_of_movement'] = ta.ease_of_movement(price['High'], price['Low'], price['Adj. Close'], price['Volume'],
def add_technical_indicators(df): """ Args: df (pd.DataFrame): The processed dataframe returned by `process_data`. Returns: pd.DataFrame: The updated dataframe with the technical indicators inside. Acknowledgements: - Thanks for Adam King for this compilation of technical indicators! The original file and code can be found here: https://github.com/notadamking/RLTrader/blob/e5b83b1571f9fcfa6a67a2a810222f1f1751996c/util/indicators.py """ # Add momentum indicators df["AO"] = ta.ao(df["High"], df["Low"]) df["MFI"] = ta.money_flow_index(df["High"], df["Low"], df["Close"], df["Volume"]) df["RSI"] = ta.rsi(df["Close"]) df["TSI"] = ta.tsi(df["Close"]) df["UO"] = ta.uo(df["High"], df["Low"], df["Close"]) # Add trend indicators df["Aroon_up"] = ta.aroon_up(df["Close"]) df["Aroon_down"] = ta.aroon_down(df["Close"]) df["Aroon_ind"] = (df["Aroon_up"] - df["Aroon_down"]) df["CCI"] = ta.cci(df["High"], df["Low"], df["Close"]) df["DPO"] = ta.dpo(df["Close"]) df["KST"] = ta.kst(df["Close"]) df["KST_sig"] = ta.kst_sig(df["Close"]) df["KST_diff"] = (df["KST"] - df["KST_sig"]) df["MACD_diff"] = ta.macd_diff(df["Close"]) df["Mass_index"] = ta.mass_index(df["High"], df["Low"]) df["Trix"] = ta.trix(df["Close"]) df["Vortex_pos"] = ta.vortex_indicator_pos(df["High"], df["Low"], df["Close"]) df["Vortex_neg"] = ta.vortex_indicator_neg(df["High"], df["Low"], df["Close"]) df["Vortex_diff"] = abs(df["Vortex_pos"] - df["Vortex_neg"]) # Add volatility indicators df["BBH"] = ta.bollinger_hband(df["Close"]) df["BBL"] = ta.bollinger_lband(df["Close"]) df["BBM"] = ta.bollinger_mavg(df["Close"]) df["BBHI"] = ta.bollinger_hband_indicator(df["Close"]) df["BBLI"] = ta.bollinger_lband_indicator(df["Close"]) df["KCHI"] = ta.keltner_channel_hband_indicator(df["High"], df["Low"], df["Close"]) df["KCLI"] = ta.keltner_channel_lband_indicator(df["High"], df["Low"], df["Close"]) df["DCHI"] = ta.donchian_channel_hband_indicator(df["Close"]) df["DCLI"] = ta.donchian_channel_lband_indicator(df["Close"]) # Volume indicators df["ADI"] = ta.acc_dist_index(df["High"], df["Low"], df["Close"], df["Volume"]) df["CMF"] = ta.chaikin_money_flow(df["High"], df["Low"], df["Close"], df["Volume"]) df["EM"] = ta.ease_of_movement(df["High"], df["Low"], df["Close"], df["Volume"]) df["FI"] = ta.force_index(df["Close"], df["Volume"]) df["NVI"] = ta.negative_volume_index(df["Close"], df["Volume"]) df["OBV"] = ta.on_balance_volume(df["Close"], df["Volume"]) df["VPT"] = ta.volume_price_trend(df["Close"], df["Volume"]) # Add miscellaneous indicators df["DR"] = ta.daily_return(df["Close"]) df["DLR"] = ta.daily_log_return(df["Close"]) # Fill in NaN values df.fillna(method="bfill", inplace=True) # First try `bfill` df.fillna(value=0, inplace=True) # Then replace the rest of the NANs with 0s return df
def addTechnicalAnalysisIndicators(df): df['rsi'] = ta.rsi(close, n=14) df['obv'] = ta.on_balance_volume(close, volume, fillna=False) return df
def OBV(self): return std_normalize( ta.on_balance_volume(self.ohclv["close"], self.ohclv["volumeto"]))