Exemplo n.º 1
0
 def w_r():
     wr = ta.wr(high, low, close, lbp=14, fillna=False)
     WR = wr[-1]
     if 0 >= WR >= 20:
         status7 = "Sell"
     elif -80 <= WR:
         status7 = "Buy"
     else:
         status7 = "Hold"
     return status7
Exemplo n.º 2
0
dd['target_3']=dd['Adj Close'].shift(-3)/dd['Adj Close']-1
dd['target_7']=dd['Adj Close'].shift(-7)/dd['Adj Close']-1
dd['target_14']=dd['Adj Close'].shift(-14)/dd['Adj Close']-1
dd['target_30']=dd['Adj Close'].shift(-30)/dd['Adj Close']-1

dd['s00_return_1']=dd.Close/dd.Close.shift(1)-1
dd['s00_return_3']=dd.Close/dd.Close.shift(3)-1
dd['s03_return_1']=dd.s00_return_1.shift(3)
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)
Exemplo n.º 3
0
import matplotlib.pyplot as plt
import ta

df = pd.read_csv('./data/coinbase_daily.csv')
df = df.dropna().reset_index().sort_values('Date')

ta_df = pd.DataFrame()

ta_df['RSI'] = ta.rsi(df["Close"])
ta_df['MFI'] = ta.money_flow_index(
    df["High"], df["Low"], df["Close"], df["Volume BTC"])
ta_df['TSI'] = ta.tsi(df["Close"])
ta_df['UO'] = ta.uo(df["High"], df["Low"], df["Close"])
ta_df['Stoch'] = ta.stoch(df["High"], df["Low"], df["Close"])
ta_df['Stoch_Signal'] = ta.stoch_signal(df["High"], df["Low"], df["Close"])
ta_df['WR'] = ta.wr(df["High"], df["Low"], df["Close"])
ta_df['AO'] = ta.ao(df["High"], df["Low"])

ta_df['MACD'] = ta.macd(df["Close"])
ta_df['MACD_signal'] = ta.macd_signal(df["Close"])
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"])
Exemplo n.º 4
0
def get_data(context, data_, window):
    # Crear ventana de datos.

    h1 = data_.history(
        context.symbols,
        context.row_features,
        bar_count=window,
        frequency=str(context.bar_period) + "T",
    )

    h1 = h1.swapaxes(2, 0)

    norm_data = []
    close_prices = []

    for i, asset in enumerate(context.assets):
        data = h1.iloc[i]
        close = h1.iloc[i].close
        if context.include_ha:
            ha = heikenashi(data)
            data = pd.concat((data, ha), axis=1)

        for period in [3, 6, 8, 10, 15, 20]:
            data["rsi" + str(period)] = ta.rsi(data.close,
                                               n=period,
                                               fillna=True)
            data["stoch" + str(period)] = ta.stoch(data.high,
                                                   data.low,
                                                   data.close,
                                                   n=period,
                                                   fillna=True)
            data["stoch_signal" + str(period)] = ta.stoch_signal(
                high=data.high,
                low=data.low,
                close=data.close,
                n=period,
                d_n=3,
                fillna=True)

            data["dpo" + str(period)] = ta.dpo(close=data.close,
                                               n=period,
                                               fillna=True)
            data["atr" + str(period)] = ta.average_true_range(high=data.high,
                                                              low=data.low,
                                                              close=data.close,
                                                              n=period,
                                                              fillna=True)

        for period in [6, 7, 8, 9, 10]:
            data["williams" + str(period)] = ta.wr(high=data.high,
                                                   low=data.low,
                                                   close=data.close,
                                                   lbp=period,
                                                   fillna=True)
        for period in [12, 13, 14, 15]:
            data["proc" + str(period)] = ta.trix(close=data.close,
                                                 n=period,
                                                 fillna=True)

        data["macd_diff"] = ta.macd_diff(close=data.close,
                                         n_fast=15,
                                         n_slow=30,
                                         n_sign=9,
                                         fillna=True)

        data["macd_signal"] = ta.macd_signal(close=data.close,
                                             n_fast=15,
                                             n_slow=30,
                                             n_sign=9,
                                             fillna=True)

        data["bb_high_indicator"] = ta.bollinger_hband_indicator(
            close=data.close, n=15, ndev=2, fillna=True)

        data["bb_low_indicator"] = ta.bollinger_lband_indicator(
            close=data.close, n=15, ndev=2, fillna=True)

        data["dc_high_indicator"] = ta.donchian_channel_hband_indicator(
            close=data.close, n=20, fillna=True)

        data["dc_low_indicator"] = ta.donchian_channel_lband_indicator(
            close=data.close, n=20, fillna=True)

        data["ichimoku_a"] = ta.ichimoku_a(high=data.high,
                                           low=data.low,
                                           n1=9,
                                           n2=26,
                                           fillna=True)

        data.fillna(method="bfill")

        # Normalizar los valores
        for feature in data.columns:
            norm_feature = preprocessing.normalize(
                data[feature].values.reshape(-1, 1), axis=0)
            data[feature] = pd.DataFrame(data=norm_feature,
                                         index=data.index,
                                         columns=[feature])

        norm_data.append(data.values)
        close_prices.append(close)
        context.features = data.columns

    return np.array(norm_data), np.array(close_prices)
