Example #1
0
def calcRoc(dfRatio):
  taOp = ROCIndicator(close=dfRatio["Open"], n=20)
  taHi = ROCIndicator(close=dfRatio["High"], n=20)
  taLo = ROCIndicator(close=dfRatio["Low"], n=20)
  taCl = ROCIndicator(close=dfRatio["Close"], n=20)
  dfRoc = pd.concat([taOp.roc(), taHi.roc(), taLo.roc(), taCl.roc()], axis=1)
  dfRoc.columns = ['Open', 'High', 'Low', 'Close']
  return dfRoc
Example #2
0
def ta_price_rate_of_change(df):
    """
    Price rate of change (ROC) calculation
    :param df: pandas dataframe
    :return: pandas dataframe
    """
    temp_df = df.copy()
    test = ROCIndicator(close=temp_df["Close"])
    # test = ROCIndicator(close=temp_df["Close"], window=mc["proc_period"])
    temp_df["ta_proc"] = test.roc()
    return temp_df
Example #3
0
    batch_size = 31
    symbol = sys.argv[1]

    end = datetime.today()
    start = datetime(2000, 9, 1)
    ETH = pdr.DataReader(symbol,'yahoo',start,end)

    df = pd.DataFrame(data=ETH)

    kama_indicator = KAMAIndicator(close = df["Close"], window = 10, pow1 = 2, pow2 = 30, fillna = False)
    df['kama'] = kama_indicator.kama()

    ppo_indicator = PercentagePriceOscillator(close = df["Close"], window_slow = 20, window_fast = 10, window_sign = 9, fillna = False)
    df['ppo'] = ppo_indicator.ppo()

    roc_indicator = ROCIndicator(close = df["Close"], window = 12, fillna = False)
    df['roc'] = roc_indicator.roc()

    macd_indicator = MACD(close = df["Close"], window_slow = 20, window_fast = 12, window_sign = 9, fillna = False)
    df['macd'] = macd_indicator.macd()

    rsi_indicator = RSIIndicator(close = df["Close"], window = 14, fillna = False)
    df['rsi'] = rsi_indicator.rsi()

    aroon_indicator = AroonIndicator(close = df["Close"], window = 20, fillna = False)
    df['aroon'] = aroon_indicator.aroon_indicator()

    boll_indicator = BollingerBands(close = df["Close"], window = 20, window_dev = 2, fillna = False)
    df['boll_mavg'] = boll_indicator.bollinger_mavg()

    df.rename(columns = {"Close": "price"}, inplace=True)
Example #4
0
 def setUpClass(cls):
     cls._df = pd.read_csv(cls._filename, sep=',')
     cls._params = dict(close=cls._df['Close'], n=12, fillna=False)
     cls._indicator = ROCIndicator(**cls._params)
Example #5
0
 def setUpClass(cls):
     cls._df = pd.read_csv(cls._filename, sep=",")
     cls._params = dict(close=cls._df["Close"], window=12, fillna=False)
     cls._indicator = ROCIndicator(**cls._params)
