aboutsummaryrefslogtreecommitdiffstats
path: root/python/report_ops/sma.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/report_ops/sma.py')
-rw-r--r--python/report_ops/sma.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/python/report_ops/sma.py b/python/report_ops/sma.py
new file mode 100644
index 00000000..30a993d4
--- /dev/null
+++ b/python/report_ops/sma.py
@@ -0,0 +1,76 @@
+import datetime
+from dataclasses import dataclass
+from serenitas.utils.db import dbconn
+from serenitas.utils.exchange import ExchangeMessage
+from .misc import _recipients, _cc_recipients
+from exchangelib import FileAttachment
+import pandas as pd
+from io import StringIO
+from typing import ClassVar
+
+
+@dataclass
+class SMA:
+ date: datetime.date
+ fund: str
+ _em: ClassVar = ExchangeMessage()
+
+ def __init_subclass__(cls, fund):
+ cls.fund = fund
+
+ def __init__(self, date):
+ self.date = date
+
+ def get_positions(self):
+ dawndb = dbconn("dawndb")
+ df_blotter = pd.read_sql_query(
+ "SELECT * FROM risk_positions(%s, NULL, %s)",
+ dawndb,
+ params=(self.date, self.fund),
+ index_col=["identifier"],
+ )
+
+ cds_positions = pd.read_sql_query(
+ "SELECT * FROM list_cds_marks_pre(%s, NULL, %s)",
+ dawndb,
+ params=(self.date, self.fund),
+ index_col=["security_id"],
+ )
+ tranche_positions = pd.read_sql_query(
+ "SELECT id, security_id, security_desc, maturity, a.notional, "
+ "protection, orig_attach, orig_detach, tranche_factor, clean_nav, "
+ "accrued, cp_code, cpty_id from list_cds(%s, %s) a "
+ "LEFT JOIN tranche_risk ON id=tranche_id AND date=%s "
+ "WHERE orig_attach IS NOT NULL",
+ dawndb,
+ params=(self.date, self.fund, self.date),
+ index_col=["id"],
+ )
+ return df_blotter, cds_positions, tranche_positions
+
+ def email_positions(self):
+ attachments = []
+ for name, df in zip(("bonds", "cds", "tranches"), (self.get_positions())):
+ buf = StringIO()
+ df.to_csv(buf)
+ attachments.append(
+ FileAttachment(
+ name=f"{self.date} {name}.csv", content=buf.getvalue().encode()
+ )
+ )
+ buf.close()
+ self._em.send_email(
+ f"{self.fund} {self.date} EOD positions ",
+ "",
+ to_recipients=_recipients["HM"],
+ cc_recipients=("bowdoin-ops@lmcg.com",),
+ attach=_cc_recipients[self.fund],
+ )
+
+
+class IsoselSMA(SMA, fund="ISOSEL"):
+ pass
+
+
+class BowdstSMA(SMA, fund="BOWDST"):
+ pass