{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import portfolio_var as port\n",
"from analytics import Swaption, BlackSwaption, Index, VolatilitySurface, Portfolio\n",
"from analytics.scenarios import run_swaption_scenarios, run_index_scenarios, run_portfolio_scenarios\n",
"import datetime\n",
"import pandas as pd\n",
"from pandas.tseries.offsets import BDay, BMonthEnd\n",
"\n",
"#import exploration.swaption_calendar_spread as spread\n",
"import exploration.swaption_calendar_spread as spread"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#Oct ME Bond HY Equiv\n",
"report_date = (datetime.date.today() + BMonthEnd(-1)).date()\n",
"bond_HY_equiv = -.12088\n",
"percentile = .95"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#The 95%tile \n",
"df, spread, dur = port.rel_spread_diff(report_date)\n",
"stress = pd.DataFrame()\n",
"stress.at[('2SD_widen', 'spread')] = df.quantile(.975) \n",
"stress.at[('2SD_tighten', 'spread')] = df.quantile(.025) \n",
"stress.at[('worst_widen', 'spread')] = df.max()\n",
"stress['pts'] = -stress * spread * dur/100\n",
"stress['nav_impact'] = bond_HY_equiv * stress['pts']"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" spread | \n",
" pts | \n",
" nav_impact | \n",
"
\n",
" \n",
" \n",
" \n",
" | 2SD_widen | \n",
" 0.157884 | \n",
" -2.208036 | \n",
" 0.266907 | \n",
"
\n",
" \n",
" | 2SD_tighten | \n",
" -0.163480 | \n",
" 2.286301 | \n",
" -0.276368 | \n",
"
\n",
" \n",
" | worst_widen | \n",
" 0.359386 | \n",
" -5.026082 | \n",
" 0.607553 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" spread pts nav_impact\n",
"2SD_widen 0.157884 -2.208036 0.266907\n",
"2SD_tighten -0.163480 2.286301 -0.276368\n",
"worst_widen 0.359386 -5.026082 0.607553"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stress"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" level_1 | \n",
" notional | \n",
" factor | \n",
" coupon | \n",
" duration | \n",
" theta | \n",
" price | \n",
" closespread | \n",
" clean_nav | \n",
" accrued | \n",
" onTR_notional | \n",
" widen | \n",
" tighten | \n",
" total | \n",
"
\n",
" \n",
" | strategy | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | HEDGE_MBS | \n",
" 3 | \n",
" -30500000.0 | \n",
" 2.92 | \n",
" 0.15 | \n",
" 9.579586 | \n",
" 0.091530 | \n",
" 323.911577 | \n",
" 728.775311 | \n",
" -2.454496e+06 | \n",
" -173891.666667 | \n",
" -2.271120e+07 | \n",
" -392951.746260 | \n",
" 439165.979817 | \n",
" 439165.979817 | \n",
"
\n",
" \n",
" | SER_IGCURVE | \n",
" 1 | \n",
" -11000000.0 | \n",
" 2.00 | \n",
" 0.02 | \n",
" 4.202955 | \n",
" 0.005495 | \n",
" 203.166063 | \n",
" 38.112262 | \n",
" -2.220374e+04 | \n",
" -12833.333333 | \n",
" 1.006705e+06 | \n",
" 3787.727425 | \n",
" -3681.218467 | \n",
" 3787.727425 | \n",
"
\n",
" \n",
" | SER_ITRXCURVE | \n",
" 1 | \n",
" 39300000.0 | \n",
" 2.00 | \n",
" 0.02 | \n",
" 14.638235 | \n",
" 0.021951 | \n",
" 203.615045 | \n",
" 138.590158 | \n",
" 2.027082e+06 | \n",
" 53396.910000 | \n",
" -3.481913e+06 | \n",
" -15658.882722 | \n",
" 16533.674519 | \n",
" 16533.674519 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" level_1 notional factor coupon duration theta \\\n",
"strategy \n",
"HEDGE_MBS 3 -30500000.0 2.92 0.15 9.579586 0.091530 \n",
"SER_IGCURVE 1 -11000000.0 2.00 0.02 4.202955 0.005495 \n",
"SER_ITRXCURVE 1 39300000.0 2.00 0.02 14.638235 0.021951 \n",
"\n",
" price closespread clean_nav accrued \\\n",
"strategy \n",
"HEDGE_MBS 323.911577 728.775311 -2.454496e+06 -173891.666667 \n",
"SER_IGCURVE 203.166063 38.112262 -2.220374e+04 -12833.333333 \n",
"SER_ITRXCURVE 203.615045 138.590158 2.027082e+06 53396.910000 \n",
"\n",
" onTR_notional widen tighten total \n",
"strategy \n",
"HEDGE_MBS -2.271120e+07 -392951.746260 439165.979817 439165.979817 \n",
"SER_IGCURVE 1.006705e+06 3787.727425 -3681.218467 3787.727425 \n",
"SER_ITRXCURVE -3.481913e+06 -15658.882722 16533.674519 16533.674519 "
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"port.cleared_cds_margins(report_date, percentile)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"120816.55576340854"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"port.index_curve_margins(report_date)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}