Example #6
0
def add_momentum_ta(
    df: pd.DataFrame,
    high: str,
    low: str,
    close: str,
    volume: str,
    fillna: bool = False,
    colprefix: str = "",
    vectorized: bool = False,
) -> pd.DataFrame:
    """Add trend technical analysis features to dataframe.

    Args:
        df (pandas.core.frame.DataFrame): Dataframe base.
        high (str): Name of 'high' column.
        low (str): Name of 'low' column.
        close (str): Name of 'close' column.
        volume (str): Name of 'volume' column.
        fillna(bool): if True, fill nan values.
        colprefix(str): Prefix column names inserted
        vectorized(bool): if True, use only vectorized functions indicators

    Returns:
        pandas.core.frame.DataFrame: Dataframe with new features.
    """

    # Relative Strength Index (RSI)
    df[f"{colprefix}momentum_rsi"] = RSIIndicator(close=df[close],
                                                  window=14,
                                                  fillna=fillna).rsi()

    # Stoch RSI (StochRSI)
    indicator_srsi = StochRSIIndicator(close=df[close],
                                       window=14,
                                       smooth1=3,
                                       smooth2=3,
                                       fillna=fillna)
    df[f"{colprefix}momentum_stoch_rsi"] = indicator_srsi.stochrsi()
    df[f"{colprefix}momentum_stoch_rsi_k"] = indicator_srsi.stochrsi_k()
    df[f"{colprefix}momentum_stoch_rsi_d"] = indicator_srsi.stochrsi_d()

    # TSI Indicator
    df[f"{colprefix}momentum_tsi"] = TSIIndicator(close=df[close],
                                                  window_slow=25,
                                                  window_fast=13,
                                                  fillna=fillna).tsi()

    # Ultimate Oscillator
    df[f"{colprefix}momentum_uo"] = UltimateOscillator(
        high=df[high],
        low=df[low],
        close=df[close],
        window1=7,
        window2=14,
        window3=28,
        weight1=4.0,
        weight2=2.0,
        weight3=1.0,
        fillna=fillna,
    ).ultimate_oscillator()

    # Stoch Indicator
    indicator_so = StochasticOscillator(
        high=df[high],
        low=df[low],
        close=df[close],
        window=14,
        smooth_window=3,
        fillna=fillna,
    )
    df[f"{colprefix}momentum_stoch"] = indicator_so.stoch()
    df[f"{colprefix}momentum_stoch_signal"] = indicator_so.stoch_signal()

    # Williams R Indicator
    df[f"{colprefix}momentum_wr"] = WilliamsRIndicator(
        high=df[high], low=df[low], close=df[close], lbp=14,
        fillna=fillna).williams_r()

    # Awesome Oscillator
    df[f"{colprefix}momentum_ao"] = AwesomeOscillatorIndicator(
        high=df[high], low=df[low], window1=5, window2=34,
        fillna=fillna).awesome_oscillator()

    # Rate Of Change
    df[f"{colprefix}momentum_roc"] = ROCIndicator(close=df[close],
                                                  window=12,
                                                  fillna=fillna).roc()

    # Percentage Price Oscillator
    indicator_ppo = PercentagePriceOscillator(close=df[close],
                                              window_slow=26,
                                              window_fast=12,
                                              window_sign=9,
                                              fillna=fillna)
    df[f"{colprefix}momentum_ppo"] = indicator_ppo.ppo()
    df[f"{colprefix}momentum_ppo_signal"] = indicator_ppo.ppo_signal()
    df[f"{colprefix}momentum_ppo_hist"] = indicator_ppo.ppo_hist()

    # Percentage Volume Oscillator
    indicator_pvo = PercentageVolumeOscillator(volume=df[volume],
                                               window_slow=26,
                                               window_fast=12,
                                               window_sign=9,
                                               fillna=fillna)
    df[f"{colprefix}momentum_pvo"] = indicator_pvo.pvo()
    df[f"{colprefix}momentum_pvo_signal"] = indicator_pvo.pvo_signal()
    df[f"{colprefix}momentum_pvo_hist"] = indicator_pvo.pvo_hist()

    if not vectorized:
        # KAMA
        df[f"{colprefix}momentum_kama"] = KAMAIndicator(close=df[close],
                                                        window=10,
                                                        pow1=2,
                                                        pow2=30,
                                                        fillna=fillna).kama()

    return df
