aboutsummaryrefslogtreecommitdiffstats
path: root/python/margin_estimates.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/margin_estimates.py')
-rw-r--r--python/margin_estimates.py79
1 files changed, 12 insertions, 67 deletions
diff --git a/python/margin_estimates.py b/python/margin_estimates.py
index 96f676e3..d4c16b94 100644
--- a/python/margin_estimates.py
+++ b/python/margin_estimates.py
@@ -9,8 +9,8 @@ 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
-
+from collateral.citi import get_total_collateral as get_collateral_citi
+from collateral.cs import get_collateral as get_collateral_cs
def html_generator(df, column_name):
formatters = {"excess": "{:,.0f}".format, "receive": "{:,.0f}".format}
@@ -22,67 +22,6 @@ def html_generator(df, column_name):
.render()
)
-
-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()
- )
-
-
-def get_collateral_cs(d: datetime.date, fund="Serenitas"):
- DATA_DIR = DAILY_DIR / fund / "CS_reports"
- collat = {}
- full_name = {
- "Serenitas": "SerenitasCGMF",
- "BowdSt": "BostonBPStLLC",
- }
- for collat_type in ("RVM", "IM", "FXIM"):
- pdf_file = (
- DATA_DIR
- / f"CollateralCptyStatement161{full_name[fund]}{collat_type}_{d:%m%d%Y}.pdf"
- )
- g = iter(load_pdf(pdf_file))
- for e in g:
- if e.text == "Cash USD (US Dollar)":
- next(g)
- value = next(g).text
- collat[collat_type] = float(
- value.strip().replace(",", "").replace("(", "-").replace(")", "")
- )
- break
- return (
- pd.DataFrame.from_dict(collat, orient="index", columns=["amount to receive"])
- .rename_axis("account")
- .reset_index()
- )
-
-
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
@@ -133,8 +72,14 @@ 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)
- cs = get_collateral_cs(args.trade_date)
+ citi_collateral = pd.DataFrame({
+ "account": ["VM", "IM"],
+ "amount to receive": get_collateral_citi(args.trade_date)[2:]})
+ cs_collateral = get_collateral_cs(args.trade_date, "Serenitas")
+ cs_collateral = pd.DataFrame({
+ "account": list(cs_collateral),
+ "amount to receive": cs_collateral.values()
+ })
body = [
"<html><body>",
"<h3> Collateral Estimates Receive/(Pay) at ISDA :</h3>",
@@ -146,9 +91,9 @@ if __name__ == "__main__":
"<h3>Payment Settlements :</h3>",
html_generator(payment_settlements, "receive"),
"<h3>Citi Breakdown :</h3>",
- html_generator(citi, "amount to receive"),
+ html_generator(citi_collateral, "amount to receive"),
"<h3>CS Breakdown :</h3>",
- html_generator(cs, "amount to receive"),
+ html_generator(cs_collateral, "amount to receive"),
"</body></html>",
]