aboutsummaryrefslogtreecommitdiffstats
path: root/python/exploration
diff options
context:
space:
mode:
Diffstat (limited to 'python/exploration')
-rw-r--r--python/exploration/swaption_calendar_spread.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/python/exploration/swaption_calendar_spread.py b/python/exploration/swaption_calendar_spread.py
index d26ad0ee..51a22d42 100644
--- a/python/exploration/swaption_calendar_spread.py
+++ b/python/exploration/swaption_calendar_spread.py
@@ -147,7 +147,8 @@ def plot_trade_scenarios(portf, shock_min=-.15, shock_max=.2):
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')
+ #earliest_date = max(portf.swaptions,key=attrgetter('exercise_date')).exercise_date
+ date_range = pd.bdate_range(portf.indices[0].trade_date, earliest_date - BDay(), freq = '3B')
vol_shock = np.arange(-0.15, 0.3, 0.01)
spread_shock = np.arange(shock_min, shock_max, 0.01)
index = portf.indices[0].name.split()[1]
@@ -164,7 +165,7 @@ def plot_trade_scenarios(portf, shock_min=-.15, shock_max=.2):
shock = hy_plot_range if index == 'HY' else portf.indices[0].spread * (1 + spread_shock)
- period = -4
+ period = -1
plot_time_color_map(df[round(df.vol_shock,2)==0], shock, 'pnl', index=index)
plot_time_color_map(df[round(df.vol_shock,2)==0], shock, 'delta', color_map = cm.coolwarm_r, index=index)
plot_color_map(df.loc[date_range[period]], shock, vol_shock, 'pnl', index=index)
@@ -172,7 +173,7 @@ def plot_trade_scenarios(portf, shock_min=-.15, shock_max=.2):
def exercise_probability():
- from analytics import Swaption, BlackSwaption, Index, VolatilitySurface, Portfolio
+ from analytics import Swaption, BlackSwaption, Index, VolatilitySurface, Portfolio, ProbSurface, QuoteSurface, VolSurface
from analytics.scenarios import run_swaption_scenarios, run_index_scenarios, run_portfolio_scenarios
import datetime
from operator import attrgetter
@@ -204,21 +205,19 @@ def exercise_probability():
#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
+ option_delta = Index.from_name('HY', 29, '5yr')
+ option_delta.price = 107.875
+ option1 = BlackSwaption(option_delta, datetime.date(2017, 12, 20), 107, option_type="payer")
+ option2 = BlackSwaption(option_delta, datetime.date(2017, 12, 20), 105, option_type="payer")
+ option1.sigma = .280
+ option2.sigma = .371
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)
+ option_delta.notional = option1.notional * option1.delta + option2.notional * option2.delta
+ option_delta.direction = 'Seller' if option_delta.notional > 0 else 'Buyer'
+ option_delta.notional = abs(option_delta.notional)
portf = Portfolio([option1, option2, option_delta])
portf.reset_pv()
@@ -229,6 +228,8 @@ def exercise_probability():
index = portf.indices[0].name.split()[1]
series = portf.indices[0].name.split()[3][1:]
+ vs = QuoteSurface(index, series, trade_date=portf.indices[0].trade_date)
+
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]