-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject1.py
87 lines (71 loc) · 2.34 KB
/
project1.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
#This is done by me with the idea got from GOOGLE
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
#Get the stock quote
df = pd.read_csv(r"NSE-TATAGLOBAL.csv")
#Show the data
print("\n\tPress 'Enter' key to view first 5 data of NSE-TATAGLOBAL.csv file ")
input()
a = df.head(5)
print(a)
print("\n\n\tPress 'Enter' key to view shape of NSE-TATAGLOBAL.csv file ")
input()
b = df.shape
print(b)
print("\n\n\tPress 'Enter' key to view GRAPH between DATE and CLOSING_PRICE ")
input()
#Visualize the closing price history
plt.figure(figsize=(16,8))
plt.title('Close Price History')
plt.plot(df['Close'])
plt.xlabel('Date',fontsize=18)
plt.ylabel('Close Price USD ($)',fontsize=18)
plt.show()
#Create a new dataframe with only the 'Close' column
data = df.filter(['Close'])
#Converting the dataframe to a numpy array
dataset = data.values
avg = 0
#average of a stream of data
n = len(dataset)
def getAvg(prev_avg, x, n):
return((prev_avg * n + x)/(n+1))
for i in range(n):
avg = getAvg(avg, dataset[i], i)
#Create a new dataframe with only the 'Open' column
data = df.filter(['Open'])
#Converting the dataframe to a numpy array
dataset_Open = data.values
#Create a new dataframe with only the 'High' column
data = df.filter(['High'])
#Converting the dataframe to a numpy array
dataset_High = data.values
#Create a new dataframe with only the 'Low' column
data = df.filter(['Low'])
#Converting the dataframe to a numpy array
dataset_Low = data.values
#Create a new dataframe with only the 'Last' column
data = df.filter(['Last'])
#Converting the dataframe to a numpy array
dataset_Last = data.values
print("\n\n\n\tPress 'Enter' key to view PREDICTED and ACTUAL Stock Values of NSE-TATAGLOBAL company. ")
input()
#for i in range(n):
# a=[(g-h)/20 for g,h in zip(dataset_High,dataset_Low)]
# psp = dataset_Last+ a -0.1
# print(psp)
pred_v = 1
def pred_value(pred_v, x, n, l):
return(((pred_v) - n + x)/(20)+l)
for i in range(n):
pred_v = pred_value(pred_v, dataset_High[i],dataset_Low[i],dataset_Last[i])
asd = float(pred_v)
psp = "{:.3f}".format(asd)
print(" Predicted value: [",psp,"]","\tActual value : ",dataset[i])
print("\n\n\n\t\t==================================")
print("\t\t| Press 'Enter' key to __EXIT__. |")
print("\t\t==================================")
input()