diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/monthend_interest_recon.py | 60 |
1 files changed, 23 insertions, 37 deletions
diff --git a/python/monthend_interest_recon.py b/python/monthend_interest_recon.py index 0c39a0a8..c62261e2 100644 --- a/python/monthend_interest_recon.py +++ b/python/monthend_interest_recon.py @@ -1,9 +1,6 @@ from serenitas.utils.env import DAILY_DIR from serenitas.utils.exchange import ExchangeMessage import datetime -from collateral.baml_isda import download_from_secure_id -from bs4 import BeautifulSoup -from urllib.parse import urlsplit, parse_qs, urlunsplit import logging import argparse @@ -11,7 +8,6 @@ from collateral.common import load_pdf from pathlib import Path import pandas as pd from collections import defaultdict -import shutil from interest_statement import export_data from dateutil.relativedelta import relativedelta @@ -21,18 +17,12 @@ logger = logging.getLogger(__name__) def get_fpath(counterparty, save=False): - match (counterparty, save): - case (counterparty, False): - return ( - DAILY_DIR / "Serenitas" / "MonthlyInterest" / f"{counterparty}_reports" - ) - case _: - return ( - DAILY_DIR - / "Serenitas" - / f"{counterparty}_reports" - / "Interest Statements" - ) + if save: + return ( + DAILY_DIR / "Serenitas" / f"{counterparty}_reports" / "Interest Statements" + ) + else: + return DAILY_DIR / "Serenitas" / "MonthlyInterest" / f"{counterparty}_reports" def download_messages(em, counterparty, start, end, save=False): @@ -54,7 +44,7 @@ def download_messages(em, counterparty, start, end, save=False): def get_CS(g): - for e in list(g)[-1]: + for e in g[-1]: if "This interest, margin" in e.text: if value == "No Accruals to Report": return 0 @@ -62,10 +52,10 @@ def get_CS(g): value = e.text -def get_BNP(g): - for e in g: +def get_BNP(l): + for e, n in zip(l, l[1:]): if "Due to" in e.text: - value = next(g).text.replace(",", "") + value = n.text.replace(",", "") return -float(value) @@ -76,10 +66,10 @@ def get_CITI(path): return -row._6 -def get_GS(g): - for e in g: +def get_GS(l): + for e, n in zip(l, l[1:]): if "due to" in e.text: - return float(next(g).text.replace("USD", "").replace(",", "")) + return float(n.text.replace("USD", "").replace(",", "")) def get_MS(path): @@ -87,12 +77,10 @@ def get_MS(path): return -round(df["LOCAL_ACCRUAL"].sum(), 2) -def get_BAML(g): - for e in g: +def get_BAML(l): + for e, n in zip(l, l[1:]): if "Net interest Amount" in e.text: - return -float( - next(g).text.replace("(", "-").replace(")", "").replace(",", "") - ) + return -float(n.text.replace("(", "-").replace(")", "").replace(",", "")) def get_JPM(g): @@ -117,18 +105,16 @@ def get_interest(counterparties, save=False): func = globals()[f"get_{cp}"] except KeyError: print(f"Missing cp {cp}") + base_path = Path("/home/serenitas/Daily/Serenitas/MonthlyInterest/") if cp in ("CITI", "MS"): - for file in Path( - f"/home/serenitas/Daily/Serenitas/MonthlyInterest/{cp}_reports" - ).glob("*.xls*"): - amount = func(file) + for p in (base_path / f"{cp}_reports").glob("*.xls*"): + if p.name.startswith("~"): + continue + amount = func(p) interest_amounts[cp] = interest_amounts[cp] + amount else: - for file in Path( - f"/home/serenitas/Daily/Serenitas/MonthlyInterest/{cp}_reports" - ).glob("*.pdf"): - g = iter(load_pdf(file, pages=True if cp == "CS" else False)) - amount = func(g) + for p in (base_path / f"{cp}_reports").glob("*.pdf"): + amount = func(load_pdf(p, pages=True if cp == "CS" else False)) interest_amounts[cp] = interest_amounts[cp] + amount return pd.DataFrame(interest_amounts, index=[0]).T.rename( index={"BAML": "BAML_ISDA"}, columns={0: "monthly_statement"} |
