aboutsummaryrefslogtreecommitdiffstats
path: root/python/position.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/position.py')
-rw-r--r--python/position.py81
1 files changed, 45 insertions, 36 deletions
diff --git a/python/position.py b/python/position.py
index e3bced7a..cd66952d 100644
--- a/python/position.py
+++ b/python/position.py
@@ -138,29 +138,6 @@ def update_fx(conn, session, currencies):
conn.commit()
-def init_swap_rates(
- conn,
- session,
- tenors=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30],
- start_date=datetime.date(1998, 10, 7),
-):
- securities = [f"USISDA{t:02} Index" for t in tenors]
- data = retrieve_data(
- session, securities, ["PX_LAST"], start_date=datetime.date(1998, 10, 7)
- )
- for t in tenors:
- ticker = f"USISDA{t:02} Index"
- sql_str = (
- f'INSERT INTO USD_swap_fixings(fixing_date, "{t}y") '
- + "VALUES(%s, %s) ON CONFLICT (fixing_date)"
- + f' DO UPDATE SET "{t}y" = excluded."{t}y"'
- )
-
- with conn.cursor() as c:
- c.executemany(sql_str, [(d, r) for d, r in data[ticker]["PX_LAST"].items()])
- conn.commit()
-
-
def init_swaption_vol(
session,
tenors=["A", "C", "F", "I"] + list(range(1, 11)) + [15, 20, 25, 30],
@@ -267,19 +244,35 @@ def update_swaption_vol(
def update_swap_rates(
- conn, session, tenors=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30]
+ conn,
+ session,
+ tenors=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30],
+ start_date: datetime.date = None,
):
- securities = [f"USISDA{t:02} Index" for t in tenors]
- data = retrieve_data(session, securities, ["PX_LAST", "LAST_UPDATE_DT"])
- for t in tenors:
- ticker = f"USISDA{t:02} Index"
- sql_str = (
- f'INSERT INTO USD_swap_fixings(fixing_date, "{t}y") '
- + "VALUES(%(LAST_UPDATE_DT)s, %(PX_LAST)s) ON CONFLICT (fixing_date)"
- + f' DO UPDATE SET "{t}y" = %(PX_LAST)s'
+ securities = {t: f"USISDA{t:02} Index" for t in tenors}
+ if start_date is None:
+ data = retrieve_data(
+ session, list(securities.values()), ["PX_LAST", "LAST_UPDATE_DT"]
)
- with conn.cursor() as c:
- c.execute(sql_str, data[ticker])
+ else:
+ data = retrieve_data(
+ session, list(securities.values()), ["PX_LAST"], start_date=start_date
+ )
+
+ with conn.cursor() as c:
+ for t, ticker in securities.items():
+ sql_str = (
+ f'INSERT INTO USD_swap_fixings(fixing_date, "{t}y") '
+ + "VALUES(%s, %s) ON CONFLICT (fixing_date)"
+ + f' DO UPDATE SET "{t}y" = %s'
+ )
+ d = data[ticker]
+ if start_date is None:
+ c.execute(sql_str, (d["LAST_UPDATE_DT"], d["PX_LAST"], d["PX_LAST"]))
+ else:
+ c.executemany(
+ sql_str, [(date, val, val) for date, val in d["PX_LAST"].items()]
+ )
conn.commit()
@@ -393,6 +386,21 @@ def populate_cashflow_history(conn, session, workdate=None, funds=("SERCGMAST",)
conn.commit()
+def update_hyg_vol(conn, session, start_date: datetime.date = None):
+ d = retrieve_data(
+ session,
+ ["HYG US Equity"],
+ fields=["PX_LAST", "CALL_IMP_VOL_30D", "3MO_CALL_IMP_VOL"],
+ start_date=start_date,
+ )
+ df = d["HYG US Equity"]
+ with conn.cursor() as c:
+ c.executemany(
+ "INSERT INTO hyg_vol_data VALUES (%s, %s, %s, %s)",
+ df.itertuples(index=True),
+ )
+
+
if __name__ == "__main__":
from serenitas.utils.pool import serenitas_pool, dawn_pool
import argparse
@@ -421,8 +429,9 @@ if __name__ == "__main__":
),
)
update_fx(dawn_conn, session, ["EURUSD", "CADUSD"])
- update_swap_rates(serenitas_conn, session)
- update_cash_rates(serenitas_conn, session)
+ update_swap_rates(serenitas_conn, session, start_date=workdate)
+ update_cash_rates(serenitas_conn, session, workdate)
+ update_hyg_vol(serenitas_conn, session, workdate)
for vol_type in ["N", "V", "N_OIS"]:
update_swaption_vol(
serenitas_conn, session, start_from=workdate, vol_type=vol_type