-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (35 loc) · 1.25 KB
/
main.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
from data import stock
import csv
from datetime import date
from scipy import stats
import os
isolated_column = input("What do you want to predict? (Open/High/Low/Close/Adj Close/Volume): ")
if isolated_column.lower() == "adj close":
isolated_column = "Adj Close"
else:
isolated_column = isolated_column.capitalize()
x = []
y = []
today_column = float()
with open(f"{stock}.csv") as csv_file:
csv_reader = csv.DictReader(csv_file)
line_count = 1
for row in csv_reader:
x.append(float(row[isolated_column]))
y.append(line_count)
line_count += 1
if line_count == 5:
today_column = float(row[isolated_column])
os.remove(f"{stock}.csv")
slope, intercept, r, p, std_err = stats.linregress(x, y)
def model(x):
return slope * x + intercept
wanted_prediction = int(input("How far ahead from today do you want to predict? (in days): ")) + line_count
prediction = model(wanted_prediction)
if today_column < prediction:
print("The prediction is it will be higher (according to the week).")
elif today_column > prediction:
print("The prediction is it will be lower (according to the week).")
else:
print("The prediction is it will stay the same (according to the week).")
print("And the R is:", r)