aboutsummaryrefslogtreecommitdiffstats
path: root/python/exploration
diff options
context:
space:
mode:
Diffstat (limited to 'python/exploration')
-rw-r--r--python/exploration/tranches.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/python/exploration/tranches.py b/python/exploration/tranches.py
index 7b475821..430e8492 100644
--- a/python/exploration/tranches.py
+++ b/python/exploration/tranches.py
@@ -7,7 +7,7 @@ import analytics.basket_index as idx_bkt
import numpy as np
import pandas as pd
-from analytics import Swaption, BlackSwaption, Index, BlackSwaptionVolSurface, Portfolio
+from analytics import Swaption, BlackSwaption, Index, BlackSwaptionVolSurface, Portfolio, ProbSurface
from analytics.scenarios import run_swaption_scenarios, run_index_scenarios, run_portfolio_scenarios, run_tranche_scenarios
import exploration.swaption_calendar_spread as spread
from scipy.interpolate import interp1d
@@ -99,14 +99,19 @@ def dispersion():
def run_scen(portf, tranche, spread_shock):
#Start with swaptions
+ index = portf.indices[0].index_type
+ series = portf.indices[0].series
+ trade_date=portf.indices[0].trade_date
+
earliest_expiry = min(portf.swaptions, key=lambda x: x.exercise_date).exercise_date
- date_range = pd.bdate_range(portf.indices[0].trade_date,
- earliest_expiry - pd.offsets.BDay(), freq='5B')
- vs = BlackSwaptionVolSurface(portf.indices[0].index_type,
- portf.indices[0].series, trade_date=portf.indices[0].trade_date)
+ date_range = pd.bdate_range(trade_date, earliest_expiry - pd.offsets.BDay(), freq='5B')
+ vs = BlackSwaptionVolSurface(index,series, trade_date=trade_date)
+ ps = ProbSurface(index,series, trade_date=trade_date)
vol_surface = vs[vs.list(option_type='payer')[-1]]
df = run_portfolio_scenarios(portf, date_range, spread_shock, np.array([0]),
vol_surface, params=["pnl", "delta"])
+ df['frac_year'] = (df.index - pd.to_datetime(trade_date)).days/365
+ df['prob'] = df.apply(lambda df: ps.tail_prob(df.frac_year, df.spread, ps.list()[-1]), axis=1)
#now do the tranches
spread_range = (1+ spread_shock) * portf.indices[0].spread