{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import exploration.option_trades as rvol\n", "import datetime\n", "import pandas as pd\n", "\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" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "w = widgets.Dropdown(\n", " options=['IG', 'HY'],\n", " value='IG',\n", " description='Index:',\n", " disabled=False,\n", ")\n", "w" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "index = w.value\n", "start_date=datetime.date(2014, 6, 11)\n", "onTR, model = rvol.realized_vol(index, tenor=\"5yr\", years=3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "onTR.plot()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model.summary()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#compute lo and hi percentiles of atm volatility daily change (vol of vol)\n", "rvol.vol_var()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = rvol.atm_vol(index, start_date, moneyness = .2)\n", "df['steepness'] = df.otm_vol - df.atm_vol\n", "df1 = df.reset_index()\n", "df1['date'] = df1.quotedate.dt.date\n", "df1 = df1.groupby(['date','expiry']).last()\n", "#Need to do: the vol looks jumpy, is it because of quote source issue? yes, need to first try to get the same quote source..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "r = []\n", "time = [1/12, 2/12, 3/12, 4/12, 5/12]\n", "for t in time:\n", " for date, g in df1.groupby(level='date'):\n", " f = interp1d(g['T'].values, g['steepness'].values, fill_value='extrapolate')\n", " r.append((date, t, f(t)))\n", "steepness = pd.DataFrame(r, columns=['date', 'T', 'steepness'])\n", "steepness = steepness.set_index(['date','T']).unstack().astype('float')\n", "steepness.columns = steepness.columns.droplevel()\n", "steepness.ewm(span = 3).mean().plot()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(steepness.iloc[-1] - steepness.mean()) / steepness.std()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Need to do: look at steepness not on moneyness but on delta range (60 delta vs 20 delta)" ] } ], "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.7.4" } }, "nbformat": 4, "nbformat_minor": 4 }