aboutsummaryrefslogtreecommitdiffstats
path: root/python/markit/import_quotes.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/markit/import_quotes.py')
-rw-r--r--python/markit/import_quotes.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/python/markit/import_quotes.py b/python/markit/import_quotes.py
index e0522b9a..0a8f108e 100644
--- a/python/markit/import_quotes.py
+++ b/python/markit/import_quotes.py
@@ -16,11 +16,14 @@ def convert(x):
except ValueError:
return None
-index_list = ['HY9', 'HY10'] + ['HY' + str(s) for s in range(15, 29)] + ['IG9'] + \
- ['IG' + str(s) for s in range(16, 29)] + \
- ['XO' + str(s) for s in range(22, 28)] + \
- ['EU9'] + \
- ['EU' + str(s) for s in range(19, 28)]
+def get_index_list(database, workdate):
+ with database.cursor() as c:
+ c.execute("SELECT distinct index, series FROM index_maturity " \
+ "WHERE issue_date IS NOT NULL and issue_date <= %s",
+ (workdate,))
+ for index, series in c:
+ yield index + str(series)
+ database.commit()
DOC_CLAUSE_MAPPING14 = {'Full Restructuring': 'MM14',
'No Restructuring': 'XR14',
@@ -31,7 +34,7 @@ DOC_CLAUSE_MAPPING = {'Full Restructuring': 'MM',
'Modified Modified Restructurin': 'MM'}
def get_markit_bbg_mapping(database, basketid_list, workdate):
- if workdate>=datetime.date(2014, 9, 19):
+ if workdate >= datetime.date(2014, 9, 19):
doc_clause_mapping = DOC_CLAUSE_MAPPING14
else:
doc_clause_mapping = DOC_CLAUSE_MAPPING
@@ -40,7 +43,7 @@ def get_markit_bbg_mapping(database, basketid_list, workdate):
with database.cursor() as c:
c.execute("SELECT markit_ticker, markit_tier, spread, currency, cds_curve, " \
" doc_clause FROM historical_cds_issuers(%s) where index_list && %s",
- (workdate, basketid_list))
+ (workdate, list(basketid_list)))
for line in c:
all_tickers.add((line['markit_ticker'], line['markit_tier']))
key = (line['markit_ticker'], line['markit_tier'], line['currency'],
@@ -56,15 +59,14 @@ def get_markit_bbg_mapping(database, basketid_list, workdate):
return (all_tickers, markit_bbg_mapping)
def get_basketids(database, index_list, workdate):
- r = []
with database.cursor() as c:
for index in index_list:
c.execute("SELECT * FROM nameToBasketID(%s, %s)", (index, workdate))
- r.append(c.fetchone()[0])
+ yield c.fetchone()[0]
database.commit()
- return r
def get_current_tickers(database, workdate):
+ index_list = get_index_list(database, workdate)
basketid_list = get_basketids(database, index_list, workdate)
return get_markit_bbg_mapping(database, basketid_list, workdate)