Python for Finance: Analyze Big Financial Data

(Elle) #1
                                                        intercept               -0.0001                 0.0006                      -0.12                   0.9043              -0.0013
0.0011
–––––––––––End of Summary––––––––
–––

Obviously, there is indeed a highly negative correlation. We can access the results as


follows:


In  [ 82 ]: model.beta
Out[82]: x -2.752894
intercept -0.000074
dtype: float64

This input, in combination with the raw log return data, is used to generate the plot in


Figure 6-9, which provides strong support for the leverage effect:


In  [ 83 ]: plt.plot(xdat,  ydat,   ‘r.’)
ax = plt.axis() # grab axis values
x = np.linspace(ax[ 0 ], ax[ 1 ] + 0.01)
plt.plot(x, model.beta[ 1 ] + model.beta[ 0 ] * x, ‘b’, lw= 2 )
plt.grid(True)
plt.axis(‘tight’)
plt.xlabel(‘EURO STOXX 50 returns’)
plt.ylabel(‘VSTOXX returns’)

Figure 6-9. Scatter plot of log returns and regression line

As a final cross-check, we can calculate the correlation between the two financial time


series directly:


In  [ 84 ]: rets.corr()
Out[84]: EUROSTOXX VSTOXX
EUROSTOXX 1.000000 -0.729538
VSTOXX -0.729538 1.000000

Although the correlation is strongly negative on the whole data set, it varies considerably


over time, as shown in Figure 6-10. The figure uses correlation on a yearly basis, i.e., for


252 trading days:


In  [ 85 ]: pd.rolling_corr(rets[‘EUROSTOXX’],  rets[‘VSTOXX’],
window= 252 ).plot(grid=True, style=‘b’)
Free download pdf