diff options
Diffstat (limited to 'python/collateral')
| -rw-r--r-- | python/collateral/cs.py | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/python/collateral/cs.py b/python/collateral/cs.py index 7f0b18bc..e6babbe4 100644 --- a/python/collateral/cs.py +++ b/python/collateral/cs.py @@ -1,3 +1,4 @@ +import datetime import pandas as pd from . import DAILY_DIR from .common import load_pdf, next_business_day @@ -41,7 +42,7 @@ def download_files(em, count=20, *, fund="Serenitas", **kwargs): p.write_bytes(attach.content) -def get_collateral(d, fund): +def get_collateral(d: datetime.date, fund): DATA_DIR = DAILY_DIR / fund / "CS_reports" collat = 0 full_name = { @@ -63,20 +64,15 @@ def get_collateral(d, fund): return collat -def collateral(d, dawn_trades, *, fund="Serenitas", **kwargs): - collateral = get_collateral(next_business_day(d), fund) +def load_cs_positions(d: datetime.date, fund: str, legacy=False): + if not legacy: + d = next_business_day(d) DATA_DIR = DAILY_DIR / fund / "CS_reports" - if fund == "BowdSt": - df = pd.read_excel( - DATA_DIR / f"CollateralCptyStatement161BostonBPStLLCRVM_{d:%m%d%Y}.xls", - header=5, - skipfooter=29, - ) - df.columns = [c.replace("\n", " ").strip() for c in df.columns] - df = df[1:] - df["Trade ID"] = df["Trade ID"].astype("int").astype("str") - df = df.rename(columns={"Notional1 CCY": "Currency"}) - elif fund == "Serenitas": + full_name = { + "Serenitas": "SerenitasCGMF", + "BowdSt": "BostonBPStLLC", + } + if legacy and fund == "Serenitas": df = pd.read_excel( DATA_DIR / f"DERV048829_{d:%b%d%Y}.xlsx", header=9, skipfooter=50, ) @@ -95,6 +91,22 @@ def collateral(d, dawn_trades, *, fund="Serenitas", **kwargs): "Order No": "Structure ID", } ) + else: + df = pd.read_excel( + DATA_DIR / f"CollateralCptyStatement161{full_name[fund]}RVM_{d:%m%d%Y}.xls", + header=5, + skipfooter=29, + ) + df.columns = [c.replace("\n", " ").strip() for c in df.columns] + df = df[1:] + df["Trade ID"] = df["Trade ID"].astype("int").astype("str") + df = df.rename(columns={"Notional1 CCY": "Currency"}) + return df + + +def collateral(d, dawn_trades, *, fund="Serenitas", **kwargs): + collateral = get_collateral(next_business_day(d), fund) + df = load_cs_positions(d, fund) df = df.merge(dawn_trades, how="left", left_on="Structure ID", right_on="cpty_id") missing_ids = df.loc[df.cpty_id.isnull(), "Structure ID"] if not missing_ids.empty: |
