1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
{
"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
}
|