diff options
Diffstat (limited to 'python/notebooks')
| -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 |
3 files changed, 21 insertions, 19 deletions
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", |
