-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstockScript.py
More file actions
81 lines (70 loc) · 2.42 KB
/
stockScript.py
File metadata and controls
81 lines (70 loc) · 2.42 KB
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
import requests
import sys
import time
def foo(n):
#tied to multiprocessing
x = getRecommendationMean()
volatility()
y = getPrice()
return float(x) , float(y)
def volatility():
url = "https://finance.yahoo.com/quote/" + TICKER_SYMBOL + "?p=" + TICKER_SYMBOL
r = requests.get(url).text
x = r.find("FIFTY_TWO_WK_RANGE-value")
start = x+44
end = x+61
fin = r[start:end].replace("<", "")
fin = fin.replace("/", "")
fin = fin.replace("t", "")
fin = fin.replace("d", "")
fin = fin.replace(">", "")
fin = fin.replace(",", "")
# print(fin)
middle = fin.find(" - ");
recomendation = str(truncate(float(fin[middle+3:])- float(fin[:middle]),2))
#print(recomendation)
changePerc = (float(fin[middle+3:])- float(fin[:middle]))/ float(fin[:middle])
# print("Change" + str(changePerc))
if changePerc > .75:
lowRisk.append((TICKER, fin[middle+3:]))
if changePerc < .75 and changePerc > .35:
medRisk.append((TICKER, fin[middle+3:]))
if changePerc < .35:
highRisk.append((TICKER, fin[middle+3:]))
def getPrice():
url = "https://finance.yahoo.com/quote/" + TICKER_SYMBOL + "/analysts?p=" + TICKER_SYMBOL
r = requests.get(url).text
r = requests.get(url).text
x = r.find("regularMarketPrice")
return x
def getRecommendationMean():
url = "https://finance.yahoo.com/quote/" + TICKER_SYMBOL + "/analysts?p=" + TICKER_SYMBOL
r = requests.get(url).text
x = r.find("recommendationMean")
# print(r[x+27:x+30])
return r[x+27:x+30]
def truncate(f, n):
'''Truncates/pads a float f to n decimal places without rounding'''
s = '{}'.format(f)
if 'e' in s or 'E' in s:
return '{0:.{1}f}'.format(f, n)
i, p, d = s.partition('.')
return '.'.join([i, (d+'0'*n)[:n]])
sdict = [("Google","GOOG"), ("Go Pro", "GPRO"), ("Snap INC", "Snap"), ("Disney", "DIS"), ("Amazon", "AMZN"), ("NVIDIA", "NVDA"), ("Apple", "AAPL"), ("Microsoft", "MSFT"), ("Facebook", "FB"), ("Twitter", "TWTR"), ("Tesla", "TSLA"), ("Netflix", "NFLX")]
highRisk = [];
medRisk = [];
lowRisk = [];
TICKER_SYMBOL = "DIS"
reccomdation = []
TICKER = "Disney"
sice = []
for i in sdict:
# print(i[0])
TICKER_SYMBOL = i[1]
TICKER = i[0]
num = foo(10)
recc = num[0]
current = num[1]
reccomdation.append((i[0],num,recc)#sice = sorted(reccomdation, key=lambda tup: tup[1])
reccomdation.sort(key=lambda x: x[1])
print(reccomdation)