-
Notifications
You must be signed in to change notification settings - Fork 4
/
predict.py
68 lines (46 loc) · 1.63 KB
/
predict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from sklearn.preprocessing import MinMaxScaler
from collections import deque
from indicator import Indicators
from settings import seq_len, ej
import pandas as pd
import numpy as np
def preprocess_prediciton(iq,symbol,symbols,timeframe):
Actives = symbols
active = symbol
main = pd.DataFrame()
current = pd.DataFrame()
for active in Actives:
if active == symbol:
main = ej.iq_get_fastdata(iq,symbol,timeframe).drop(columns = {'from','to'})
else:
current = ej.iq_get_fastdata(iq,symbol,timeframe)
current = current.drop(columns = {'from','to','open','min','max'})
current.columns = [f'close_{active}',f'volume_{active}']
main = main.join(current)
df = main
"""
graphical analysis components
"""
df.isnull().sum().sum()
df.fillna(method="ffill", inplace=True)
df = df.loc[~df.index.duplicated(keep = 'first')]
df = Indicators(df)
#df = df.drop(columns = {'open','min','max'})
df = df.dropna()
df = df.fillna(method="ffill")
df = df.dropna()
df.sort_index(inplace = True)
scaler = MinMaxScaler()
indexes = df.index
df_scaled = scaler.fit_transform(df)
pred = pd.DataFrame(df_scaled,index = indexes)
sequential_data = []
prev_days = deque(maxlen = seq_len)
for i in pred.iloc[len(pred) -seq_len :len(pred) , :].values:
prev_days.append([n for n in i[:]])
if len(prev_days) == seq_len:
sequential_data.append([np.array(prev_days)])
X = []
for seq in sequential_data:
X.append(seq)
return np.array(X)