-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stock.py
167 lines (118 loc) · 6.29 KB
/
Stock.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import urllib.request
import json
class Stock:
def return_all_data_stock(symbol):
api_key = "G3UER06K80CNLHNV"
url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + symbol + "&apikey=" \
+ str(api_key)
data = urllib.request.urlopen(url)
data = json.load(data)
print(data)
def compare_lowest(symbol, date): # date must be in the form yyyy-mm-dd
api_key = "G3UER06K80CNLHNV"
url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + symbol + "&apikey=" \
+ str(api_key)
data = urllib.request.urlopen(url)
data = json.load(data)
current = data["Time Series (Daily)"][date]["3. low"]
lowest = float(data["Time Series (Daily)"][date]["3. low"])
lowest_date = date
for item, datte in data["Time Series (Daily)"].items():
if float(datte["3. low"]) <= float(lowest):
lowest = datte["3. low"]
lowest_date = item
print("Data: " + str(date) + "'s lowest is: " + str(current) + "$/per share compared to " + str(lowest_date) +
" at " +
str(lowest) + "$/per share")
def today_data(symbol):
api_key = "G3UER06K80CNLHNV"
url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + symbol + "&apikey=" \
+ str(api_key)
data = urllib.request.urlopen(url)
data = json.load(data)
iter(data["Time Series (Daily)"])
print(next(iter(data["Time Series (Daily)"].items())))
def data_from_this_date(symbol, date):
api_key = "G3UER06K80CNLHNV"
url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + symbol + "&apikey=" \
+ str(api_key)
data = urllib.request.urlopen(url)
data = json.load(data)
print(data["Time Series (Daily)"][date])
## counts the number of lows repeated beneath a certain bracket the gives a percentage of how likely it will hit it
def predict_low_of_next(symbol, today_date, percentage_in_integer): # the variable is how low it will go in percent form
api_key = "G3UER06K80CNLHNV"
url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + symbol + "&apikey=" \
+ str(api_key)
datea = urllib.request.urlopen(url)
data = json.load(datea)
multiplier = (100 - percentage_in_integer) / 100
percent_low = float(data["Time Series (Daily)"][today_date]["3. low"]) * multiplier
counter = 0
for item, date in data["Time Series (Daily)"].items():
if float(date["3. low"]) <= float(percent_low):
counter = counter + 1
print("There is a " + str(counter / len(data["Time Series (Daily)"]) * 100) + "% likelihood of falling below " +
str(percent_low) + "$")
#return counter / len(data["Time Series (Daily)"] * 100)
def predict_high(symbol, price):
api_key = "G3UER06K80CNLHNV"
url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + symbol + "&apikey=" \
+ str(api_key)
datea = urllib.request.urlopen(url)
data = json.load(datea)
counter = 0
for item, date in data["Time Series (Daily)"].items():
if float(date["3. low"]) >= float(price):
counter = counter + 1
print("There is a " + str(counter / len(data["Time Series (Daily)"]) * 100) +
"% likelihood of climbing to or above " + str(
price) + "$")
def predict_low(symbol, price):
api_key = "G3UER06K80CNLHNV"
url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + symbol + "&apikey=" \
+ str(api_key)
datea = urllib.request.urlopen(url)
data = json.load(datea)
counter = 0
for item, date in data["Time Series (Daily)"].items():
if float(date["3. low"]) <= float(price):
counter = counter + 1
print("There is a " + str(counter / len(data["Time Series (Daily)"]) * 100) +
"% likelihood of falling below " + str(price) + "$")
print("Welcome to Jinda's Stock Data Python Application!")
symbol = input("Please in a valid symbol in all caps: ")
keep_going = True
while keep_going:
print("____________________________________________")
print("Menu Options: |\nD - View All Data |" +
"\nT - View Today's Data |\nC - Compare the Lowest Low |" +
"\nF - Retrieve Data From a Certain Date |\nPP - Predict Lowest from Percentage |" +
"\nPH - Predict Likelihood of the Highest Low |\nPL - Predict Likelihood of the Lowest Low |" +
"\nQ - Quit |")
print(" |")
command = input("Please Choose one of the following: ")
if command == "D":
return_all_data_stock(symbol)
elif command == "T":
today_data(symbol)
elif command == "C":
date_today = input("Please input the today's date in the form yyyy-mm-dd: ")
compare_lowest(symbol, date_today)
elif command == "F":
date_retrieved = input("Please input the date of which you would like to retrieve the data from in the " +
"form of yyyy-mm-dd: ")
data_from_this_date(symbol, date_retrieved)
elif command == "PP":
percentage = input("Please input the drop in percentage that you would like predicted: ")
date_today = input("Please input today's date in the form yyyy-mm-dd: ")
predict_low_of_next(symbol, date_today, float(percentage))
elif command == "PH":
price = input("Please input the high price that you would like predicted: ")
predict_high(symbol, price)
elif command == "PL":
price = input("Please input the low price that you would like predicted: ")
predict_low(symbol, price)
elif command == "Q":
print("See you next time!")
keep_going = False