diff options
Diffstat (limited to 'python/markit/rates.py')
| -rw-r--r-- | python/markit/rates.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/python/markit/rates.py b/python/markit/rates.py index 25e7ad80..07d1e5f1 100644 --- a/python/markit/rates.py +++ b/python/markit/rates.py @@ -8,14 +8,13 @@ import requests import xml.etree.ElementTree as ET import zipfile from yieldcurve import YC, ql_to_jp -import lz4 from pickle import dumps -def downloadMarkitIRData(download_date = datetime.date.today(), +def downloadMarkitIRData(download_date=datetime.date.today(), currency="USD"): conn = dbconn("serenitasdb") ## T+1 rates are published in the evening - effective_date = download_date + datetime.timedelta(days = 1) + effective_date = download_date + datetime.timedelta(days=1) basedir = os.path.join(root, "data", "Yield Curves") filename = "InterestRates_{0}_{1:%Y%m%d}".format(currency, effective_date) if not os.path.exists(os.path.join(basedir, filename + '.xml')): @@ -24,7 +23,7 @@ def downloadMarkitIRData(download_date = datetime.date.today(), with zipfile.ZipFile(BytesIO(r.content)) as z: z.extractall(path = os.path.join(root, "data", "Yield Curves")) else: - return downloadMarkitIRData(download_date-datetime.timedelta(days=1)) + return downloadMarkitIRData(download_date - datetime.timedelta(days=1)) tree = ET.parse(os.path.join(root, "data", "Yield Curves", filename + '.xml')) deposits = zip([e.text for e in tree.findall('./deposits/*/tenor')], @@ -39,7 +38,7 @@ def downloadMarkitIRData(download_date = datetime.date.today(), jp_yc = ql_to_jp(ql_yc) sql_str = "INSERT INTO {}_curves VALUES(%s, %s) ON CONFLICT DO NOTHING".format(currency) with conn.cursor() as c: - c.execute(sql_str, (effective_date, lz4.block.compress(dumps(jp_yc)))) + c.execute(sql_str, (MarkitData['effectiveasof'], jp_yc.__getstate__())) instruments = MarkitData['deposits'] + MarkitData['swaps'] names = ",".join(['"{}"'.format(r[0]) for r in instruments]) values = ",".join(["%s"] * (len(instruments) + 1)) # +1 for effective_date |
