diff options
Diffstat (limited to 'python/bowdst.py')
| -rw-r--r-- | python/bowdst.py | 80 |
1 files changed, 59 insertions, 21 deletions
diff --git a/python/bowdst.py b/python/bowdst.py index f7fab0cc..51ed0a2b 100644 --- a/python/bowdst.py +++ b/python/bowdst.py @@ -29,32 +29,70 @@ def download_messages(em): if not p.exists(): p.write_bytes(attach.content) + def load_report(workdate: datetime.date): p = DAILY_DIR / str(workdate) / "Reports" / f"Asset Detail_{workdate:%d %b %Y}.csv" - df = pd.read_csv(p, thousands=",", parse_dates=["As Of Date", "Maturity Date", "Report Run Date"]) - df = df.drop([ - "Reporting Account Number", "Reporting Account Name", - "Source Account Name", "Xref Security ID", "Country Name", - "Country Code", "Local Currency Name", "Acct Base Currency Name", - "Acct Base Currency Code", "CINS", "Issuer ID", "SEDOL", "Valoren", "Sicovam", - "WPK", "Quick", "Underlying Sec ID", "Loan ID", "Manager", - "Book Yield Value", - "Counterparty", "Ticker with Exchange Code", - "Ticker with Yellow Key", "Acctg Status Update (EDT)", - "Accounting Status", "Primary GSP Account", - "Extended GSP Account Number", "Percent Of Total"], axis=1) + df = pd.read_csv( + p, thousands=",", parse_dates=["As Of Date", "Maturity Date", "Report Run Date"] + ) + df = df.drop( + [ + "Reporting Account Number", + "Reporting Account Name", + "Source Account Name", + "Xref Security ID", + "Country Name", + "Country Code", + "Local Currency Name", + "Acct Base Currency Name", + "Acct Base Currency Code", + "CINS", + "Issuer ID", + "SEDOL", + "Valoren", + "Sicovam", + "WPK", + "Quick", + "Underlying Sec ID", + "Loan ID", + "Manager", + "Book Yield Value", + "Counterparty", + "Ticker with Exchange Code", + "Ticker with Yellow Key", + "Acctg Status Update (EDT)", + "Accounting Status", + "Primary GSP Account", + "Extended GSP Account Number", + "Percent Of Total", + ], + axis=1, + ) df["Source Account Number"] = df["Source Account Number"].str[-4:].astype("int") df.columns = df.columns.str.replace(" ", "_").str.lower() - df = df.rename(columns={ - "shares/par": "current_notional", - "local_unrealized_gain/loss": "local_unrealized_pnl", - "base_unrealized_gain/loss": "base_unrealized_pnl"}) - for col in ['current_notional', 'local_price', 'base_price', 'local_cost', - 'base_cost', - 'local_market_value', 'base_market_value', 'local_unrealized_pnl', - 'base_unrealized_pnl', 'local_notional_cost', - 'base_notional_cost', 'local_notional_value', 'base_notional_value']: + df = df.rename( + columns={ + "shares/par": "current_notional", + "local_unrealized_gain/loss": "local_unrealized_pnl", + "base_unrealized_gain/loss": "base_unrealized_pnl", + } + ) + for col in [ + "current_notional", + "local_price", + "base_price", + "local_cost", + "base_cost", + "local_market_value", + "base_market_value", + "local_unrealized_pnl", + "base_unrealized_pnl", + "local_notional_cost", + "base_notional_cost", + "local_notional_value", + "base_notional_value", + ]: df[col] = df[col].apply(lambda s: s[1:-1] if s.startswith("(") else s) df[col] = pd.to_numeric(df[col].str.replace(",", "")) df["row"] = df.index |
