diff options
Diffstat (limited to 'python/bbg_index_quotes.py')
| -rw-r--r-- | python/bbg_index_quotes.py | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/python/bbg_index_quotes.py b/python/bbg_index_quotes.py index b11d0395..b8f016f5 100644 --- a/python/bbg_index_quotes.py +++ b/python/bbg_index_quotes.py @@ -6,32 +6,44 @@ securities = {} for series in range(9, 32): for index_type in ["IG", "HY"]: for t in [3, 5, 7, 10]: - securities[f"CDX {index_type} CDSI S{series} {t}Y Corp"] = \ - (series, index_type, f"{t}yr") + securities[f"CDX {index_type} CDSI S{series} {t}Y Corp"] = ( + series, + index_type, + f"{t}yr", + ) for series in range(10, 31): for index_type in ["EUR", "XOVER"]: for t in [3, 5, 7, 10]: - securities[f"ITRX {index_type} CDSI S{series} {t}Y Corp"] = \ - (series, index_type, f"{t}yr") + securities[f"ITRX {index_type} CDSI S{series} {t}Y Corp"] = ( + series, + index_type, + f"{t}yr", + ) -place_holders = ",".join(['%s'] * 7) -sql_str_price = ("INSERT INTO index_quotes_pre" - "(date, index, series, version, tenor, close_price, source)" - f" VALUES({place_holders}) ON CONFLICT DO NOTHING") -sql_str_spread = ("INSERT INTO index_quotes_pre" - "(date, index, series, version, tenor, close_spread, source)" - f" VALUES({place_holders}) ON CONFLICT DO NOTHING") +place_holders = ",".join(["%s"] * 7) +sql_str_price = ( + "INSERT INTO index_quotes_pre" + "(date, index, series, version, tenor, close_price, source)" + f" VALUES({place_holders}) ON CONFLICT DO NOTHING" +) +sql_str_spread = ( + "INSERT INTO index_quotes_pre" + "(date, index, series, version, tenor, close_spread, source)" + f" VALUES({place_holders}) ON CONFLICT DO NOTHING" +) start_date = datetime.date.today() - datetime.timedelta(days=7) # one weeek of overlap -conn = dbconn('serenitasdb') +conn = dbconn("serenitasdb") with init_bbg_session(BBG_IP) as session: d = retrieve_data(session, securities.keys(), fields=["TICKER", "VERSION"]) - ticker_mapping = {v['TICKER']: securities[k] + (v['VERSION'],) - for k, v in d.items() if v} + ticker_mapping = { + v["TICKER"]: securities[k] + (v["VERSION"],) for k, v in d.items() if v + } for pcs in ["MSG1", "CMAN", "CBGN"]: securities = [f"{e['TICKER']} {pcs} Curncy" for e in d.values() if e] - d2 = retrieve_data(session, securities, fields=["PX_LAST"], - start_date=start_date) + d2 = retrieve_data( + session, securities, fields=["PX_LAST"], start_date=start_date + ) with conn.cursor() as c: for k, v in d2.items(): ticker = k.split()[0] @@ -45,7 +57,11 @@ with init_bbg_session(BBG_IP) as session: else: sql_str = sql_str_spread if not v.empty: - c.executemany(sql_str, - [(t[0], index, series, version, tenor, t[1], pcs) - for t in v.itertuples()]) + c.executemany( + sql_str, + [ + (t[0], index, series, version, tenor, t[1], pcs) + for t in v.itertuples() + ], + ) conn.commit() |
