Python for Finance: Analyze Big Financial Data

(Elle) #1

However, to put this on more formal ground, we want to work again with the log returns


of the two financial time series. Figure 6-8 shows these graphically:


In  [ 79 ]: rets    =   np.log(data /   data.shift( 1 ))
rets.head()
Out[79]: EUROSTOXX VSTOXX
1999-01-04 NaN NaN
1999-01-05 0.017228 0.489248
1999-01-06 0.022138 -0.165317
1999-01-07 -0.015723 0.256337
1999-01-08 -0.003120 0.021570
In [ 80 ]: rets.plot(subplots=True, grid=True, style=‘b’, figsize=( 8 , 6 ))

Figure 6-8. Log returns of EURO STOXX 50 and VSTOXX

We have everything together to implement the regression analysis. In what follows, the


EURO STOXX 50 returns are taken as the independent variable while the VSTOXX


returns are taken as the dependent variable:


In  [ 81 ]: xdat    =   rets[‘EUROSTOXX’]
ydat = rets[‘VSTOXX’]
model = pd.ols(y=ydat, x=xdat)
model
Out[81]: ––––––––-Summary of Regression Analysis–––––-
–––

                                    Formula:    Y   ~   <x> +   <intercept>

                                    Number  of  Observations:                                   4033
Number of Degrees of Freedom: 2

                                    R-squared:                                  0.5322
Adj R-squared: 0.5321

                                    Rmse:                                                       0.0389

                                    F-stat  (1, 4031):      4586.3942,  p-value:                    0.0000

                                    Degrees of  Freedom:    model   1,  resid   4031

                                    –––––––—Summary of  Estimated   Coefficients–––––
–––
Variable Coef Std Err t-stat p-value CI 2.5%
CI 97.5%
–––––––––––––––––––––––—
–––
x -2.7529 0.0406 -67.72 0.0000 -2.8326
-2.6732
Free download pdf