예제 #1
0
파일: enrich.py 프로젝트: scasb/deeptrades
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)
예제 #2
0
        def adx():
            adx = ta.adx(high, low, close, n=14, fillna=False)
            adxn = ta.adx_neg(high, low, close, n=14, fillna=False)
            adxp = ta.adx_pos(high, low, close, n=14, fillna=False)

            if adxp[-1] > adxn[-1]:
                trn_adx_status = " Buy"
            elif adxp[-1] < adxn[-1]:
                trn_adx_status = " Sell"
            else:
                trn_adx_status = " Hold"
            return trn_adx_status
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
예제 #4
0
    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
        """
        self.synthetic_return = np.exp(
            self.drift + self.stdev * norm.ppf(np.random.rand((t_intervals * self.frequency) + self.frequency, 1)))
        self.initial_close = self.close.iloc[-1]
        self.synthetic_close = np.zeros_like(self.synthetic_return)
        self.synthetic_close[0] = self.initial_close

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

        OHLC = []

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

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

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

        close_prices = data.close

        if self.context.include_ha:
            ha = heikenashi(data)
            data = pd.concat((data, ha), axis=1)
        if self.context.include_wadl:
            wad = wadl(data, 15)
            wad = wad.fillna(method="bfill")
            data = pd.concat((data, wad), 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["adx" + str(period)] = ta.adx(high=data.high,
                                               low=data.low,
                                               close=data.close,
                                               n=period,
                                               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 periiod 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["cci"] = ta.cci(high=data.high,
                             low=data.low,
                             close=data.close,
                             n=15,
                             c=0.015,
                             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["ichimoku_b"] = ta.ichimoku_b(high=data.high,
                                           low=data.low,
                                           n1=9,
                                           n2=26,
                                           fillna=True)



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

        return data.values, close_prices