aboutsummaryrefslogtreecommitdiffstats
path: root/python/parse_baml_swaption.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/parse_baml_swaption.py')
-rw-r--r--python/parse_baml_swaption.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/python/parse_baml_swaption.py b/python/parse_baml_swaption.py
new file mode 100644
index 00000000..51f2e8f6
--- /dev/null
+++ b/python/parse_baml_swaption.py
@@ -0,0 +1,48 @@
+from serenitas.utils.exchange import ExchangeMessage
+import pandas as pd
+from serenitas.utils.db import dawn_engine
+
+columns = [
+ "option_recap",
+ "index_buyer",
+ "index_seller",
+ "trade_date",
+ "effective_date",
+ "execution_time",
+ "notional",
+ "price",
+ "mid_price",
+ "strike",
+ "expiry_date",
+ "option_type",
+ "exercise_clearing_house",
+ "premium_fee",
+ "premium_fee_pay_date",
+ "trade_id",
+ "venue_mic",
+]
+
+
+em = ExchangeMessage()
+for msg in em.get_msgs(path=["AutoBook", "BAML Swaption"]):
+ dfs = pd.read_html(msg.body)
+ trades = []
+ for df in dfs:
+ if len(df[0]) > 5:
+ trade = dict(zip(df[0].values, df[1].values))
+ if "Block" in trade or "Unwind Price" in trade:
+ continue
+ trades.append(trade)
+
+ df = pd.DataFrame.from_dict(trades)
+ df.columns = df.columns.str.lower().str.replace(" ", "_")
+ additional_columns = ["collateral"] if "collateral" in df.columns else []
+ print(additional_columns)
+ df = df[columns + additional_columns]
+
+ try:
+ df.to_sql(
+ "baml_swaption_ticket", index=False, con=dawn_engine, if_exists="append"
+ )
+ except Exception as e:
+ print(e)