diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/pnl_explain.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/python/pnl_explain.py b/python/pnl_explain.py index 6e9ba203..0e54b718 100644 --- a/python/pnl_explain.py +++ b/python/pnl_explain.py @@ -16,18 +16,18 @@ def get_index_pv( end_date: datetime.date, fund: str, conn: connection, - strategies: Union[Tuple[str], None] = None, + strategies: Tuple[str] = (), ): dr = pd.bdate_range(start_date, next_business_day(end_date), freq=bus_day) - if strategies is None: + if not strategies: return pd.DataFrame(0.0, index=dr, columns=["pv", "upfront", "accrued"]) pvs = [] upfronts = [] accrueds = [] dates = [] - for d in dr: - prev_day = (d - bus_day).date() + for d in dr.date: + prev_day = prev_business_day(d) if ( previous_twentieth(prev_day, roll=True) == prev_day ): # this is a payment date @@ -374,6 +374,7 @@ def cumulative_from_daily(df): if __name__ == "__main__": import argparse from serenitas.utils.db import dbconn + from itertools import chain dawndb = dbconn("dawndb") parser = argparse.ArgumentParser() @@ -401,8 +402,8 @@ if __name__ == "__main__": action="store", default="tranche", dest="pnl_type", - choices=("tranche", "swaption", "bond", "hedge", "curve"), - help="instrument for which we want the pnl ('tranche', 'swaption', 'bond', 'hedge', 'curve')", + choices=("tranche", "swaption", "bond", "hedge", "curve", "cleared"), + help="instrument for which we want the pnl ('tranche', 'swaption', 'bond', 'hedge', 'curve', 'cleared')", ) parser.add_argument( "-f", @@ -425,15 +426,16 @@ if __name__ == "__main__": strats = { "swaption": ("IGOPTDEL", "HYOPTDEL"), "hedge": ("HEDGE_MBS", "HEDGE_CLO", "HEDGE_MAC"), - "tranche": ("IGINX", "HYINX", "XOINX"), + "tranche": ("IGINX", "HYINX", "XOINX", "EUINX"), "curve": ("SER_ITRXCURVE", "SER_IGCURVE", "SER_HYCURVE"), - "bond": None, + "bond": (), } + strats["cleared"] = tuple(chain.from_iterable(strats.values())) df_index = get_index_pv( args.start_date, args.end_date, args.fund, dawndb, strats[args.pnl_type] ) pnl_index = df_index.pv.diff() + df_index[["upfront", "accrued"]].sum(axis=1) - if args.pnl_type not in ["hedge", "curve"]: + if args.pnl_type not in ["hedge", "curve", "cleared"]: df_instrument = get_pv(conn=dawndb, **vars(args)) pnl_instrument = get_pnl(df_instrument, args.pnl_type, pv2=args.pv2) pnl = pd.concat( |