Exemplo n.º 5
0
                s=7,
                m=14,
                l=28,
                ws=4,
                wm=2,
                wl=1,
                fillna=True)
X['stoch_signal'] = ta.stoch_signal(price['High'],
                                    price['Low'],
                                    price['Adj. Close'],
                                    n=14,
                                    d_n=3,
                                    fillna=True)
X['wr'] = ta.wr(price['High'],
                price['Low'],
                price['Adj. Close'],
                lbp=14,
                fillna=True)
X['ao'] = ta.ao(price['Low'], price['Adj. Close'], s=5, l=34, fillna=True)
X['daily_return'] = ta.daily_return(price['Adj. Close'], fillna=True)
# </editor-fold>

print('creating TA test set')
# <editor-fold desc="Create the test set">
X_test = pd.DataFrame(index=price_test.index,
                      data={
                          'bollinger_hband_indicator':
                          np.array([np.nan] * price_test.index.shape[0])
                      })
X_test['bollinger_hband_indicator'] = ta.bollinger_hband_indicator(
    price_test['Adj. Close'], n=20, ndev=2, fillna=True)
    def get_trayectory(self, t_intervals):
        """
        :param t_intervals: número de intervalos en cada trayectoria
        :return: Datos con características de la trayectoria sintética y precios de cierre en bruto de al misma
        """
        trayectories = []
        closes = []
        p = True
        for i, asset in enumerate(self.context.assets):
            synthetic_return = np.exp(
                self.drift[i] + self.stdev[i] * norm.ppf(np.random.rand((t_intervals * self.frequency) + self.frequency, 1)))
            initial_close = self.close[i, -1]
            synthetic_close = np.zeros_like(synthetic_return)
            synthetic_close[0] = initial_close

            for t in range(1, synthetic_return.shape[0]):
                synthetic_close[t] = synthetic_close[t - 1] * synthetic_return[t]

            OHLC = []

            for t in range(synthetic_return.shape[0]):
                if t % self.frequency == 0 and t > 0:
                    open = synthetic_close[t - self.frequency]
                    high = np.max(synthetic_close[t - self.frequency: t])
                    low = np.min(synthetic_close[t - self.frequency: t])
                    close = synthetic_close[t]

                    OHLC.append([open, high, close, low])

            data = pd.DataFrame(data=OHLC, columns=["open", "high", "low", "close"])

            close = data.close

            if self.context.include_ha:
                ha = heikenashi(data)
                data = pd.concat((data, ha), axis=1)

            for period in [3, 6, 8, 10, 15, 20]:
                data["rsi" + str(period)] = ta.rsi(data.close, n=period, fillna=True)
                data["stoch" + str(period)] = ta.stoch(data.high, data.low, data.close, n=period, fillna=True)
                data["stoch_signal" + str(period)] = ta.stoch_signal(high=data.high,
                                                                     low=data.low,
                                                                     close=data.close,
                                                                     n=period,
                                                                     d_n=3,
                                                                     fillna=True)

                data["dpo" + str(period)] = ta.dpo(close=data.close,
                                                   n=period,
                                                   fillna=True)

                data["atr" + str(period)] = ta.average_true_range(high=data.high,
                                                                  low=data.low,
                                                                  close=data.close,
                                                                  n=period,
                                                                  fillna=True)

            for period in [6, 7, 8, 9, 10]:
                data["williams" + str(period)] = ta.wr(high=data.high,
                                                       low=data.low,
                                                       close=data.close,
                                                       lbp=period,
                                                       fillna=True)
            for period in [12, 13, 14, 15]:
                data["proc" + str(period)] = ta.trix(close=data.close,
                                                     n=period,
                                                     fillna=True)

            data["macd_diff"] = ta.macd_diff(close=data.close,
                                             n_fast=15,
                                             n_slow=30,
                                             n_sign=9,
                                             fillna=True)

            data["macd_signal"] = ta.macd_signal(close=data.close,
                                                 n_fast=15,
                                                 n_slow=30,
                                                 n_sign=9,
                                                 fillna=True)

            data["bb_high_indicator"] = ta.bollinger_hband_indicator(close=data.close,
                                                                     n=15,
                                                                     ndev=2,
                                                                     fillna=True)

            data["bb_low_indicator"] = ta.bollinger_lband_indicator(close=data.close,
                                                                    n=15,
                                                                    ndev=2,
                                                                    fillna=True)

            data["dc_high_indicator"] = ta.donchian_channel_hband_indicator(close=data.close,
                                                                            n=20,
                                                                            fillna=True)

            data["dc_low_indicator"] = ta.donchian_channel_lband_indicator(close=data.close,
                                                                           n=20,
                                                                           fillna=True)

            data["ichimoku_a"] = ta.ichimoku_a(high=data.high,
                                               low=data.low,
                                               n1=9,
                                               n2=26,
                                               fillna=True)

            data.fillna(method="bfill")

            # Normalizar los valores
            for feature in data.columns:
                norm_feature = preprocessing.normalize(data[feature].values.reshape(-1, 1), axis=0)
                data[feature] = pd.DataFrame(data=norm_feature, index=data.index, columns=[feature])

            self.assets = data.columns

            trayectories.append(data.values)
            closes.append(close)

        return np.array(trayectories), np.array(closes)