aboutsummaryrefslogtreecommitdiffstats
path: root/python/citco_monitor.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/citco_monitor.py')
-rw-r--r--python/citco_monitor.py55
1 files changed, 54 insertions, 1 deletions
diff --git a/python/citco_monitor.py b/python/citco_monitor.py
index 7200c92b..dfb22f51 100644
--- a/python/citco_monitor.py
+++ b/python/citco_monitor.py
@@ -1,9 +1,61 @@
import datetime
+from exchangelib import HTMLBody
from serenitas.analytics.dates import prev_business_day
from serenitas.utils.db import dbconn
-from report_ops.utils import check_cleared_cds
+from report_ops.utils import check_cleared_cds, Monitor
+from report_ops.misc import _recon_recipients, _cc_recipients
+
+
+class BondFactorMonitor(
+ Monitor,
+ headers=(
+ "date",
+ "citco_security_id",
+ "security_id",
+ "serenitas_factor",
+ "admin_factor",
+ "difference",
+ ),
+ num_format=[("{0:,.2f}", 3), ("{0:,.2f}", 4), ("{0:,.2f}", 5)],
+):
+ @classmethod
+ def email(cls, fund):
+ if not cls._staging_queue:
+ return
+ cls._em.send_email(
+ f"*ACTION REQUESTED* Incorrect Factors: {fund}",
+ HTMLBody(
+ f"""
+<html>
+ <head>
+ <style>
+ table, th, td {{ border: 1px solid black; border-collapse: collapse;}}
+ th, td {{ padding: 5px; }}
+ </style>
+ </head>
+ <body>
+ Hello,<br><br>We see the below factor rematches. Could you please correct these factors?<br><br>{cls.to_tabulate()}
+ </body>
+</html>"""
+ ),
+ to_recipients=_recon_recipients[fund],
+ cc_recipients=_cc_recipients[fund],
+ )
+
+
+def check_bond_factors(date, fund, conn):
+ with conn.cursor() as c:
+ c.execute(
+ "SELECT citco_security_id, security_id, serenitas_factor, admin_factor, serenitas_factor-admin_factor as difference FROM compare_citco_bonds (%s, %s) WHERE abs(serenitas_factor - admin_factor) > .01;",
+ (date, fund),
+ )
+ for row in c:
+ d = row._asdict() | {"date": date}
+ BondFactorMonitor.stage(d)
+ BondFactorMonitor.email(fund)
+
if __name__ == "__main__":
import argparse
@@ -20,3 +72,4 @@ if __name__ == "__main__":
conn = dbconn("dawndb")
for fund in ("ISOSEL",):
check_cleared_cds(args.cob, fund, conn)
+ check_bond_factors(args.cob, fund, conn)