diff options
Diffstat (limited to 'python/notebooks/Realized Vol.ipynb')
| -rw-r--r-- | python/notebooks/Realized Vol.ipynb | 165 |
1 files changed, 10 insertions, 155 deletions
diff --git a/python/notebooks/Realized Vol.ipynb b/python/notebooks/Realized Vol.ipynb index 464b14d6..cfa46012 100644 --- a/python/notebooks/Realized Vol.ipynb +++ b/python/notebooks/Realized Vol.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -18,24 +18,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "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" - } - ], + "outputs": [], "source": [ "w = widgets.Dropdown(\n", " options=['IG', 'HY'],\n", @@ -48,7 +33,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -59,157 +44,27 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, - "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" - } - ], + "outputs": [], "source": [ "onTR.plot()" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "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" - } - ], + "outputs": [], "source": [ "model.summary()" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "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" - ] - } - ], + "outputs": [], "source": [ "#compute lo and hi percentiles of atm volatility daily change (vol of vol)\n", "rvol.vol_var()" |
