aboutsummaryrefslogtreecommitdiffstats
path: root/python/markit
diff options
context:
space:
mode:
Diffstat (limited to 'python/markit')
-rw-r--r--python/markit/import_quotes.py67
1 files changed, 35 insertions, 32 deletions
diff --git a/python/markit/import_quotes.py b/python/markit/import_quotes.py
index bf20d2da..2fd09bc3 100644
--- a/python/markit/import_quotes.py
+++ b/python/markit/import_quotes.py
@@ -173,7 +173,7 @@ def insert_cds(database, workdate: datetime.date):
next(fh)
csvreader = csv.DictReader(fh)
if fixed:
- g = ((l, int(float(l["RunningCoupon"])) * 10000) for l in csvreader)
+ g = ((l, int(float(l["RunningCoupon"]) * 10000)) for l in csvreader)
else:
# we repeat each line with both values
g = product(csvreader, (100, 500))
@@ -219,55 +219,58 @@ def insert_cds(database, workdate: datetime.date):
)
except ValueError:
logging.error(f"couldn't build curve for {k.ticker}")
- buf = sc.as_buffer(True)
- for (cid, sen), curves in mappings:
- c.execute(
- "INSERT INTO cds_curves VALUES(%s, %s, %s, %s, %s) "
- "ON CONFLICT (date, company_id, seniority) "
- "DO UPDATE SET curve=excluded.curve, redcode=excluded.redcode",
- (workdate, cid, sen.name, line["RedCode"], buf),
- )
- c.executemany(
- sqlstr,
- [
- (
- workdate,
- t,
- upf * 100,
- upf * 100,
- spread,
- spread,
- "MKIT",
- recovery_rates[0],
- )
- for t, upf in zip(curves, upfront_rates)
- ],
- )
- tickers_found.add(k)
+ else:
+ buf = sc.as_buffer(True)
+ for (cid, sen), curves in mappings:
+ c.execute(
+ "INSERT INTO cds_curves VALUES(%s, %s, %s, %s, %s) "
+ "ON CONFLICT (date, company_id, seniority) "
+ "DO UPDATE SET curve=excluded.curve, redcode=excluded.redcode",
+ (workdate, cid, sen.name, line["RedCode"], buf),
+ )
+ c.executemany(
+ sqlstr,
+ [
+ (
+ workdate,
+ t,
+ upf * 100,
+ upf * 100,
+ spread,
+ spread,
+ "MKIT",
+ recovery_rates[0],
+ )
+ for t, upf in zip(curves, upfront_rates)
+ ],
+ )
+ tickers_found.add(k)
database.commit()
tickers_missing = markit_bbg_mapping.keys() - tickers_found
- tickers_missing.remove(CurveKey("JTIUK", "SNRFOR", "EUR", "CR14", 100))
+ jtiuk = CurveKey("JTIUK", "SNRFOR", "EUR", "CR14", 100)
+ if jtiuk in tickers_missing:
+ tickers_missing.remove(jtiuk)
with database.cursor() as c:
for curve_key in tickers_missing:
logger.warning(f"{curve_key.full_ticker} missing for {workdate}")
for (cid, sen), e in markit_bbg_mapping[curve_key]:
c.execute(
- "SELECT date, curve FROM cds_curves "
+ "SELECT date, redcode, curve FROM cds_curves "
"WHERE company_id=%s AND seniority=%s AND date <= %s "
"ORDER BY date desc",
(cid, sen.name, workdate),
)
try:
- date, curve = c.fetchone()
+ date, redcode, curve = c.fetchone()
except TypeError:
logger.error(f"{curve_key.full_ticker} never existed")
else:
if (workdate - date).days < 20: # we copy over the old curve
c.execute(
- "INSERT INTO cds_curves VALUES(%s, %s, %s, %s) "
+ "INSERT INTO cds_curves VALUES(%s, %s, %s, %s, %s) "
"ON CONFLICT (date, company_id, seniority) "
- "DO UPDATE SET curve=excluded.curve",
- (workdate, cid, sen.name, curve),
+ "DO UPDATE SET curve=excluded.curve, redcode=excluded.redcode",
+ (workdate, cid, sen.name, redcode, curve),
)
logger.info(f"Using {date} curve for {curve_key.ticker}")
else: