diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/import_quotes.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/python/import_quotes.py b/python/import_quotes.py index b5dde7f5..5c3c9f9c 100644 --- a/python/import_quotes.py +++ b/python/import_quotes.py @@ -9,6 +9,7 @@ import pandas as pd import numpy as np import psycopg2 from sqlalchemy import create_engine +from collections import defaultdict def convert(x): try: @@ -16,8 +17,8 @@ def convert(x): except ValueError: return None -index_list = ['HY9', 'HY10', 'HY15', 'HY17', 'HY19', 'HY21', 'HY22', 'HY23', - 'IG9', 'IG19', 'IG21', 'IG22', 'IG23', 'XO22', 'EU9', 'EU19', 'EU21', 'EU22'] +index_list = ['HY9', 'HY10'] + ['HY' + str(s) for s in range(15, 24)] + ['IG9'] + \ + ['IG' + str(s) for s in range(16, 24)] + ['XO22', 'EU9', 'EU19', 'EU21', 'EU22'] DOC_CLAUSE_MAPPING14 = {'Full Restructuring': 'MM14', 'No Restructuring': 'XR14', @@ -32,7 +33,7 @@ def get_markit_bbg_mapping(database, basketid_list, workdate): doc_clause_mapping = DOC_CLAUSE_MAPPING14 else: doc_clause_mapping = DOC_CLAUSE_MAPPING - markit_bbg_mapping = {} + markit_bbg_mapping = defaultdict(list) all_tickers = set([]) with database.cursor() as c: c.execute("SELECT markit_ticker, markit_tier, spread, currency, cds_curve, " \ @@ -44,7 +45,7 @@ def get_markit_bbg_mapping(database, basketid_list, workdate): doc_clause_mapping[line['doc_clause']], float(line['spread'])/10000) if key==('CESEOP', 'SNRFOR', 'USD', 'XR14', 0.05): key=('CESEOP', 'SNRFOR', 'USD', 'XR', 0.05) - markit_bbg_mapping[key] = line['cds_curve'] + markit_bbg_mapping[key].append(line['cds_curve']) database.commit() return (all_tickers, markit_bbg_mapping) @@ -79,11 +80,12 @@ def insert_cds(database, workdate): for line in csvreader: k = (line['Ticker'], line['Tier'], line['Ccy'], line['DocClause'], float(line['RunningCoupon'])) if k in markit_bbg_mapping: - c.executemany(sqlstr, - [(workdate, t, convert(line[colnames[i]]), convert(line[colnames[i]]), - float(line['RunningCoupon'])*10000, float(line['RunningCoupon'])*10000, - 'MKIT', convert(line['RealRecovery'])/100) - for i, t in enumerate(markit_bbg_mapping[k])]) + for curves in markit_bbg_mapping[k]: + c.executemany(sqlstr, + [(workdate, t, convert(line[colnames[i]]), convert(line[colnames[i]]), + float(line['RunningCoupon'])*10000, float(line['RunningCoupon'])*10000, + 'MKIT', convert(line['RealRecovery'])/100) + for i, t in enumerate(curves)]) tickers_found.add((line['Ticker'], line['Tier'])) database.commit() print(all_tickers-tickers_found) |
