diff options
| -rw-r--r-- | python/env.py | 1 | ||||
| -rw-r--r-- | python/markit/import_quotes.py | 11 |
2 files changed, 6 insertions, 6 deletions
diff --git a/python/env.py b/python/env.py index 3df56531..829fbc08 100644 --- a/python/env.py +++ b/python/env.py @@ -4,3 +4,4 @@ from pathlib import Path DAILY_DIR = Path(os.environ["DAILY_DIR"]) LOG_DIR = Path(os.environ["LOG_DIR"]) DATA_DIR = Path(os.environ["DATA_DIR"]) +BASE_DIR = Path(os.environ["BASE_DIR"]) diff --git a/python/markit/import_quotes.py b/python/markit/import_quotes.py index de9f86bf..2b4eda15 100644 --- a/python/markit/import_quotes.py +++ b/python/markit/import_quotes.py @@ -7,6 +7,7 @@ import os from collections import defaultdict from dataclasses import dataclass +from env import BASE_DIR from itertools import chain from pandas.tseries.offsets import BDay from pyisda.curve import SpreadCurve, DocClause, Seniority @@ -127,7 +128,6 @@ def insert_cds(database, workdate): """ all_tickers, markit_bbg_mapping = get_current_tickers(database, workdate) - filename = "cds eod {0:%Y%m%d}.csv".format(workdate) colnames = [ "Upfront" + tenor for tenor in ["6m", "1y", "2y", "3y", "4y", "5y", "7y", "10y"] ] @@ -153,10 +153,8 @@ def insert_cds(database, workdate): default_table = { (cid, Seniority[seniority]): event_date for cid, seniority, event_date in c } - - with open( - os.path.join(os.environ["BASE_DIR"], "Tranche_data", "CDS", filename) - ) as fh: + CDS_DIR = BASE_DIR / "Tranche_data" / "CDS" + with (CDS_DIR / f"cds eod {workdate:%Y%m%d}.csv").open() as fh: csvreader = csv.DictReader(fh) with database.cursor() as c: for line in csvreader: @@ -200,7 +198,8 @@ def insert_cds(database, workdate): buf = sc.as_buffer(True) for (cid, sen), curves in markit_bbg_mapping[k]: c.execute( - "INSERT INTO cds_curves VALUES(%s, %s, %s, %s)", + "INSERT INTO cds_curves VALUES(%s, %s, %s, %s) " + "ON CONFLICT DO NOTHING", (workdate, cid, sen.name, buf), ) c.executemany( |
