aboutsummaryrefslogtreecommitdiffstats
path: root/python/markit
diff options
context:
space:
mode:
Diffstat (limited to 'python/markit')
-rw-r--r--python/markit/__main__.py6
-rw-r--r--python/markit/cds.py18
2 files changed, 14 insertions, 10 deletions
diff --git a/python/markit/__main__.py b/python/markit/__main__.py
index 58a5106d..00a05d96 100644
--- a/python/markit/__main__.py
+++ b/python/markit/__main__.py
@@ -83,13 +83,13 @@ elif args.cds:
"version": "5",
"format": "csv",
"report": "FIXED_COUPON",
- "date": workdate.strftime("%Y%m%d"),
+ "date": f"{workdate:%Y%m%d}",
"type": "CDS",
}
if not args.insert_only:
- download_cds_data(payload)
+ download_cds_data(payload, workdate)
payload.update({"type": "CredIndex", "version": 4})
- download_composite_data(payload, historical)
+ download_composite_data(payload, workdate, historical)
serenitasdb = dbconn("serenitasdb")
insert_cds(serenitasdb, workdate)
serenitasdb.close()
diff --git a/python/markit/cds.py b/python/markit/cds.py
index 459d6340..80c7f8d2 100644
--- a/python/markit/cds.py
+++ b/python/markit/cds.py
@@ -16,15 +16,18 @@ def convertToNone(v):
return v if v else None
-def download_cds_data(payload):
+def download_cds_data(payload, workdate):
r = requests.post("https://www.markit.com/export.jsp", params=payload)
content = io.BytesIO(r.content)
+ save_dir = BASE_DIR / "Tranche_data" / "CDS" / f"{workdate:%Y}"
+ if not save_dir.exists():
+ save_dir.mkdir()
+ csv_file = save_dir / f"{workdate}_fixed.csv"
try:
with zipfile.ZipFile(content) as z:
- fname = BASE_DIR / "Tranche_data" / "CDS" / f"cds eod {payload['date']}.csv"
- with fname.open("wb") as f2:
+ with csv_file.open("wb") as f2:
for f in z.namelist():
- if "csv" in f:
+ if f.endswith("csv"):
f1 = z.open(f)
next(f1)
next(f1)
@@ -34,10 +37,11 @@ def download_cds_data(payload):
logger.error(content.getvalue().decode())
-def download_composite_data(payload, historical=False):
+def download_composite_data(payload, workdate, historical=False):
# if historical, we want to maintain the invariant mtime(f)== payload['date'] + BDay(1)
if historical:
- ts = (pd.Timestamp(payload["date"]) + BDay(1)).timestamp()
+ ts = (workdate + BDay(1)).timestamp()
+
for report in ["COMPOSITES", "TRANCHE_COMPOSITES"]:
for family in ["CDX", "ITRAXX-EUROPE"]:
payload.update({"family": family, "report": report})
@@ -46,7 +50,7 @@ def download_composite_data(payload, historical=False):
try:
with zipfile.ZipFile(io.BytesIO(r.content)) as z:
for f in z.namelist():
- if "csv" in f:
+ if f.endswith("csv"):
path = z.extract(
f,
path=os.path.join(