-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brains.py
52 lines (42 loc) · 1.27 KB
/
Brains.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
#---------------------------------------------
# Title: Stock Trading Algorithm
# Author: Jack Elkes
# Date: 27SEP2021
#---------------------------------------------
# This will be the file for the logic the bot will use to make trades
import StockSelect as stock
import numpy as np
import sklearn.linear_model as LinearRegression
import ReadTrends as RT
from TradeLogs import *
import datetime
import json
#----------------------------------------
# Find current value
#----------------------------------------
current_value = 5000
#----------------------------------------
# Buy or Sell?
#----------------------------------------
y1 = np.array(RT.day_agg["low"])
y2 = np.array(RT.day_agg["high"])
x = np.arange(y1.shape[0])
x = np.array(x).reshape(-1,1)
model = LinearRegression.LinearRegression()
model.fit(x, y1)
print(model.coef_)
y_pred = model.predict(x)
trade = ""
if y_pred[0] > 0 and current_value <= RT.highest:
print("you should buy")
trade = "Buy"
if y_pred[0] < 0 and current_value > RT.highest:
print("you should sell")
trade = "Sell"
elif current_value < RT.lowest:
print("you should sell")
trade = "Sell"
else:
trade = "Not Sure"
with open('trades.txt', 'w') as outfile:
json.dump(trades, outfile, indent=4, sort_keys=False)