Example #7
0
    def applyIndicator(self, full_company_price):
        self.data = full_company_price

        high = self.data['high']
        low = self.data['low']
        close = self.data['close']
        volume = self.data['volume']

        EMA12 = EMAIndicator(close, 12, fillna=False)
        EMA30 = EMAIndicator(close, 20, fillna=False)
        EMA60 = EMAIndicator(close, 60, fillna=False)
        MACD1226 = MACD(close, 26, 12, 9, fillna=False)
        MACD2452 = MACD(close, 52, 24, 18, fillna=False)
        ROC12 = ROCIndicator(close, 12, fillna=False)
        ROC30 = ROCIndicator(close, 30, fillna=False)
        ROC60 = ROCIndicator(close, 60, fillna=False)
        RSI14 = RSIIndicator(close, 14, fillna=False)
        RSI28 = RSIIndicator(close, 28, fillna=False)
        RSI60 = RSIIndicator(close, 60, fillna=False)
        AROON25 = AroonIndicator(close, 25, fillna=False)
        AROON50 = AroonIndicator(close, 50, fillna=False)
        AROON80 = AroonIndicator(close, 80, fillna=False)
        MFI14 = MFIIndicator(high, low, close, volume, 14, fillna=False)
        MFI28 = MFIIndicator(high, low, close, volume, 28, fillna=False)
        MFI80 = MFIIndicator(high, low, close, volume, 80, fillna=False)
        CCI20 = CCIIndicator(high, low, close, 20, 0.015, fillna=False)
        CCI40 = CCIIndicator(high, low, close, 40, 0.015, fillna=False)
        CCI100 = CCIIndicator(high, low, close, 100, 0.015, fillna=False)
        WILLR14 = WilliamsRIndicator(high, low, close, 14, fillna=False)
        WILLR28 = WilliamsRIndicator(high, low, close, 28, fillna=False)
        WILLR60 = WilliamsRIndicator(high, low, close, 60, fillna=False)
        BBANDS20 = BollingerBands(close, 20, 2, fillna=False)
        KC20 = KeltnerChannel(high, low, close, 20, 10, fillna=False)
        STOCH14 = StochasticOscillator(high, low, close, 14, 3, fillna=False)
        STOCH28 = StochasticOscillator(high, low, close, 28, 6, fillna=False)
        STOCH60 = StochasticOscillator(high, low, close, 60, 12, fillna=False)
        CMI20 = ChaikinMoneyFlowIndicator(high,
                                          low,
                                          close,
                                          volume,
                                          20,
                                          fillna=False)
        CMI40 = ChaikinMoneyFlowIndicator(high,
                                          low,
                                          close,
                                          volume,
                                          40,
                                          fillna=False)
        CMI100 = ChaikinMoneyFlowIndicator(high,
                                           low,
                                           close,
                                           volume,
                                           100,
                                           fillna=False)

        self.data['ema12'] = (close - EMA12.ema_indicator()) / close
        self.data['ema30'] = (close - EMA30.ema_indicator()) / close
        self.data['ema60'] = (close - EMA60.ema_indicator()) / close
        self.data['macd1226'] = MACD1226.macd() - MACD1226.macd_signal()
        self.data['macd2452'] = MACD2452.macd() - MACD2452.macd_signal()
        self.data['roc12'] = ROC12.roc()
        self.data['roc30'] = ROC30.roc()
        self.data['roc60'] = ROC60.roc()
        self.data['rsi14'] = RSI14.rsi()
        self.data['rsi28'] = RSI28.rsi()
        self.data['rsi60'] = RSI60.rsi()
        self.data['aroon25'] = AROON25.aroon_indicator()
        self.data['aroon50'] = AROON50.aroon_indicator()
        self.data['aroon80'] = AROON80.aroon_indicator()
        self.data['mfi14'] = MFI14.money_flow_index()
        self.data['mfi28'] = MFI28.money_flow_index()
        self.data['mfi80'] = MFI80.money_flow_index()
        self.data['cci20'] = CCI20.cci()
        self.data['cci40'] = CCI40.cci()
        self.data['cci100'] = CCI100.cci()
        self.data['willr14'] = WILLR14.wr()
        self.data['willr28'] = WILLR28.wr()
        self.data['willr60'] = WILLR60.wr()
        self.data['bband20up'] = (BBANDS20.bollinger_hband() - close) / close
        self.data['bband20down'] = (close - BBANDS20.bollinger_lband()) / close
        self.data['stoch14'] = STOCH14.stoch()
        self.data['stoch28'] = STOCH28.stoch()
        self.data['stoch60'] = STOCH60.stoch()
        self.data['cmi20'] = CMI20.chaikin_money_flow()
        self.data['cmi40'] = CMI40.chaikin_money_flow()
        self.data['cmi100'] = CMI100.chaikin_money_flow()
        self.data['kc20up'] = (KC20.keltner_channel_hband() - close) / close
        self.data['kc20down'] = (close - KC20.keltner_channel_lband()) / close
        return self.data
