diff options
Diffstat (limited to 'python/collateral/gs_fcm.py')
| -rw-r--r-- | python/collateral/gs_fcm.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/python/collateral/gs_fcm.py b/python/collateral/gs_fcm.py index 68480c66..851d8618 100644 --- a/python/collateral/gs_fcm.py +++ b/python/collateral/gs_fcm.py @@ -2,7 +2,7 @@ import datetime import pandas as pd from . import DAILY_DIR, SftpClient -from .common import compare_notionals, STRATEGY_CASH_MAPPING +from .common import compare_notionals, compare_notionals_rates, STRATEGY_CASH_MAPPING def download_files(*args, **kwargs): @@ -23,7 +23,7 @@ def get_filename(d: datetime.date, name: str): return fname -def collateral(d: datetime.date, positions, *, engine, fund, **kwargs): +def collateral(d: datetime.date, positions, *, engine, fund, positions_irs, **kwargs): df = pd.read_csv( get_filename(d + datetime.timedelta(days=1), "Open_Trades_Redcode"), usecols=[ @@ -33,11 +33,22 @@ def collateral(d: datetime.date, positions, *, engine, fund, **kwargs): "Maturity Date", "COB Date", "Red Code", + "Instrument", + "CCP Trade ID", + "Pay Notional", ], parse_dates=["COB Date", "Maturity Date"], index_col=["Red Code", "Maturity Date"], thousands=",", ) + df_rates = ( + df[df["Instrument"] == "IRS"] + .drop(["Instrument", "Notional"], axis=1) + .set_index("CCP Trade ID") + ) + df = df[df["Instrument"] == "CDS"].drop( + ["Instrument", "CCP Trade ID", "Pay Notional"], axis=1 + ) df.Notional = df.Notional.where(df.Direction == "Buy", -df.Notional) df.index.names = ["security_id", "maturity"] cob_date = df["COB Date"][0] @@ -46,6 +57,16 @@ def collateral(d: datetime.date, positions, *, engine, fund, **kwargs): ].sum() df = df.rename(columns={"Notional": "NOTIONAL"}) compare_notionals(df, positions, "GS", fund) + df_rates = df_rates.rename(columns={"Pay Notional": "NOTIONAL"}) + compare_notionals_rates(df_rates, positions_irs, "GS") + positions_irs["Amount"] = df_rates.reindex(positions_irs.index)["NPV (local)"] + df_rates = ( + positions_irs.groupby(["folder", "currency"]) + .agg({"Amount": "sum"}) + .reset_index(["folder", "currency"]) + ) + df_rates = df_rates.rename(columns={"folder": "Strategy", "currency": "Currency"}) + df["dirty_upfront"] = df["NPV (local)"] / df.NOTIONAL positions["dirty_upfront"] = df.reindex(positions.index)["dirty_upfront"] positions["Amount"] = positions["notional"] * positions["dirty_upfront"] @@ -64,7 +85,9 @@ def collateral(d: datetime.date, positions, *, engine, fund, **kwargs): .reset_index(["folder", "currency"]) ) df = df.rename(columns={"folder": "Strategy", "currency": "Currency"}) + df = pd.concat([df, df_rates]) df["date"] = cob_date + df_margin = pd.read_csv( get_filename( d + datetime.timedelta(days=1), "Account_Balances_and_Margin_extended" |
