aboutsummaryrefslogtreecommitdiffstats
path: root/python/import_cds_quotes.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/import_cds_quotes.py')
-rw-r--r--python/import_cds_quotes.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/python/import_cds_quotes.py b/python/import_cds_quotes.py
index 430ff190..d45a947f 100644
--- a/python/import_cds_quotes.py
+++ b/python/import_cds_quotes.py
@@ -2,7 +2,7 @@ import os
from common import root
import csv
import datetime
-from db import connmlpdb
+from db import serenitasdb
import re, sys
from pandas.tseries.offsets import BDay
import pdb
@@ -13,13 +13,13 @@ def convert(x):
except ValueError:
return None
-def get_current_tickers(connmlpdb, workdate):
+def get_current_tickers(database, workdate):
sqlstr = "SELECT markit_ticker, markit_tier, cds_curve from index_members(%s, %s)"
markit_bbg_mapping = {}
all_tickers = set([])
for index in ['HY9', 'HY10', 'HY15', 'HY17', 'HY19', 'HY21', 'IG9', 'IG19', 'IG21']:
spread=0.05 if 'HY' in index else 0.01
- with connmlpdb.cursor() as c:
+ with database.cursor() as c:
c.execute(sqlstr, (index, workdate))
for line in c:
all_tickers.add((line['markit_ticker'], line['markit_tier']))
@@ -31,20 +31,20 @@ def get_current_tickers(connmlpdb, workdate):
return (all_tickers, markit_bbg_mapping)
-def insert_cds(connmlpdb, workdate):
- all_tickers, markit_bbg_mapping = get_current_tickers(connmlpdb, workdate)
+def insert_cds(database, workdate):
+ all_tickers, markit_bbg_mapping = get_current_tickers(database, workdate)
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)"
tickers_found = set([])
- with connmlpdb.cursor() as c:
+ with database.cursor() as c:
c.execute("DELETE from cds_quotes where date=%s", (workdate,))
- connmlpdb.commit()
+ database.commit()
with open(os.path.join(root, "Tranche_data", "CDS", filename)) as fh:
csvreader = csv.DictReader(fh)
- with connmlpdb.cursor() as c:
+ 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']))
@@ -56,7 +56,7 @@ def insert_cds(connmlpdb, workdate):
for i, t in enumerate(markit_bbg_mapping[k])])
except KeyError:
continue
- connmlpdb.commit()
+ database.commit()
print(all_tickers-tickers_found)
if __name__=="__main__":
@@ -65,4 +65,4 @@ if __name__=="__main__":
else:
workdate = datetime.datetime.today()-BDay(1)
workdate = workdate.date()
- insert_cds(connmlpdb, workdate)
+ insert_cds(serenitasdb, workdate)