diff options
Diffstat (limited to 'python/import_cds_quotes.py')
| -rw-r--r-- | python/import_cds_quotes.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/python/import_cds_quotes.py b/python/import_cds_quotes.py index 3ccdac28..a5328b21 100644 --- a/python/import_cds_quotes.py +++ b/python/import_cds_quotes.py @@ -63,6 +63,27 @@ def insert_cds(database, workdate): database.commit() print(all_tickers-tickers_found) +def insert_cds_single(database, workdate, bbgtickers, mkt_tuple): + filename = "cds eod {0}.csv".format(datetime.datetime.strftime(workdate, "%Y%m%d")) + colnames = ['Upfront'+tenor for tenor in ['6m', '1y', '2y', '3y', '4y', '5y', '7y', '10y']] + sqlstr = "INSERT INTO cds_quotes(date, curve_ticker, upfrontbid, upfrontask," \ + "runningbid, runningask, source, recovery) VALUES(%s, %s, %s, %s, %s, %s, %s, %s)" + with open(os.path.join(root, "Tranche_data", "CDS", filename)) as fh: + csvreader = csv.DictReader(fh) + with database.cursor() as c: + for line in csvreader: + if (line['Ticker'], line['Tier'], line['DocClause'], line['RunningCoupon'], line['Ccy']) == \ + mkt_tuple: + try: + 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(bbgtickers)]) + except psycopg2.IntegrityError: + database.rollback() + database.commit() + if __name__=="__main__": if len(sys.argv)>=2: workdate = datetime.datetime.strptime(sys.argv[1], "%Y-%m-%d") @@ -70,3 +91,12 @@ if __name__=="__main__": workdate = datetime.datetime.today()-BDay(1) workdate = workdate.date() insert_cds(serenitasdb, workdate) + ## backpopulate single ticker + # bbgtickers = ['CT675194bis', 'CT406651bis', 'CT406655bis', 'CX404662bis', 'CX404666bis', + # 'CX404670bis', 'CX404678bis', 'CX404690bis'] + # mkt_tuple = ('REALOGR', 'SNRFOR', 'XR', "0.05", 'USD') + # 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_single(serenitasdb, workdate, bbgtickers, mkt_tuple) |
