예제 #1
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)
예제 #2
0
 def f_i():
     fi = ta.force_index(close, volume, n=2, fillna=False)
     FI = fi[-1]
     if FI >= 0:
         vol_status_fi = "Buy"
     elif FI <= 0:
         vol_status_fi = "Sell"
     else:
         vol_status_fi = "Hold"
     return vol_status_fi
예제 #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
def process_data(data):
    data['BB_5'] = ta.bollinger_mavg(
        data['CLOSE'], 5)  #bollinger_moving average 5 trading periods
    data['BB_10'] = ta.bollinger_mavg(
        data['CLOSE'], 10)  #bollinger_moving average 10 trading periods
    data['BB_20'] = ta.bollinger_mavg(
        data['CLOSE'], 20)  # bollinger_moving average 20 periods
    data['ADX'] = ta.adx(data['HIGH'], data['LOW'], data['CLOSE'],
                         14)  #Average Directional Index
    data['ATR'] = ta.average_true_range(data['HIGH'], data['LOW'],
                                        data['CLOSE'], 14)  #Average True Range
    data['CCI'] = ta.cci(data['HIGH'], data['LOW'], data['CLOSE'],
                         14)  #Commodity Channel Index
    data['DCH'] = ta.donchian_channel_hband(
        data['CLOSE'])  #Donchian Channel High Band
    data['DCL'] = ta.donchian_channel_lband(
        data['CLOSE'])  #Donchian Channel Low Band
    data['DPO'] = ta.dpo(data['CLOSE'])  #Detrend Price Oscilator
    data['EMAf'] = ta.ema_fast(
        data['CLOSE'])  #Expornential Moving Average fast
    data['EMAs'] = ta.ema_slow(
        data['CLOSE'])  #Expornential Moving Average slow
    data['FI'] = ta.force_index(
        data['CLOSE'],
        data['VOLUME'])  # Force Index(reveals the value of a trend)
    data['ICHa'] = ta.ichimoku_a(data['HIGH'], data['LOW'])  #Ichimoku A
    data['ICHb'] = ta.ichimoku_b(data['HIGH'], data['LOW'])  #Ichimoku B
    data['KC'] = ta.keltner_channel_central(
        data['HIGH'], data['LOW'], data['CLOSE'])  #Keltner channel(KC) Central
    data['KST'] = ta.kst(
        data['CLOSE']
    )  #KST Oscillator (KST) identify major stock market cycle junctures
    data['MACD'] = ta.macd(
        data['CLOSE'])  # Moving Average convergence divergence
    data['OBV'] = ta.on_balance_volume_mean(
        data['CLOSE'], data['VOLUME'])  # on_balance_volume_mean
    data['RSI'] = ta.rsi(data['CLOSE'])  # Relative Strength Index (RSI)
    data['TRIX'] = ta.trix(
        data['CLOSE']
    )  #Shows the percent rate of change of a triple exponentially smoothed moving average
    data['TSI'] = ta.tsi(data['CLOSE'])  #True strength index (TSI)
    data['ROC1'] = (data['CLOSE'] - data['OPEN']) / data['OPEN']
    data['RET'] = data['CLOSE'].pct_change()
    data['y'] = np.where(data['OPEN'] <= data['CLOSE'], 1, -1)
    data = data.dropna()
    return data
예제 #6
0
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"])
ta_df['NVI'] = ta.negative_volume_index(df["Close"],
                                        df["Volume BTC"])

ta_df['DR'] = ta.daily_return(df["Close"])
ta_df['DLR'] = ta.daily_log_return(df["Close"])
ta_df['CR'] = ta.cumulative_return(df["Close"])

corr = ta_df.corr()
예제 #7
0
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'],
                                            n=20,
                                            fillna=True)
X['volume_price_trend'] = ta.volume_price_trend(price['Adj. Close'],
                                                price['Volume'],
                                                fillna=True)
X['negative_volume_index'] = ta.negative_volume_index(price['Adj. Close'],
                                                      price['Volume'],
                                                      fillna=True)
X['average_true_range'] = ta.average_true_range(price['High'],
                                                price['Low'],
예제 #8
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