def preproc(self): self.dat = df = pd.read_csv(self.path) s = np.asanyarray(ta.stoch( df["High"], df["Low"], df["Close"], 14)).reshape( (-1, 1)) - np.asanyarray( ta.stoch_signal(df["High"], df["Low"], df["Close"], 14)).reshape((-1, 1)) m = np.asanyarray(ta.macd(df["Close"])).reshape( (-1, 1)) - np.asanyarray(ta.macd_signal(df["Close"])).reshape( (-1, 1)) trend3 = np.asanyarray(self.dat[["Close"]]) - np.asanyarray( ta.ema(self.dat["Close"], 20)).reshape((-1, 1)) cross1 = np.asanyarray(ta.ema(self.dat["Close"], 20)).reshape( (-1, 1)) - np.asanyarray(ta.ema(self.dat["Close"], 5)).reshape( (-1, 1)) y = np.asanyarray(self.dat[["Open"]]) x = np.concatenate([s, m, cross1], 1) gen = tf.keras.preprocessing.sequence.TimeseriesGenerator( x, y, self.window_size) self.x = [] self.y = [] for i in gen: self.x.extend(i[0].tolist()) self.y.extend(i[1].tolist()) self.x = np.asanyarray( self.x) #.reshape((-1, self.window_size, x.shape[-1])) self.y = np.asanyarray(self.y) self.df = self.x self.trend = self.y
def do_ta(self, data_series): open = Series(data_series['open'].astype('float64')) high = Series(data_series['high'].astype('float64')) low = Series(data_series['low'].astype('float64')) close = Series(data_series['close'].astype('float64')) # Trend # ---------------- ema30 = ta.ema(series=close, periods=30) ema50 = ta.ema(series=close, periods=50) ema100 = ta.ema(series=close, periods=100) ema200 = ta.ema(series=close, periods=200) macd_diff = ta.macd_diff(close=close, n_fast=12, n_slow=26, n_sign=9) macd_signal = ta.macd_signal(close=close, n_fast=12, n_slow=26, n_sign=9) data_series['ema30'] = ema30 data_series['ema50'] = ema50 data_series['ema100'] = ema100 data_series['ema200'] = ema200 data_series['macd_diff'] = macd_diff data_series['macd_signal'] = macd_signal # Momentum # ---------------- rsi = ta.rsi(close=close) stochastic = ta.stoch(high=high, low=low, close=close) data_series['rsi'] = rsi data_series['stochastic'] = stochastic # Volatility # ---------------- bollinger_h = ta.bollinger_hband(close=close) bollinger_l = ta.bollinger_lband(close=close) bollinger_h_indicator = ta.bollinger_hband_indicator(close=close) bollinger_l_indicator = ta.bollinger_lband_indicator(close=close) data_series['bollinger_h'] = bollinger_h data_series['bollinger_l'] = bollinger_l data_series['bollinger_h_indicator'] = bollinger_h_indicator data_series['bollinger_l_indicator'] = bollinger_l_indicator data_series['last_candle_change'] = self.lcc(close=close) return data_series
def preproc(self): self.dat = df = pd.read_csv(self.path) s = np.asanyarray(ta.stoch(df["High"],df["Low"],df["Close"],14)).reshape((-1, 1)) - np.asanyarray(ta.stoch_signal(df["High"],df["Low"],df["Close"],14)).reshape((-1, 1)) x = np.asanyarray(ta.daily_return(df["Close"])).reshape((-1,1)) m = np.asanyarray(ta.macd_diff(df["Close"])).reshape((-1,1)) cross1 = np.asanyarray(ta.ema(self.dat["Close"],20)).reshape((-1, 1)) - np.asanyarray(ta.ema(self.dat["Close"],5)).reshape((-1, 1)) x = np.concatenate([x], 1) y = np.asanyarray(self.dat[["Open"]]) gen = tf.keras.preprocessing.sequence.TimeseriesGenerator(x, y, self.window_size) self.x = [] self.y = [] for i in gen: self.x.extend(i[0].tolist()) self.y.extend(i[1].tolist()) self.x = np.asanyarray(self.x)[1000::] self.y = np.asanyarray(self.y)[1000::] self.df = self.x[-self.STEP_SIZE::] self.trend = self.y[-self.STEP_SIZE::]
lista.append({ 'TimeStamp': A1_Hist['candles'][i]['time'], 'Open': A1_Hist['candles'][i]['mid']['o'], 'High': A1_Hist['candles'][i]['mid']['h'], 'Low': A1_Hist['candles'][i]['mid']['l'], 'Close': A1_Hist['candles'][i]['mid']['c'] }) pd_hist = pd.DataFrame(lista) pd_hist = pd_hist[['TimeStamp', 'Open', 'High', 'Low', 'Close']] pd_hist['TimeStamp'] = pd.to_datetime(pd_hist['TimeStamp']) # -- ---------------------------------------------------------------- Agregar analisis tecnico -- # # -- ---------------------------------------------------------------- ------------------------ -- # pd_hist['ema_Close'] = ta.ema(series=pd_hist['Close'], periods=20) # -- ------------------------------------------------------------------- --------------------- -- # # -- ------------------------------------------------------------------- --------------------- -- # trace0 = go.Scatter(x=pd_hist['TimeStamp'], y=pd_hist['ema_Close'], mode='lines', name='lines0') trace1 = go.Scatter(x=pd_hist['TimeStamp'], y=pd_hist['Close'], mode='lines', name='lines1') data = [trace0, trace1]