diff options
Diffstat (limited to 'python/markit/rates.py')
| -rw-r--r-- | python/markit/rates.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/python/markit/rates.py b/python/markit/rates.py index 95be7f98..0519d401 100644 --- a/python/markit/rates.py +++ b/python/markit/rates.py @@ -8,6 +8,7 @@ import xml.etree.ElementTree as ET import zipfile from serenitas.analytics.yieldcurve import YC, ql_to_jp from serenitas.analytics.bbg_helpers import retrieve_data +from serenitas.analytics.utils import prev_business_day def downloadMarkitIRData(conn, download_date=datetime.date.today(), currency="USD"): @@ -179,17 +180,24 @@ def update_bbg_desc(conn, session, download_date): def get_bbg_quotes(conn, session, start_from): fields = ["PX_LAST"] + indices = ["SOFRRATE Index", "ESTRON Index"] with conn.cursor() as c: c.execute("SELECT unnest(members) AS bbg_ticker FROM bbg_curves") - tickers = set(t for (t,) in c) - data = retrieve_data(session, tickers, fields, start_date=start_from) - with conn.cursor() as c: - for k, v in data.items(): - c.executemany( - "INSERT INTO bbg_rate_quotes(bbg_ticker, date, quote1) " - "VALUES(%s, %s, %s) " - "ON CONFLICT (date, bbg_ticker) " - "DO UPDATE SET quote1=EXCLUDED.quote1", - [(k, *t) for t in v.itertuples()], - ) - conn.commit() + tickers = set(t for (t,) in c if t not in indices) + + def update_aux(conn, session, tickers, fields, start_from): + data = retrieve_data(session, tickers, fields, start_date=start_from) + with conn.cursor() as c: + for k, v in data.items(): + c.executemany( + "INSERT INTO bbg_rate_quotes(bbg_ticker, date, quote1) " + "VALUES(%s, %s, %s) " + "ON CONFLICT (date, bbg_ticker) " + "DO UPDATE SET quote1=EXCLUDED.quote1", + [(k, *t) for t in v.itertuples()], + ) + conn.commit() + + update_aux(conn, session, tickers, fields, start_from) + # indices are published on a one day lag + update_aux(conn, session, indices, fields, prev_business_day(start_from)) |
