diff options
Diffstat (limited to 'python/notebooks/Risk Management.ipynb')
| -rw-r--r-- | python/notebooks/Risk Management.ipynb | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/python/notebooks/Risk Management.ipynb b/python/notebooks/Risk Management.ipynb new file mode 100644 index 00000000..a650b1c3 --- /dev/null +++ b/python/notebooks/Risk Management.ipynb @@ -0,0 +1,119 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "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", + "\n", + "#import exploration.swaption_calendar_spread as spread\n", + "import exploration.swaption_calendar_spread as spread" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df, spread, dur = port.rel_spread_diff()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#The 95%tile \n", + "stress = pd.DataFrame(index = ['widen', 'tighten'], columns=['pts'])\n", + "stress.loc['widen'] = df.quantile(.975) \n", + "stress.loc['tighten'] = df.quantile(.025)\n", + "stress = -stress * spread * dur/100" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#August ME Bond HY Equiv\n", + "bond_HY_equiv = .1652\n", + "stress['nav_impact'] = bond_HY_equiv * stress" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Swaptions\n", + "#Aug 2018: Buy Sept HY payer spread\n", + "option_delta = Index.from_tradeid(891)\n", + "option1 = BlackSwaption.from_tradeid(10, option_delta)\n", + "option2 = BlackSwaption.from_tradeid(11, option_delta)\n", + "portf = Portfolio([option1, option2, option_delta])\n", + "portf.trade_date = datetime.date(2017, 8, 31)\n", + "portf.mark()\n", + "orig_pv = portf.pv\n", + "orig_ref = portf.ref" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for x, y in stress.pts.iteritems():\n", + " portf.ref = orig_ref + y\n", + " stress[x] = portf.pv - orig_pv" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "stress" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "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 +} |
