-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLearning.py
46 lines (33 loc) · 1.33 KB
/
Learning.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
from pymongo import MongoClient
import pandas as pd
import Globals as gb
import Algorithms as algo
class Learning:
def __init__(self,symbol):
client = MongoClient('localhost:27017')
db = client.stockstalker.FiveMinuteStocks
self.symbol = symbol
stocks = db.find({'symbol':symbol}).sort('date',1)
self.df0 = pd.DataFrame(list(stocks))
def make_model(self):
df = self.df0[["m5_change", "m10_change", "m15_change", "m20_change", "m60_change", "rolling_mean"]].astype(float)
df['prediction'] = df['m60_change'].shift(-1)
df = df.fillna(0)
df.loc[df.prediction >= 0, 'prediction'] = 1
df.loc[df.prediction < 0, 'prediction'] = 0
df_len = len(df)
end = int(0.7 * df_len)
features = df.columns[:-1]
x = df[features]
y = df.prediction
x_train = x[:end]
y_train = y[:end]
x_test = x[end:]
y_test = y[end:]
algo.performRFClass(x_train, y_train, x_test, y_test, self.symbol, True)
# performAdaBoostClass(x_train,y_train,x_test,y_test)
# performGTBClass(x_train,y_train,x_test,y_test)
model = Learning('0941')
model.make_model()
model = Learning('AAPL')
model.make_model()