diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/report_ops/__main__.py | 6 | ||||
| -rw-r--r-- | python/report_ops/cash.py | 106 |
2 files changed, 52 insertions, 60 deletions
diff --git a/python/report_ops/__main__.py b/python/report_ops/__main__.py index 4124ef08..ac8ad764 100644 --- a/python/report_ops/__main__.py +++ b/python/report_ops/__main__.py @@ -10,7 +10,8 @@ from serenitas.analytics.exceptions import MissingDataError from .sma import SMA from .cash import CashReport from .admin import CitcoReport -from .wires import WireReport + +# from .wires import WireReport from .custodians import upload_to_custodian, get_custodian_download_fun from .utils import notify_payment_settlements, notify_fx_hedge from .misc import _fund_custodians @@ -86,7 +87,8 @@ if args.cash_reports or args.wire_reports: if args.cash_reports: Report = CashReport else: - Report = WireReport + pass + # Report = WireReport for fund, custodians in _fund_custodians.items(): for custodian in custodians: get_custodian_download_fun(custodian)(args.date, fund, em=em) diff --git a/python/report_ops/cash.py b/python/report_ops/cash.py index 2742e1f7..1df97d63 100644 --- a/python/report_ops/cash.py +++ b/python/report_ops/cash.py @@ -74,86 +74,76 @@ class NTCashReport(CashReport, custodian="NT"): class UMBCashReport(CashReport, custodian="UMB"): - @classmethod - def yield_rows(cls, knowledge_date, fund): - df = pd.read_excel(cls.get_report(knowledge_date, fund), skiprows=3) - yield from df.groupby(["Portfolio #", "Currency", "Portfolio Name"]).sum( - numeric_only=True - )["Current Balance"].reset_index().to_dict(orient="records") - - @classmethod - def from_report_line(cls, d): - return cls( - date=prev_business_day(d["knowledge_date"]), - fund=d["fund"], - account_name=d["Portfolio Name"], - account_number=d["Portfolio #"], - currency_code=d["Currency"], - balance=d["Current Balance"], + def __iter__(self): + df = pd.read_excel(self.get_report(), skiprows=3) + df = ( + df.groupby(["Portfolio #", "Currency", "Portfolio Name"]) + .sum(numeric_only=True) + .reset_index() + ) + return ( + (prev_business_day(self.date), self.fund, *t) + for t in df[ + ["Portfolio Name", "Portfolio #", "Currency", "Current Balance"] + ].itertuples(index=False) ) class BNYCashReport(CashReport, custodian="BNY"): - @staticmethod - def get_ts(s): - m = re.search(r"\d{14}", s) - return datetime.datetime.strptime(m[0], "%Y%m%d%H%M%S") - - @classmethod - def yield_rows(cls, knowledge_date, fund): - df = pd.read_csv(cls.get_report(knowledge_date, fund)) + def __iter__(self): + df = pd.read_csv(self.get_report()) df["Beginning Balance Local"] = df["Beginning Balance Local"].apply( lambda s: "-" + s[1:-1] if s.startswith("(") else s ) df["Beginning Balance Local"] = pd.to_numeric( df["Beginning Balance Local"].str.replace(",", "") ) - yield from df.groupby( - ["Account Number", "Account Name", "Local Currency Code"] - ).sum(numeric_only=True).reset_index().to_dict(orient="records") - - @classmethod - def from_report_line(cls, d): - return cls( - date=prev_business_day(d["knowledge_date"]), - fund=d["fund"], - account_name=d["Account Name"], - account_number=d["Account Number"], - currency_code=d["Local Currency Code"], - balance=d["Beginning Balance Local"], + df = ( + df.groupby(["Account Number", "Account Name", "Local Currency Code"]) + .sum(numeric_only=True) + .reset_index() ) + return ( + (prev_business_day(self.date), self.fund, *t) + for t in df[ + [ + "Account Name", + "Account Number", + "Local Currency Code", + "Beginning Balance Local", + ] + ].itertuples(index=False) + ) + + @staticmethod + def get_ts(s): + m = re.search(r"\d{14}", s) + return datetime.datetime.strptime(m[0], "%Y%m%d%H%M%S") class ScotiaCashReport(CashReport, custodian="SCOTIA"): - @classmethod - def yield_rows(cls, knowledge_date, fund): - p = cls.get_report(knowledge_date, fund) + def __iter__(self): + p = self.get_report() df = pd.read_excel(p, skipfooter=1) - if df.empty: # No wires, so we can't skip the footer + if df.empty: df = pd.read_excel(p) - yield df.to_dict(orient="records")[0] - - @classmethod - def from_report_line(cls, d): - return cls( - date=prev_business_day(d["knowledge_date"]), - fund=d["fund"], - account_name=d["Account Name"], - account_number=d["Account"], - currency_code="USD", - balance=d["Opening Bal."], + rec = df.iloc[0] + yield ( + prev_business_day(self.date), + self.fund, + rec["Account Name"], + rec["Account"], + "USD", + rec["Opening Bal."], ) - @classmethod - def get_report(cls, knowledge_date, fund): + def get_report(self): REPORT_DIR = DAILY_DIR / "Selene" / "Scotia_reports" try: return next( REPORT_DIR.glob( - f"IsoSelene_{prev_business_day(knowledge_date):%d-%b-%Y}_*_xlsx.JOAAPKO3.JOAAPKO1" + f"IsoSelene_{prev_business_day(self.date):%d-%b-%Y}_*_xlsx.JOAAPKO3.JOAAPKO1" ) ) except StopIteration as e: - raise MissingDataError( - f"Report not ready {knowledge_date}: {cls.custodian} {fund}" - ) + raise MissingDataError(f"Report not ready {self.date}: {self.custodian}") |
