diff options
| -rw-r--r-- | python/margin_estimates.py | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/python/margin_estimates.py b/python/margin_estimates.py index 193d5914..0451ff11 100644 --- a/python/margin_estimates.py +++ b/python/margin_estimates.py @@ -6,6 +6,19 @@ import argparse from pandas.tseries.offsets import BDay from io import StringIO import pandas as pd +from premailer import transform + + +def html_generator(df, column_name): + formatters = {"excess": "{:,.0f}".format, "receive": "{:,.0f}".format} + return transform( + df.style.format(formatter=formatters, thousands=",") + .set_table_attributes('border="1"') + .applymap(lambda x: "text-align: right;", subset=[column_name]) + .hide_index() + .render() + ) + if __name__ == "__main__": parser = argparse.ArgumentParser() @@ -30,7 +43,6 @@ if __name__ == "__main__": "JPM": "JP Morgan", "WELLSFCM": "Wells Fargo FCM", } - formatters = {"excess": "{:,.0f}".format, "receive": "{:,.0f}".format} isda_cp = pd.read_sql_query( "SELECT date, broker as counterparty, -sum(amount) as excess FROM strategy_im si WHERE strategy='CSH_CASH' GROUP BY broker, date, fund having date=%s and fund='SERCGMAST' ORDER BY date DESC;", @@ -58,21 +70,21 @@ if __name__ == "__main__": con=dawndb, params=((args.trade_date + BDay(1)).date(), (args.trade_date + BDay(3)).date()), ) - body = ( - f"<h3> Collateral Estimates Receive/(Pay) at ISDA :</h3>\n\n" - + isda_cp.to_html(index=False, formatters=formatters) - + f"<h3> Collateral Estimates Receive/(Pay) at FCM :</h3>\n\n" - + fcm_cp.to_html(index=False, formatters=formatters) - + f"<h3>Payment Settlements By Date :</h3>\n\n" - + payment_settlements_agg.to_html(index=False, formatters=formatters) - + f"<h3>Payment Settlements :</h3>\n\n" - + payment_settlements.to_html(index=False, formatters=formatters) - ) + body = [ + f"<h3> Collateral Estimates Receive/(Pay) at ISDA :</h3>", + html_generator(isda_cp, "excess"), + f"<h3> Collateral Estimates Receive/(Pay) at FCM :</h3>", + html_generator(fcm_cp, "excess"), + f"<h3>Payment Settlements By Date :</h3>", + html_generator(payment_settlements_agg, "receive"), + f"<h3>Payment Settlements :</h3>", + html_generator(payment_settlements, "receive"), + ] em = ExchangeMessage() em.send_email( f"Collateral Estimates {args.trade_date:%Y-%m-%d}", - HTMLBody(body), - ["NYOps@lmcg.com"], + HTMLBody("\n\n".join(body)), + ["fyu@lmcg.com"], ["fyu@lmcg.com"], ) |
