diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/import_quotes.py | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/python/import_quotes.py b/python/import_quotes.py index 887cb626..cff077d2 100644 --- a/python/import_quotes.py +++ b/python/import_quotes.py @@ -15,22 +15,33 @@ def convert(x): except ValueError: return None +index_list = ['HY9', 'HY10', 'HY15', 'HY17', 'HY19', 'HY21', 'HY22', 'HY23' + 'IG9', 'IG19', 'IG21', 'IG22', 'IG23', 'XO22'] + +def doc_clause_from_index(index, date): + if index[:2] in ['HY', 'IG']: + if workdate>=datetime.date(2014, 9, 19): + return 'XR14' + else: + return 'XR' + else: + if workdate>=datetime.date(2014, 9, 19): + return 'MM14' + else: + return 'MM' + def get_current_tickers(database, workdate): - sqlstr = "SELECT markit_ticker, markit_tier, cds_curve from index_members(%s, %s)" + sqlstr = "SELECT markit_ticker, markit_tier, currency, cds_curve from index_members(%s, %s)" markit_bbg_mapping = {} all_tickers = set([]) - if workdate >= datetime.date(2014, 9, 19): - doc_clause = 'XR14' - else: - doc_clause = 'XR' - for index in ['HY9', 'HY10', 'HY15', 'HY17', 'HY19', 'HY21', 'HY22', - 'IG9', 'IG19', 'IG21', 'IG22', 'IG23']: - spread=0.05 if 'HY' in index else 0.01 + for index in index_list: + spread=0.05 if index[:2] in ['XO', 'HY'] else 0.01 + doc_clause = doc_clause_from_index(index, workdate) with database.cursor() as c: c.execute(sqlstr, (index, workdate)) for line in c: all_tickers.add((line['markit_ticker'], line['markit_tier'])) - key = (line['markit_ticker'], line['markit_tier'], 'USD', doc_clause, spread) + key = (line['markit_ticker'], line['markit_tier'], line['currency'], doc_clause, spread) hykey = key[:-1]+(0.05,) if hykey in markit_bbg_mapping: del markit_bbg_mapping[hykey] ## we only keep the tightest quote @@ -53,16 +64,14 @@ def insert_cds(database, workdate): csvreader = csv.DictReader(fh) with database.cursor() as c: for line in csvreader: - tickers_found.add((line['Ticker'], line['Tier'])) k = (line['Ticker'], line['Tier'], line['Ccy'], line['DocClause'], float(line['RunningCoupon'])) - try: + 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])]) - except KeyError: - continue + tickers_found.add((line['Ticker'], line['Tier'])) database.commit() print(all_tickers-tickers_found) @@ -122,7 +131,7 @@ if __name__=="__main__": workdate = datetime.datetime.today()-BDay(1) workdate = workdate.date() #insert_cds(serenitasdb, workdate) - insert_index(serenitasdb, workdate) + # insert_index(serenitasdb, workdate) ## backpopulate single ticker # company_id = 16632863 # with serenitasdb.cursor() as c: @@ -140,3 +149,9 @@ if __name__=="__main__": # mkt_tuple = (tup[1], tup[2]) + ('XR', '0.05', 'USD') # insert_cds_single(serenitasdb, workdate, bbg_tickers, mkt_tuple) # serenitasdb.close() + for f in os.listdir(os.path.join(root, "Tranche_data", "CDS")): + if f.endswith("csv"): + workdate = datetime.datetime.strptime(f.split(" ")[2].split(".")[0], "%Y%m%d") + workdate = workdate.date() + insert_cds(serenitasdb, workdate) + serenitasdb.close() |
