diff options
Diffstat (limited to 'python/pnl_explain.py')
| -rw-r--r-- | python/pnl_explain.py | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/python/pnl_explain.py b/python/pnl_explain.py index 984f1c34..352e19b6 100644 --- a/python/pnl_explain.py +++ b/python/pnl_explain.py @@ -169,16 +169,19 @@ def get_tranche_pv( {"pv": pv, "upfront": upfronts, "accrued": accrueds}, index=pd.to_datetime(dates), ) - defaults = pd.DataFrame( - {"upfront": [963398.61 * 3, 738908.68 * 3, 990427.08 * 3, 990260.59 * 3]}, - index=[ - pd.Timestamp("2020-06-01"), - pd.Timestamp("2020-06-10"), - pd.Timestamp("2020-06-25"), - pd.Timestamp("2020-07-08"), - ], - ) - return df.sub(defaults, fill_value=0.0) + if fund == "SERCGMAST": + defaults = pd.DataFrame( + {"upfront": [963398.61 * 3, 738908.68 * 3, 990427.08 * 3, 990260.59 * 3]}, + index=[ + pd.Timestamp("2020-06-01"), + pd.Timestamp("2020-06-10"), + pd.Timestamp("2020-06-25"), + pd.Timestamp("2020-07-08"), + ], + ) + return df.sub(defaults.reindex(df.index, fill_value=0.0), fill_value=0.0) + else: + return df def get_tranche_pv2( @@ -255,10 +258,15 @@ def get_tranche_pv2( def get_pv(**kwargs): pnl_type = kwargs.pop("pnl_type") + if "pv2" in kwargs: + pv2 = kwargs.pop("pv2") if pnl_type == "swaption": return get_swaption_pv(**kwargs) elif pnl_type == "tranche": - return get_tranche_pv(**kwargs) + if pv2: + return get_tranche_pv2(**kwargs) + else: + return get_tranche_pv(**kwargs) else: return get_bond_pv(**kwargs) @@ -402,6 +410,7 @@ if __name__ == "__main__": choices=("Subprime", "CLO", "CRT"), help="bond type for which we want the pnl ('Subprime', 'CLO', 'CRT')", ) + parser.add_argument("-2", "--pv2", action="store_true", default=False) args = parser.parse_args() strats = { @@ -417,14 +426,11 @@ if __name__ == "__main__": pnl_index = df_index.pv.diff() + df_index[["upfront", "accrued"]].sum(axis=1) if args.pnl_type not in ["hedge", "curve"]: df_instrument = get_pv(conn=dawndb, **vars(args)) - pnl_instrument = get_pnl(df_instrument, args.pnl_type) + pnl_instrument = get_pnl(df_instrument, args.pnl_type, pv2=args.pv2) pnl = pd.concat( [pnl_index, pnl_instrument], keys=["index", args.pnl_type], axis=1 ) print(cumulative_from_daily(pnl.sum(axis=1))) - elif args.pnl_type in ["hedge", "curve"]: + else: print(cumulative_from_daily(pnl_index)) - # HTZ: -738908.68 * 3 - # JCP 963398.61 * 3 - # CRC: 990260.59 * 3 |
