forked from sostrader/thesisbot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
predict.py
executable file
·61 lines (38 loc) · 1.27 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
from sklearn.preprocessing import MinMaxScaler
from collections import deque
from indicator import Indicators
from settings import mt, seq_len
import pandas as pd
import numpy as np
import time
def preprocess_prediciton(symbol,timeframe):
df = mt.history(symbol,timeframe,1)
print("predict",df)
"""
strategy analysis components
"""
df.isnull().sum().sum()
df.fillna(method="ffill", inplace=True)
df = df.loc[~df.index.duplicated(keep = 'first')]
start_time = time.time()
df = Indicators(df)
print(("--- %s seconds ---" % (time.time() - start_time)))
df = df.drop("return_next", 1)
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)