diff options
Diffstat (limited to 'python/exploration/swaption_calendar_spread.py')
| -rw-r--r-- | python/exploration/swaption_calendar_spread.py | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/python/exploration/swaption_calendar_spread.py b/python/exploration/swaption_calendar_spread.py index 304e7be9..a1a244d6 100644 --- a/python/exploration/swaption_calendar_spread.py +++ b/python/exploration/swaption_calendar_spread.py @@ -149,7 +149,7 @@ def plot_trade_scenarios(portf): earliest_date = min(portf.swaptions,key=attrgetter('exercise_date')).exercise_date date_range = pd.bdate_range(portf.indices[0].trade_date, earliest_date - BDay(), freq = '5B') vol_shock = np.arange(-0.15, 0.3, 0.01) - spread_shock = np.arange(-0.15, 0.35, 0.01) + spread_shock = np.arange(-0.15, 0.2, 0.01) index = portf.indices[0].name.split()[1] series = portf.indices[0].name.split()[3][1:] vs = VolatilitySurface(index, series, trade_date=portf.indices[0].trade_date) @@ -158,7 +158,7 @@ def plot_trade_scenarios(portf): df = run_portfolio_scenarios(portf, date_range, spread_shock, vol_shock, vol_surface, params=["pnl","delta"], vol_time_roll=True) - hy_plot_range = 100 - (500- portf.indices[0].spread * (1 + spread_shock))*portf.indices[0].DV01/portf.indices[0].notional*100 + hy_plot_range = 100 + (500- portf.indices[0].spread * (1 + spread_shock))*abs(portf.indices[0].DV01)/portf.indices[0].notional*100 shock = hy_plot_range if index == 'HY' else portf.indices[0].spread * (1 + spread_shock) @@ -168,4 +168,68 @@ def plot_trade_scenarios(portf): plot_color_map(df.loc[date_range[period]], shock, vol_shock, 'pnl', index=index) #plot_df(df.loc[date_range[period]], shock, vol_shock) +def exercise_probability(): + + from analytics import Swaption, BlackSwaption, Index, VolatilitySurface, Portfolio + from analytics.scenarios import run_swaption_scenarios, run_index_scenarios, run_portfolio_scenarios + import datetime + from operator import attrgetter + + import exploration.swaption_calendar_spread as spread + + import sys + #don't do this at home + from pandas.tseries.offsets import BDay + import datetime + import numpy as np + import pandas as pd + from scipy.interpolate import SmoothBivariateSpline + from matplotlib import cm + from mpl_toolkits.mplot3d import Axes3D + import matplotlib.pyplot as plt + from operator import attrgetter + + import os + import numpy as np + import matplotlib + import matplotlib.pyplot as plt + from mpl_toolkits.axes_grid1 import AxesGrid + + import re + from db import dbengine + engine = dbengine('serenitasdb') + + #import swaption_calendar_spread as spread + + #Ad hoc + option_delta = Index.from_name('HY', 28, '5yr') + option_delta.price = 107.625 + option1 = BlackSwaption(option_delta, datetime.date(2017, 9, 20), 107, option_type="payer") + option2 = BlackSwaption(option_delta, datetime.date(2017, 9, 20), 105, option_type="payer") + option1.sigma = .270 + option2.sigma = .3625 + option1.notional = 20_000_000 + option2.notional = 40_000_000 + option1.direction = 'Long' + option2.direction = 'Short' + option_delta.notional = -2000000 + #option_delta.notional = option_delta.notional - option_delta2.notional + if option_delta.notional < 0: + option_delta.direction = 'Seller' + option_delta.notional = abs(option_delta.notional) + portf = Portfolio([option1, option2, option_delta]) + + portf.reset_pv() + earliest_date = min(portf.swaptions,key=attrgetter('exercise_date')).exercise_date + date_range = pd.bdate_range(portf.indices[0].trade_date, earliest_date - BDay(), freq = '5B') + vol_shock = np.arange(-0.15, 0.3, 0.01) + spread_shock = np.arange(-0.15, 0.35, 0.01) + index = portf.indices[0].name.split()[1] + series = portf.indices[0].name.split()[3][1:] + + vs = VolatilitySurface(index, series, trade_date=portf.indices[0].trade_date) + vol_select = vs.list(option_type='payer', model='black')[-1] + vol_surface = vs[vol_select] + prob = vs.prob_surf(vol_select) + vs.prob_plot(vol_select)
\ No newline at end of file |
