diff options
Diffstat (limited to 'python/notebooks/Realized Vol.ipynb')
| -rw-r--r-- | python/notebooks/Realized Vol.ipynb | 175 |
1 files changed, 160 insertions, 15 deletions
diff --git a/python/notebooks/Realized Vol.ipynb b/python/notebooks/Realized Vol.ipynb index 39bfac6e..464b14d6 100644 --- a/python/notebooks/Realized Vol.ipynb +++ b/python/notebooks/Realized Vol.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -10,7 +10,7 @@ "import datetime\n", "import pandas as pd\n", "\n", - "from exploration.curve_trades import on_the_run\n", + "from analytics import on_the_run\n", "from scipy.interpolate import interp1d\n", "from matplotlib import pyplot as plt\n", "from ipywidgets import widgets" @@ -18,9 +18,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b7808ffade83485bba8f589bedb10f68", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Dropdown(description='Index:', options=('IG', 'HY'), value='IG')" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "w = widgets.Dropdown(\n", " options=['IG', 'HY'],\n", @@ -33,38 +48,168 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "index = w.value\n", "start_date=datetime.date(2014, 6, 11)\n", - "onTR, model = rvol.realized_vol(index, on_the_run('IG'), \"5yr\", years=3)" + "onTR, model = rvol.realized_vol(index, tenor=\"5yr\", years=3)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4dfbcdf09a294dc781ad1a5b4c382c96", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "<matplotlib.axes._subplots.AxesSubplot at 0x7fe3eb2ad390>" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "#onTR.plot()" + "onTR.plot()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "<table class=\"simpletable\">\n", + "<caption>Constant Mean - GARCH Model Results</caption>\n", + "<tr>\n", + " <th>Dep. Variable:</th> <td>spread_return</td> <th> R-squared: </th> <td> -0.001</td> \n", + "</tr>\n", + "<tr>\n", + " <th>Mean Model:</th> <td>Constant Mean</td> <th> Adj. R-squared: </th> <td> -0.001</td> \n", + "</tr>\n", + "<tr>\n", + " <th>Vol Model:</th> <td>GARCH</td> <th> Log-Likelihood: </th> <td> 94.1921</td>\n", + "</tr>\n", + "<tr>\n", + " <th>Distribution:</th> <td>Normal</td> <th> AIC: </th> <td> -180.384</td>\n", + "</tr>\n", + "<tr>\n", + " <th>Method:</th> <td>Maximum Likelihood</td> <th> BIC: </th> <td> -161.947</td>\n", + "</tr>\n", + "<tr>\n", + " <th></th> <td></td> <th> No. Observations: </th> <td>742</td> \n", + "</tr>\n", + "<tr>\n", + " <th>Date:</th> <td>Wed, Sep 11 2019</td> <th> Df Residuals: </th> <td>738</td> \n", + "</tr>\n", + "<tr>\n", + " <th>Time:</th> <td>10:44:17</td> <th> Df Model: </th> <td>4</td> \n", + "</tr>\n", + "</table>\n", + "<table class=\"simpletable\">\n", + "<caption>Mean Model</caption>\n", + "<tr>\n", + " <td></td> <th>coef</th> <th>std err</th> <th>t</th> <th>P>|t|</th> <th>95.0% Conf. Int.</th> \n", + "</tr>\n", + "<tr>\n", + " <th>mu</th> <td> -0.0178</td> <td>7.408e-03</td> <td> -2.400</td> <td>1.641e-02</td> <td>[-3.230e-02,-3.258e-03]</td>\n", + "</tr>\n", + "</table>\n", + "<table class=\"simpletable\">\n", + "<caption>Volatility Model</caption>\n", + "<tr>\n", + " <td></td> <th>coef</th> <th>std err</th> <th>t</th> <th>P>|t|</th> <th>95.0% Conf. Int.</th> \n", + "</tr>\n", + "<tr>\n", + " <th>omega</th> <td>3.6040e-03</td> <td>1.414e-03</td> <td> 2.548</td> <td>1.082e-02</td> <td>[8.322e-04,6.376e-03]</td>\n", + "</tr>\n", + "<tr>\n", + " <th>alpha[1]</th> <td> 0.1348</td> <td>4.345e-02</td> <td> 3.103</td> <td>1.914e-03</td> <td>[4.968e-02, 0.220]</td> \n", + "</tr>\n", + "<tr>\n", + " <th>beta[1]</th> <td> 0.7960</td> <td>5.441e-02</td> <td> 14.631</td> <td>1.774e-48</td> <td>[ 0.689, 0.903]</td> \n", + "</tr>\n", + "</table><br/><br/>Covariance estimator: robust" + ], + "text/plain": [ + "<class 'statsmodels.iolib.summary.Summary'>\n", + "\"\"\"\n", + " Constant Mean - GARCH Model Results \n", + "==============================================================================\n", + "Dep. Variable: spread_return R-squared: -0.001\n", + "Mean Model: Constant Mean Adj. R-squared: -0.001\n", + "Vol Model: GARCH Log-Likelihood: 94.1921\n", + "Distribution: Normal AIC: -180.384\n", + "Method: Maximum Likelihood BIC: -161.947\n", + " No. Observations: 742\n", + "Date: Wed, Sep 11 2019 Df Residuals: 738\n", + "Time: 10:44:17 Df Model: 4\n", + " Mean Model \n", + "==============================================================================\n", + " coef std err t P>|t| 95.0% Conf. Int.\n", + "------------------------------------------------------------------------------\n", + "mu -0.0178 7.408e-03 -2.400 1.641e-02 [-3.230e-02,-3.258e-03]\n", + " Volatility Model \n", + "============================================================================\n", + " coef std err t P>|t| 95.0% Conf. Int.\n", + "----------------------------------------------------------------------------\n", + "omega 3.6040e-03 1.414e-03 2.548 1.082e-02 [8.322e-04,6.376e-03]\n", + "alpha[1] 0.1348 4.345e-02 3.103 1.914e-03 [4.968e-02, 0.220]\n", + "beta[1] 0.7960 5.441e-02 14.631 1.774e-48 [ 0.689, 0.903]\n", + "============================================================================\n", + "\n", + "Covariance estimator: robust\n", + "\"\"\"" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "model.summary()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'df' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m-----------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m<ipython-input-6-bc681e92175e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m#compute lo and hi percentiles of atm volatility daily change (vol of vol)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mrvol\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvol_var\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m~/projects/code/python/exploration/option_trades.py\u001b[0m in \u001b[0;36mvol_var\u001b[0;34m(percentile, index, start_date)\u001b[0m\n\u001b[1;32m 111\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mwe\u001b[0m \u001b[0mshould\u001b[0m \u001b[0mgroup\u001b[0m \u001b[0mit\u001b[0m \u001b[0mby\u001b[0m \u001b[0mseries\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 112\u001b[0m \"\"\"\n\u001b[0;32m--> 113\u001b[0;31m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0matm_vol\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstart_date\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 114\u001b[0m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrolling_vol\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mterm\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 115\u001b[0m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msort_index\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/projects/code/python/exploration/option_trades.py\u001b[0m in \u001b[0;36matm_vol\u001b[0;34m(index, date, series, moneyness)\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 88\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0matm_vol\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mseries\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmoneyness\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 89\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0matm_vol_calc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmoneyness\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 90\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 91\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mrolling_vol\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcol\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'atm_vol'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mterm\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'df' is not defined" + ] + } + ], "source": [ "#compute lo and hi percentiles of atm volatility daily change (vol of vol)\n", "rvol.vol_var()" @@ -137,9 +282,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.1" + "version": "3.7.4" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } |
