aboutsummaryrefslogtreecommitdiffstats
path: root/python/exploration
diff options
context:
space:
mode:
Diffstat (limited to 'python/exploration')
-rw-r--r--python/exploration/tranches.py76
1 files changed, 1 insertions, 75 deletions
diff --git a/python/exploration/tranches.py b/python/exploration/tranches.py
index 430e8492..a8e8d05e 100644
--- a/python/exploration/tranches.py
+++ b/python/exploration/tranches.py
@@ -9,7 +9,6 @@ import pandas as pd
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
from datetime import date
@@ -77,7 +76,7 @@ def dispersion():
maturities = {}
settings = Settings()
for series in [24, 25, 26, 27, 28, 29]:
- index_temp = idx_bkt.MarkitBasketIndex('IG', series, ["5yr",], trade_date=trade_date)
+ index_temp = idx_bkt.MarkitBasketIndex('IG', series, ["5yr",], value_date=trade_date)
maturities[series] = index_temp.maturities[0]
cds_schedule = Schedule.from_rule(settings.evaluation_date, Date.from_datetime(maturities[series]),
Period('3M'), WeekendsOnly(), date_generation_rule=Rule.CDS2015)
@@ -95,76 +94,3 @@ def dispersion():
dispersion = pd.concat(disp)
curve_df.groupby(['series', 'maturity']).mean()
curve_df.groupby(['series', 'maturity']).std()
-
-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(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
- results = run_tranche_scenarios(tranche, spread_range, date_range)
- results.date = pd.to_datetime(results.date)
- notional = 10000000
- results['delta_tranche'] = -notional * (results['0-3_delta'] - 6* results['7-15_delta'])
- results['pnl_tranche'] = notional * (results['0-3_pnl'] + results['0-3_carry'] -
- 6* (results['7-15_pnl'] + results['7-15_carry']))
- results.index.name = 'spread'
-
- #combine
- df = df.reset_index().merge(results.reset_index(), on=['date', 'spread'])
- df['final_pnl'] = df.pnl_tranche + df.pnl
- df['final_delta'] = df.delta_tranche + df.delta
-
- return df
-
-def set_port():
-
- #Construct Portfolio
- option_delta = Index.from_name('IG', 30, '5yr')
- option_delta.spread = 59
-
- option1 = BlackSwaption(option_delta, date(2018, 6, 20), 80, option_type="payer")
- option1.sigma = .621
- option1.direction = 'Short'
-
- option1.notional = 150_000_000
- option_delta.notional = 1
-
- portf = Portfolio([option1, option_delta])
- portf.reset_pv()
- trade_date = (pd.datetime.today() - pd.offsets.BDay(1)).normalize()
- tranche = bkt.TrancheBasket('IG', 29, '5yr', trade_date=trade_date)
-
- return portf, tranche
-
-def set_df():
-
- portf, tranche = set_port()
-
- shock_min = -.3
- shock_max = .8
- spread_shock = np.arange(shock_min, shock_max, 0.05)
- shock_range = (1+ spread_shock) * portf.indices[0].spread
-
- results = run_scen(portf, tranche, spread_shock)
- results = results.set_index('date')
- return results, shock_range
-
-def plot_scenarios():
-
- df, shock_range = set_df()
- plot_time_color_map(df, shock_range, attr="final_pnl")
- plot_time_color_map(df, shock_range, attr="final_delta", color_map= 'rainbow', centered = False)