diff options
Diffstat (limited to 'python/report_ops')
| -rw-r--r-- | python/report_ops/cash.py | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/python/report_ops/cash.py b/python/report_ops/cash.py index c44362c8..43fda7ed 100644 --- a/python/report_ops/cash.py +++ b/python/report_ops/cash.py @@ -8,7 +8,7 @@ import pandas as pd from serenitas.utils.db import dbconn, dawn_engine from typing import ClassVar from .misc import get_dir, dt_from_fname -from .custodians import NT, UMB +from .custodians import NT, UMB, BNY @dataclass @@ -45,13 +45,15 @@ class IAMDeal(Deal, deal_type=None, table_name="iam_tickets"): @dataclass class CashReport: fund: ClassVar[str] + custodian: ClassVar[str] date: datetime.date _conn: ClassVar[dbconn] = dbconn("dawndb") _staging_queue: ClassVar[set] = set() _insert_sql = "INSERT INTO cash_balances VALUES (%s, %s, %s, %s, %s, %s) ON CONFLICT DO NOTHING" - def __init_subclass__(cls, fund): + def __init_subclass__(cls, fund, custodian): cls.fund = fund + cls.custodian = custodian def to_db(self, report_name): self.download_reports(self.date) @@ -74,8 +76,21 @@ class CashReport: c.executemany(cls._insert_sql, cls._staging_queue) cls._conn.commit() + def stage_from_row(self, row): + (account, currency), amount = row + self._staging_queue.add( + ( + prev_business_day(self.date), + self.fund, + f"{self.custodian} Custody Account {self.fund}", + account, + currency, + amount, + ) + ) -class NTCashReport(CashReport, NT, fund="ISOSEL"): + +class NTCashReport(CashReport, NT, fund="ISOSEL", custodian="NT"): def to_db(self): p = super().to_db("cash_") df = pd.read_csv(p, on_bad_lines="warn") @@ -88,21 +103,8 @@ class NTCashReport(CashReport, NT, fund="ISOSEL"): self.commit() self._staging_queue.clear() - def stage_from_row(self, row): - (account, currency), amount = row - self._staging_queue.add( - ( - prev_business_day(self.date), - self.fund, - f"NT Custody Account {self.fund}", - account, - currency, - amount, - ) - ) - -class UMBCashReport(CashReport, UMB, fund="SERCGMAST"): +class UMBCashReport(CashReport, UMB, fund="SERCGMAST", custodian="UMB"): def to_db(self): p = super().to_db("umb_") df = pd.read_excel(p, skiprows=3) @@ -113,15 +115,16 @@ class UMBCashReport(CashReport, UMB, fund="SERCGMAST"): self.commit() self._staging_queue.clear() - def stage_from_row(self, row): - (account, currency), amount = row - self._staging_queue.add( - ( - prev_business_day(self.date), - self.fund, - f"UMB Custody Account {self.fund}", - account, - currency, - amount, - ) - ) + +class BNYCashReport(CashReport, BNY, fund="BOWDST", custodian="BNY"): + def to_db(self): + p = super().to_db("Live-cash") + df = pd.read_csv(p) + for row in ( + df.groupby(["Account Number", "Local Currency Code"]) + .sum()["Opening Balance Local"] + .items() + ): + self.stage_from_row(row) + self.commit() + self._staging_queue.clear() |
