A Sample notebook based on the EurEX Tutorial
In [10]:
from pylab import *
from pandas import *
es = read_csv('/resources/es.txt', sep=';', index_col=0, parse_dates=True, dayfirst=True)
vs = read_csv('/resources/vs.txt', sep=',', index_col=0, parse_dates=True, dayfirst=True)
In [11]:
es.describe()
Out[11]:
In [12]:
# Remove the "DEL" column.
del es['DEL']
es.head()
Out[12]:
In [13]:
vs.describe()
Out[13]:
In [14]:
vs.head()
Out[14]:
In [15]:
data = DataFrame({'EUROSTOXX' : es['SX5E'][es.index > datetime(1999, 12, 31)],
'VSTOXX' : vs['V2TX'][vs.index > datetime(1999, 12, 31)]})
data.describe()
Out[15]:
In [16]:
data.head()
Out[16]:
In [17]:
!pip install h5py
In [18]:
h5 = HDFStore('data.h5')
h5['es'] = es
h5['vs'] = vs
h5['data'] = data
h5
Out[18]:
In [19]:
h5.close()
In [20]:
h5 = HDFStore('data.h5', 'a')
es = h5['es']
vs = h5['vs']
data = h5['data']
h5.close()
In [21]:
data.head()
Out[21]:
In [22]:
%matplotlib inline
In [23]:
data.plot(subplots=True, figsize=(9, 4), color='blue', grid=True)
Out[23]:
Observation: The two indexes seem to be highly negatively correlated. When the EURO STOXX 50 goes up, the VSTOXX comes down and vice versa. Something sometimes called the leverage effect.
To calculate and visualize the absolute changes, we plot a histogram which shows the absolute differences and their absolute frequencies.
In [24]:
data.diff().hist(color='b', alpha=.5, bins=100)
Out[24]:
The figure shows the absolute returns of both indexes on daily basis.
Observation: The daily percentage changes might also be of interest. We can compute and plot them as well.
In [25]:
data.pct_change().head()
Out[25]:
In [26]:
data.pct_change().hist(color='b', alpha=.5, bins=100)
Out[26]:
In [27]:
data['esr'] = log(data['EUROSTOXX'] / data['EUROSTOXX'].shift(1))
data['vsr'] = log(data['VSTOXX'] / data['VSTOXX'].shift(1))
data.head()
Out[27]:
In [28]:
data[['esr', 'vsr']].plot(subplots=True, figsize=(9, 4), color='blue', grid=True)
Out[28]:
There are (at least) two possible ways to calculate the correlation between both log-returns. On the one hand, we can generate a correlation matrix as output (which would be preferred for more than two time series). On the other hand, we can compute the correlation directly between the two time series of interest:
In [29]:
data[['esr','vsr']].corr()
Out[29]:
In [30]:
data['esr'].corr(data['vsr'])
Out[30]:
Observation: The log-returns of both indexes are highly negatively correlated. Again support for the leverage effect which implies that with dropping index levels risk increases. Also, if index levels rise, risks come down in general.
In [30]: