diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/analytics/option.py | 7 | ||||
| -rw-r--r-- | python/notebooks/Option Trades.ipynb | 8 | ||||
| -rw-r--r-- | python/notebooks/Reto Report.ipynb | 14 | ||||
| -rw-r--r-- | python/notebooks/VaR.ipynb | 18 |
4 files changed, 27 insertions, 20 deletions
diff --git a/python/analytics/option.py b/python/analytics/option.py index 065de803..eecb9997 100644 --- a/python/analytics/option.py +++ b/python/analytics/option.py @@ -332,13 +332,18 @@ class BlackSwaption(ForwardIndex): pv=self._G - pv) def shock(self, params, *, spread_shock, vol_surface, vol_shock, **kwargs): + """scenarios based on spread and vol shocks, vol surface labeled in the dict""" orig_spread, orig_sigma = self.index.spread, self.sigma r = [] actual_params = [p for p in params if hasattr(self, p)] + vol_surface = vol_surface[self.index.index_type + self.index.series] for ss in spread_shock: self.index.spread = orig_spread * (1 + ss) # TODO: Vol floored at 20% for now. - curr_vol = max(.2, vol_surface.ev(self.T, math.log(self.moneyness))) + if isinstance(vol_surface, SmoothBivariateSpline): + curr_vol = max(.2, vol_surface.ev(self.T, math.log(self.moneyness))) + else: + curr_vol = max(.2, vol_surface(self.T, math.log(self.moneyness))) for vs in vol_shock: self.sigma = curr_vol * (1 + vs) r.append([getattr(self, p) for p in actual_params]) diff --git a/python/notebooks/Option Trades.ipynb b/python/notebooks/Option Trades.ipynb index 6d60669c..6a28003f 100644 --- a/python/notebooks/Option Trades.ipynb +++ b/python/notebooks/Option Trades.ipynb @@ -40,9 +40,11 @@ " vol_shock = np.arange(-.15, .31, 0.01)\n", " spread_shock = np.arange(shock_min, shock_max, 0.01)\n", " index = portf.indices[0].index_type\n", - " vs = BlackSwaptionVolSurface(index, portf.indices[0].series, \n", - " value_date=portf.value_date)\n", - " vol_surface = vs[vs.list(option_type='payer')[-1]]\n", + " vol_surface = {}\n", + " for trade in portf.swaptions:\n", + " vs = BlackSwaptionVolSurface(trade.index.index_type, trade.index.series, \n", + " value_date=date)\n", + " vol_surface[trade.index.index_type + trade.index.series] = vs[vs.list(option_type='payer')[-1]]\n", " \n", " df = run_portfolio_scenarios(portf, date_range, params=[\"pnl\",\"delta\"],\n", " spread_shock = spread_shock,\n", diff --git a/python/notebooks/Reto Report.ipynb b/python/notebooks/Reto Report.ipynb index c91cd918..6e62b252 100644 --- a/python/notebooks/Reto Report.ipynb +++ b/python/notebooks/Reto Report.ipynb @@ -159,17 +159,17 @@ "#Update manually - positive notional = long risk\n", "non_trancheSwap_risk_notional = 49119912 \n", "\n", - "portf.add_trade(CreditIndex('HY', on_the_run('HY'), '5yr', value_date = date, notional = -non_trancheSwap_risk_notional), 'port')\n", + "portf.add_trade(CreditIndex('HY', on_the_run('HY'), '5yr', value_date = date, notional = -non_trancheSwap_risk_notional), 'bond')\n", " \n", "portf.value_date = date\n", "portf.mark(interp_method=\"bivariate_linear\")\n", "portf.reset_pv()\n", - " \n", - "vs = BlackSwaptionVolSurface(portf.swaptions[0].index.index_type, \n", - " portf.swaptions[0].index.series, \n", - " value_date=date, \n", - " interp_method = \"bivariate_linear\")\n", - "vol_surface = vs[vs.list(option_type='payer')[-1]]\n", + "\n", + "vol_surface = {}\n", + "for trade in portf.swaptions:\n", + " vs = BlackSwaptionVolSurface(trade.index.index_type, trade.index.series, \n", + " value_date=date, interp_method = \"bivariate_linear\")\n", + " vol_surface[trade.index.index_type + trade.index.series] = vs[vs.list(option_type='payer')[-1]]\n", "vol_shock = [0]\n", "corr_shock = [0]\n", "spread_shock = widen + tighten\n", diff --git a/python/notebooks/VaR.ipynb b/python/notebooks/VaR.ipynb index 178d72b3..2fa3ee1d 100644 --- a/python/notebooks/VaR.ipynb +++ b/python/notebooks/VaR.ipynb @@ -28,7 +28,7 @@ "metadata": {}, "outputs": [], "source": [ - "date = (datetime.date.today() - pd.tseries.offsets.BDay(3)).date()\n", + "date = (datetime.date.today() - pd.tseries.offsets.BDay(1)).date()\n", "report_date = (date + pd.tseries.offsets.BMonthEnd(-1)).date()\n", "index_type = \"IG\"\n", "quantile = .025" @@ -134,7 +134,7 @@ " \"AND trade_date <= %s\")\n", "swaption_sql_string = (\"select id, security_desc from swaptions where date(expiration_date) \"\n", " \"> %s and swap_type = 'CD_INDEX_OPTION' \"\n", - " \"AND trade_date <= %s\")\n", + " \"AND trade_date <= %s AND termination_date iS NULL\")\n", "index_sql_string = (\"SELECT id, sum(notional * case when protection='Buyer' then -1 else 1 end) \"\n", " \"OVER (partition by security_id, attach) AS ntl_agg \"\n", " \"FROM cds WHERE swap_type='CD_INDEX' AND termination_cp IS null \"\n", @@ -166,14 +166,14 @@ "portf.add_trade(CreditIndex('HY', on_the_run('HY'), '5yr', value_date = date, notional = -non_trancheSwap_risk_notional), 'bond')\n", " \n", "portf.value_date = date\n", - "portf.mark(interp_method=\"bivariate_spline\")\n", + "portf.mark(interp_method=\"bivariate_linear\")\n", "portf.reset_pv()\n", - " \n", - "vs = BlackSwaptionVolSurface(portf.swaptions[0].index.index_type, \n", - " portf.swaptions[0].index.series, \n", - " value_date=date, \n", - " interp_method = \"bivariate_spline\")\n", - "vol_surface = vs[vs.list(option_type='payer')[-1]]\n", + "\n", + "vol_surface = {}\n", + "for trade in portf.swaptions:\n", + " vs = BlackSwaptionVolSurface(trade.index.index_type, trade.index.series, \n", + " value_date=date, interp_method = \"bivariate_linear\")\n", + " vol_surface[trade.index.index_type + trade.index.series] = vs[vs.list(option_type='payer')[-1]]\n", "vol_shock = [0]\n", "corr_shock = [0]\n", "spread_shock = widen + tighten\n", |
