aboutsummaryrefslogtreecommitdiffstats
path: root/python/position.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/position.py')
-rw-r--r--python/position.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/python/position.py b/python/position.py
index 2f3d4473..50f23df1 100644
--- a/python/position.py
+++ b/python/position.py
@@ -1,3 +1,4 @@
+from quantlib.time.date import Friday, nth_weekday, pydate_from_qldate
from serenitas.analytics.bbg_helpers import bbg_retry, retrieve_data
from serenitas.analytics.dates import prev_business_day
from serenitas.utils.db2 import InfDateLoaderPandas
@@ -409,6 +410,51 @@ def update_hyg_vol(conn, session, start_date: datetime.date = None):
conn.commit()
+def update_hyg_vol_surface(conn, session, start_date: datetime.date = None):
+ # year = 2023
+ # months = [3, 4, 5]
+ # expiries = [nth_weekday(3, Wednesday, m, year) for m in months]
+
+ # def bbg_ticker(exp, mon):
+ # exp = f"{exp:%b%y}".upper()
+ # return f"HYG US {exp} {mon} VOL Equity"
+
+ # moneyness = [80, 90, 95, 100, 102.5, 105, 110]
+ # securities = [bbg_ticker(exp, mon) for exp, mon in product(expiries, moneyness)]
+ expiries = [pydate_from_qldate(e) for e in [nth_weekday(3, Friday, 5, 2023)]]
+ strikes = [69, 70, 70.5, 71, 71.5, 72, 72.5, 73, 73.5, 74, 75, 76, 77, 78, 79, 80]
+
+ def bbg_ticker(expiry, option_type, strike):
+ return f"HYG US {expiry:%m/%d/%y} {option_type}{strike} Equity"
+
+ securities = [
+ bbg_ticker(exp, t, s) for exp, s, t in product(expiries, strikes, ("P", "C"))
+ ]
+ d = retrieve_data(
+ session,
+ securities,
+ fields=[
+ "PX_LAST",
+ ],
+ start_date=start_date,
+ )
+ for exp, s, t in product(expiries, strikes, ("P", "C")):
+ data = d[bbg_ticker(exp, t, s)]
+ if "PX_LAST" in data:
+ df = data["PX_LAST"]
+ else:
+ continue
+
+ with conn.cursor() as c:
+ c.executemany(
+ "INSERT INTO hyg_option_quotes(date, expiry, strike, option_type, price) "
+ "VALUES (%s, %s, %s, %s, %s) "
+ "ON CONFLICT DO NOTHING",
+ [(d, exp, s, t, val) for d, val in df.items()],
+ )
+ conn.commit()
+
+
if __name__ == "__main__":
from serenitas.utils.pool import serenitas_pool, dawn_pool
import argparse