Example #8
0
def add_momentum_ta(df: pd.DataFrame,
                    high: str,
                    low: str,
                    close: str,
                    volume: str,
                    fillna: bool = False,
                    colprefix: str = ""):
    """Add trend technical analysis features to dataframe.

    Args:
        df (pandas.core.frame.DataFrame): Dataframe base.
        high (str): Name of 'high' column.
        low (str): Name of 'low' column.
        close (str): Name of 'close' column.
        fillna(bool): if True, fill nan values.
        colprefix(str): Prefix column names inserted

    Returns:
        pandas.core.frame.DataFrame: Dataframe with new features.
    """

    # Relative Strength Index (RSI)
    df[f'{colprefix}momentum_rsi'] = RSIIndicator(close=df[close],
                                                  n=14,
                                                  fillna=fillna).rsi()

    # Money Flow Indicator
    df[f'{colprefix}momentum_mfi'] = MFIIndicator(
        high=df[high],
        low=df[low],
        close=df[close],
        volume=df[volume],
        n=14,
        fillna=fillna).money_flow_index()

    # TSI Indicator
    df[f'{colprefix}momentum_tsi'] = TSIIndicator(close=df[close],
                                                  r=25,
                                                  s=13,
                                                  fillna=fillna).tsi()

    # Ultimate Oscillator
    df[f'{colprefix}momentum_uo'] = UltimateOscillatorIndicator(
        high=df[high],
        low=df[low],
        close=df[close],
        s=7,
        m=14,
        len=28,
        ws=4.0,
        wm=2.0,
        wl=1.0,
        fillna=fillna).uo()

    # Stoch Indicator
    indicator = StochIndicator(high=df[high],
                               low=df[low],
                               close=df[close],
                               n=14,
                               d_n=3,
                               fillna=fillna)
    df[f'{colprefix}momentum_stoch'] = indicator.stoch()
    df[f'{colprefix}momentum_stoch_signal'] = indicator.stoch_signal()

    # Williams R Indicator
    df[f'{colprefix}momentum_wr'] = WilliamsRIndicator(high=df[high],
                                                       low=df[low],
                                                       close=df[close],
                                                       lbp=14,
                                                       fillna=fillna).wr()

    # Awesome Oscillator
    df[f'{colprefix}momentum_ao'] = AwesomeOscillatorIndicator(
        high=df[high], low=df[low], s=5, len=34, fillna=fillna).ao()

    # KAMA
    df[f'{colprefix}momentum_kama'] = KAMAIndicator(close=df[close],
                                                    n=10,
                                                    pow1=2,
                                                    pow2=30,
                                                    fillna=fillna).kama()

    # Rate Of Change
    df[f'{colprefix}momentum_roc'] = ROCIndicator(close=df[close],
                                                  n=12,
                                                  fillna=fillna).roc()
    return df
Example #9
0
 def test_roc2(self):
     target = 'ROC'
     result = ROCIndicator(close=self._df['Close'], n=12, fillna=False).roc()
     pd.testing.assert_series_equal(self._df[target].tail(), result.tail(), check_names=False)