aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/cds_rebook.py47
1 files changed, 45 insertions, 2 deletions
diff --git a/python/cds_rebook.py b/python/cds_rebook.py
index c720fc42..623946ad 100644
--- a/python/cds_rebook.py
+++ b/python/cds_rebook.py
@@ -1,3 +1,5 @@
+from exchange import ExchangeMessage, FileAttachment
+from io import BytesIO
from utils.db import serenitas_pool, dbconn
import datetime
import pandas as pd
@@ -24,9 +26,9 @@ def get_outstanding_positions(conn, trade_date, fcm, fund="SERCGMAST"):
yield from c
-def new_version_quotes(conn, auction_date: datetime.date, recovery, accrual_days):
+def new_version_quotes(conn, auction_date: datetime.date, recovery, accrual_days, coupon=0.05):
adj_recovery = 100 * (
- recovery + accrual_days * 0.05 / 360 - cds_accrued(auction_date, 0.05)
+ recovery + accrual_days * coupon / 360 - cds_accrued(auction_date, coupon)
)
with conn.cursor() as c1, conn.cursor() as c2:
c1.execute(
@@ -155,8 +157,49 @@ def insert_newids(dawndb, d: datetime.date, df: pd.DataFrame):
dawndb.commit()
+def send_csv(dawndb, d: datetime.date, ticker):
+ columns = ["dealid", "folder", "cp_code", "trade_date", "effective_date", "maturity",
+ "currency", "payment_rolldate", "notional", "fixed_rate", "day_count",
+ "frequency", "protection", "security_id", "security_desc", "upfront",
+ "upfront_settle_date", "swap_type", "account_code", "portfolio", "fund",
+ "indexfactor", "version"]
+ buf = BytesIO()
+ with dawndb.cursor() as c:
+ sql_str = (f"COPY (SELECT {','.join(columns)} "
+ "FROM cds "
+ "JOIN index_version "
+ "ON security_id=redindexcode "
+ f"WHERE fund='BOWDST' AND cp_code='CONTRA' AND trade_date='{d}')"
+ " TO STDOUT WITH (FORMAT CSV, HEADER)")
+ c.copy_expert(sql_str, buf)
+ dawndb.commit()
+ buf = buf.getvalue()
+ em = ExchangeMessage()
+ body = f"""Hello,
+
+This are the the rebookings due to {ticker} credit event on {d:%m/%d}. Let me know if you have any questions.
+
+Thanks,
+Guillaume"""
+ em.send_email(f"{ticker} credit event",
+ body,
+ to_recipients=(
+ "caagtradecapture@bnymellon.com",
+ "hm-operations@bnymellon.com",
+ "julie.picariello@bnymellon.com",
+ ),
+ cc_recipients=(
+ "sa1futures.optionsprocessing@bnymellon.com",
+ "bowdoin-ops@lmcg.com",
+ "Viraphong.Douangmany@BNYMellon.com"
+ ),
+ attach=(FileAttachment(name=f"{ticker}_rebooking.csv", content=buf),)
+ )
+
+
if __name__ == "__main__":
conn = serenitas_pool.getconn()
+ dawndb = dbconn("dawndb")
# PKD
# rebook(datetime.date(2019, 1, 24), 101148)
# WINDSSE