diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/margin_estimates.py | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/python/margin_estimates.py b/python/margin_estimates.py index ff47abee..dde772cc 100644 --- a/python/margin_estimates.py +++ b/python/margin_estimates.py @@ -1,5 +1,6 @@ from serenitas.utils.db import dbconn from serenitas.utils.exchange import ExchangeMessage, FileAttachment +from serenitas.utils.env import DAILY_DIR from exchangelib import HTMLBody import datetime import argparse @@ -7,6 +8,8 @@ from pandas.tseries.offsets import BDay from io import StringIO import pandas as pd from premailer import transform +from collateral.common import load_pdf, get_col +from collateral.citi import get_df def html_generator(df, column_name): @@ -20,6 +23,38 @@ def html_generator(df, column_name): ) +def get_total_collateral_citi(d): + try: + fname = next( + (DAILY_DIR / "CITI_reports").glob( + f"262966_MarginNotice_{d.strftime('%Y%m%d')}_*.pdf" + ) + ) + except StopIteration: + raise FileNotFoundError(f"CITI file not found for date {d.date()}") + l = load_pdf(fname) + col1 = (370, 500, 70, 250) + col2 = (370, 500, 300, 530) + col3 = (370, 500, 530, 600) + variation_margin = get_df(l, col1, col2, col3) + anchor = next(c for c in l if c.text == "Non Regulatory Initial Margin") + top = int(anchor["top"]) + 10 + bottom = top + 160 + col1 = (top, bottom, 70, 320) + col2 = (top, bottom, 320, 530) + col3 = (top, bottom, 530, 600) + initial_margin = get_df(l, col1, col2, col3) + margins = { + "vm": [-variation_margin.loc["Regulatory VM Requirement", "amount"]], + "im": [-initial_margin.loc["Non Reg IM Requirement Due Customer", "amount"]], + } + return ( + pd.DataFrame.from_dict(margins, orient="index", columns=["amount to receive"]) + .rename_axis("account") + .reset_index() + ) + + if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( @@ -70,6 +105,7 @@ if __name__ == "__main__": con=dawndb, params=((args.trade_date + BDay(1)).date(), (args.trade_date + BDay(3)).date()), ) + citi = get_total_collateral_citi(args.trade_date) body = [ "<html><body>", "<h3> Collateral Estimates Receive/(Pay) at ISDA :</h3>", @@ -80,13 +116,15 @@ if __name__ == "__main__": html_generator(payment_settlements_agg, "receive"), "<h3>Payment Settlements :</h3>", html_generator(payment_settlements, "receive"), - "</html></body>", + "<h3>Citi Breakdown :</h3>", + html_generator(citi, "amount to receive"), + "</body></html>", ] em = ExchangeMessage() em.send_email( f"Collateral Estimates {args.trade_date:%Y-%m-%d}", HTMLBody("".join(body)), - ["NYOps@lmcg.com"], + ["fyu@lmcg.com"], ["fyu@lmcg.com"], ) |
