-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
94 lines (75 loc) · 2.45 KB
/
test.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
import requests
import json
"""
For the examples we are using 'requests' which is a popular minimalistic python library for making HTTP requests.
Please use 'pip install requests' to add it to your python libraries.
"""
def get_symbol(symbol):
url = "http://d.yimg.com/autoc.finance.yahoo.com/autoc?query={}®ion=1&lang=en".format(symbol)
result = requests.get(url).json()
for x in result['ResultSet']['Result']:
if x['symbol'] == symbol:
return x['name']
company = get_symbol("MSFT")
print(company)
stringdic = {
'blackrock' : 'BLK',
'att' : 'T',
'apple' : 'AAPL',
'microsoft' : 'MSFT',
'google' : 'GOOG',
'facebook' : 'FB',
'nike' : 'NKE',
'southwest' : 'LUV'
}
def convert(tokenized_string_list):
actual_list = []
for company in tokenized_string_list:
if company.lower() in stringdic:
actual_list.append(stringdic[company.lower()])
return actual_list
# def convertstock(stocks, proporitons):
# string = ''
# positioncounter = 0
# for stock in stocks:
# ''.join(string,stock,'~')
# portfolioAnalysisRequest = requests.get("https://www.blackrock.com/tools/hackathon/portfolio-analysis", params={
# 'positions' : 'BLK~50|SNP500~50',
# 'outputFormat': 'json',
# 'calculateExposures': 'true',
# 'calculatePerformance':'true',
# 'prettifyJson':'true'
# })
# portfolioAnalysisRequest.text # get in text string format
# portfolioAnalysisRequest.json() # get as json object
# y = json.loads(portfolioAnalysisRequest.text)
# #print(y)
# y = y['resultMap']['PORTFOLIOS'][0]['portfolios'][0]['returns']['latestPerf'].keys()
# #['riskData']['totalRisk']#['weightedAveragePerformance']
# # : 3,
# # : 1.75,
# # rnrRatingY3 : 2.5,
# # rnrRatingY5 : 3.25,
# # : 3.99,
# # rnrRiskAdjustedReturnY10 : 3.395,
# # rnrRiskAdjustedReturnY3 : 3.525,
# # rnrRiskAdjustedReturnY5 : 3.58,
# # rnrRiskRatingOverall : 1.75,
# # rnrRiskRatingY10 : 1.5,
# # rnrRiskRatingY3 : 1.75,
# # rnrRiskRatingY5 : 2,
# # : 0.6625,
# # rnrRiskScoreY10 : 0.4775,
# # rnrRiskScoreY3 : 0.655,
# # rnrRiskScoreY5 : 0.6425,
# # rnrSecYield : 0.5625,
# # : 0.5775,
# # rnrSharpeRatioY10 : 0.505,
# # rnrSharpeRatioY15 : 0.35,
# # rnrSharpeRatioY3 : 0.465,
# # rnrSharpeRatioY5 : 0.54,
# print(y)
# # print('rating' + str(y['rnrRatingOverall']))
# # print('ret' + str(y['rnrRiskAdjustedReturnOverall']))
# # print('risk' + str(y['rnrRiskScoreOverall']))
# # print('sharpe' + str(y['rnrSharpeRatioY1']))