Skip to content

Instantly share code, notes, and snippets.

@under0tech
Created September 16, 2022 18:16
Show Gist options
  • Save under0tech/1ec42049cd8416587ba28829846ca503 to your computer and use it in GitHub Desktop.
Save under0tech/1ec42049cd8416587ba28829846ca503 to your computer and use it in GitHub Desktop.
def PrepareData(days):
df = init_df.copy()
df['future'] = df['close'].shift(-days)
last_sequence = np.array(df[['close']].tail(days))
df.dropna(inplace=True)
sequence_data = []
sequences = deque(maxlen=N_STEPS)
for entry, target in zip(df[['close'] + ['date']].values, df['future'].values):
sequences.append(entry)
if len(sequences) == N_STEPS:
sequence_data.append([np.array(sequences), target])
last_sequence = list([s[:len(['close'])] for s in sequences]) + list(last_sequence)
last_sequence = np.array(last_sequence).astype(np.float32)
# construct the X's and Y's
X, Y = [], []
for seq, target in sequence_data:
X.append(seq)
Y.append(target)
# convert to numpy arrays
X = np.array(X)
Y = np.array(Y)
return df, last_sequence, X, Y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment