diff options
Diffstat (limited to 'python/pnl_explain.py')
| -rw-r--r-- | python/pnl_explain.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/python/pnl_explain.py b/python/pnl_explain.py index c1b42e3c..72586ea1 100644 --- a/python/pnl_explain.py +++ b/python/pnl_explain.py @@ -54,6 +54,9 @@ def pnl_explain(identifier, start_date = None, end_date = None, dates = pd.date_range(start_date, end_date, freq = bus_day) keys1 = ['price','factor', 'coupon', 'prev_cpn_date'] df[keys1] = df[keys1].fillna(method='ffill') + if identifier.endswith('_A'): + df.loc[df.price.notnull() & (df.factor==0),'factor'] = 1 + df.loc[df.price.notnull() & (df.factor==0),'factor'] = 1 keys2 = ['losses', 'principal','interest', 'faceamount','accrued_payment', 'principal_payment'] df[keys2] = df[keys2].fillna(value=0) df.faceamount = df.faceamount.cumsum() @@ -67,8 +70,11 @@ def pnl_explain(identifier, start_date = None, end_date = None, daily['realized_pnl'] = (daily.price/100 * daily.factor.diff() + daily.principal/100) * \ daily.faceamount daily['realized_accrued'] = daily.interest/100 * daily.faceamount - daily['accrued'] = yearfrac(daily.prev_cpn_date, daily.index.to_series(), daycount) * \ - daily.coupon/100*daily.factor * daily.faceamount + if identifier.endswith('_A'): + daily['accrued'] = 0 + else: + daily['accrued'] = yearfrac(daily.prev_cpn_date, daily.index.to_series(), daycount) * \ + daily.coupon/100*daily.factor * daily.faceamount if delay >0: ## we shift cashflows by delay 'D', and then move it to the next business day ## for some reason .shift(0, bus_day) doesn't work (but would work on an index) |
