Example #1
0
 def kst():
     kst = ta.kst(close,
                  r1=10,
                  r2=15,
                  r3=20,
                  r4=30,
                  n1=10,
                  n2=10,
                  n3=10,
                  n4=15,
                  fillna=False)
     kst_sig = ta.kst_sig(close,
                          r1=10,
                          r2=15,
                          r3=20,
                          r4=30,
                          n1=10,
                          n2=10,
                          n3=10,
                          n4=15,
                          nsig=9,
                          fillna=False)
     if kst[-1] < kst_sig[-1]:
         trn_kst_status = "Sell"
     elif kst[-1] > kst_sig[-1]:
         trn_kst_status = "Buy"
     else:
         trn_kst_status = "Hold"
     return trn_kst_status
Example #2
0
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)
Example #3
0
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
Example #5
0
def add_indicators(df):
    df['RSI'] = ta.rsi(df["Close"])
    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['DR'] = ta.daily_return(df["Close"])
    df['DLR'] = ta.daily_log_return(df["Close"])

    df.fillna(method='bfill', inplace=True)

    return df
Example #6
0
dd['s03_return_3']=dd.s00_return_3.shift(3)
dd['s05_return_1']=dd.s00_return_1.shift(5)
dd['s05_return_3']=dd.s00_return_3.shift(5)


dd['s00_rsi_14']=ta.rsi(dd.Close, 14)
dd['s00_rsi_7']=ta.rsi(dd.Close, 7)
dd['s00_willR_14']=ta.wr(dd.High,dd.Low,dd.Close,14)
dd['s00_willR_7']=ta.wr(dd.High,dd.Low,dd.Close,7)
dd['s00_stoch_sig_14_3']=ta.stoch_signal(dd.High,dd.Low,dd.Close,14,3)
dd['s00_stoch_sig_7_3']=ta.stoch_signal(dd.High,dd.Low,dd.Close,7,3)
dd['s00_cci_20_0015']=ta.cci(dd.High,dd.Low,dd.Close,20,0.015)
dd['s00_cci_20_005']=ta.cci(dd.High,dd.Low,dd.Close,20,0.05)
dd['s00_macd_12_26_9']=ta.macd_diff(dd.Close,12,26,9)
dd['s00_macd_7_14_9']=ta.macd_diff(dd.Close,7,14, 9)
dd['s00_kst_9']=ta.kst(dd.Close)-ta.kst_sig(dd.Close)

dd['s01_rsi_14']=dd.s00_rsi_14.shift(+1)
dd['s01_rsi_7']=dd.s00_rsi_7.shift(+1)
dd['s01_willR_14']=dd.s00_willR_14.shift(+1)
dd['s01_willR_7']=dd.s00_willR_7.shift(+1)
dd['s01_stoch_sig_14_3']=dd.s00_stoch_sig_14_3.shift(+1)
dd['s01_stoch_sig_7_3']=dd.s00_stoch_sig_7_3.shift(+1)
dd['s01_cci_20_0015']=dd.s00_cci_20_0015.shift(+1)
dd['s01_cci_20_005']=dd.s00_cci_20_005.shift(+1)
dd['s01_macd_12_26_9']=dd.s00_macd_12_26_9.shift(+1)
dd['s01_macd_7_14_9']=dd.s00_macd_7_14_9.shift(+1)
dd['s01_kst_9']=dd.s00_kst_9.shift(+1)

dd['s03_rsi_14']=dd.s00_rsi_14.shift(+3)
dd['s03_rsi_7']=dd.s00_rsi_7.shift(+3)
Example #7
0
ta_df['MACD_diff'] = ta.macd_diff(df["Close"])
ta_df['EMA_fast'] = ta.ema_indicator(df["Close"])
ta_df['EMA_slow'] = ta.ema_indicator(df["Close"])
ta_df['Vortex_pos'] = ta.vortex_indicator_pos(
    df["High"], df["Low"], df["Close"])
ta_df['Vortex_neg'] = ta.vortex_indicator_neg(
    df["High"], df["Low"], df["Close"])
ta_df['Vortex_diff'] = abs(
    ta_df['Vortex_pos'] -
    ta_df['Vortex_neg'])
ta_df['Trix'] = ta.trix(df["Close"])
ta_df['Mass_index'] = ta.mass_index(df["High"], df["Low"])
ta_df['CCI'] = ta.cci(df["High"], df["Low"], df["Close"])
ta_df['DPO'] = ta.dpo(df["Close"])
ta_df['KST'] = ta.kst(df["Close"])
ta_df['KST_sig'] = ta.kst_sig(df["Close"])
ta_df['KST_diff'] = (
    ta_df['KST'] -
    ta_df['KST_sig'])
ta_df['Ichimoku_a'] = ta.ichimoku_a(df["High"], df["Low"], visual=True)
ta_df['Ichimoku_b'] = ta.ichimoku_b(df["High"], df["Low"], visual=True)
ta_df['Aroon_up'] = ta.aroon_up(df["Close"])
ta_df['Aroon_down'] = ta.aroon_down(df["Close"])
ta_df['Aroon_ind'] = (
    ta_df['Aroon_up'] -
    ta_df['Aroon_down']
)

ta_df['ATR'] = ta.average_true_range(
    df["High"],
    df["Low"],
Example #8
0
                                n=9,
                                n2=25,
                                fillna=True)
X['cci'] = ta.cci(price['High'],
                  price['Low'],
                  price['Adj. Close'],
                  n=20,
                  c=1,
                  fillna=True)
X['dpo'] = ta.dpo(price['Adj. Close'], n=20, fillna=True)
X['kst_sig'] = ta.kst_sig(price['Adj. Close'],
                          r1=10,
                          r2=15,
                          r3=20,
                          r4=30,
                          n1=10,
                          n2=10,
                          n3=10,
                          n4=15,
                          nsig=9,
                          fillna=True)
X['ichimoku_a'] = ta.ichimoku_a(price['High'],
                                price['Low'],
                                n1=9,
                                n2=26,
                                fillna=True)
X['ichimoku_b'] = ta.ichimoku_b(price['High'],
                                price['Low'],
                                n2=26,
                                n3=52,
                                fillna=True)
Example #9
0
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