Skip to content

Instantly share code, notes, and snippets.

@semio
Last active January 4, 2019 09:42
Show Gist options
  • Save semio/3a8a5f0c8c282c4b17b0170271c17dc9 to your computer and use it in GitHub Desktop.
Save semio/3a8a5f0c8c282c4b17b0170271c17dc9 to your computer and use it in GitHub Desktop.
将msci A股指数成份列表的ISIN转为A股代码..
import pandas as pd
import requests as req
path_to_china_a_constituents = './China_A_constituents_FINAL-Aug2018.xlsx'
df = pd.read_excel(path_to_china_a_constituents, sheet_name='China A Inclusion', skiprows=4)
res = []
for n in df['ISIN']:
print(n)
# session = requests_retry_session()
j = req.get('https://www.morningstar.com/api/v2/search/securities/5/usquote-v2/?q={}'.format(str.lower(n))).json()
res_ = []
if j is not None and j['result']['msg'] == 'success':
for m in j['m']:
for r in m['r']:
print("\t", r["OS001"])
res_.append(r['OS001'])
# assert len(res_) == 1
res.append(res_[0])
df['A share code'] = res
df.to_csv(out_path, index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment