-
Notifications
You must be signed in to change notification settings - Fork 1
/
vxxdata.py
73 lines (57 loc) · 2.76 KB
/
vxxdata.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
import requests
import json
import sys
import requests.packages.urllib3
from datetime import date, time, datetime
from dateutil import parser
requests.packages.urllib3.disable_warnings()
def generateReport(ticker):
r = requests.get('http://www.blackrock.com/tools/hackathon/performance?identifiers=' + ticker, verify=False)
response = r.status_code
if response == 200:
doIt = 0
response = r.json()
try:
json_data = response['resultMap']['RETURNS'][0]
except:
r = requests.get('http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=' + ticker + '®ion=1&lang=en', verify=False)
try:
tickerSym = r.json()['ResultSet']['Result'][0]["symbol"]
except:
return "Sorry, there was an error getting that data, please try again later."
else:
r = requests.get('http://www.blackrock.com/tools/hackathon/performance?identifiers=' + tickerSym, verify=False)
response = r.status_code
if response == 200:
response = r.json()
try:
json_data = response['resultMap']['RETURNS'][0]
except:
return "Sorry, it doesn't look like we have information on that stock."
else:
doIt = 1
else:
doIt = 1
if doIt == 1:
if parser.parse(str(json_data['highDate'])) == datetime.today() or parser.parse(str(json_data['highDate'])) == parser.parse("20181018"):
highTime = 1
else:
highTime = 0
dateString = str(datetime.today().strftime('%Y%m%d'))
dateString = "20181018"
returnsMap = json_data["returnsMap"]
stockInfo = returnsMap[dateString]
upPercentage = json_data['upMonthsPercent']
print(stockInfo)
sharpe = stockInfo['oneYearSharpeRatio']
risk = stockInfo['oneYearRisk']
totalMonths = json_data['totalMonths']
returnsType = json_data['returnsType']
speechOutput = "Here's the BlackRock report on the " + ticker + " stock. "
if highTime == 1:
speechOutput += "It's currently at it's highest price. "
speechOutput += "It typically goes up " + str(round((upPercentage * 100), 2)) + "% of the time, based on the " + str(totalMonths) + " months we have the data for. "
speechOutput += "It usually offers returns " + returnsType.lower() + ", with a one year return on investment of " + str(round(sharpe,2)) + " and a risk of " + str(round(risk,2)) + "."
return speechOutput
if __name__ == "__main__":
print(generateReport("AMZN"))