How it works...

In Steps 2 and Step 3, we downloaded the daily stock prices of Google, Microsoft, and Apple. Then, we calculated simple returns and multiplied them by 100 to avoid encountering convergence errors.

In Step 5, we defined empty lists for storing elements required at later stages: GARCH coefficients, conditional volatilities, standardized residuals, and the models themselves (used for forecasting). In Step 6, we iterated over the columns of the DataFrame containing the stock returns and fitted a univariate GARCH model to each of the series. We stored the results in the predefined lists. Then, we wrangled the data in order to have objects such as residuals in DataFrames, to make work with them and visual inspection easier.

In Step 8, we calculated the constant conditional correlation matrix (R) as the unconditional correlation matrix of zt:

 ,

where zt stands for time t standardized residuals from the univariate GARCH models.

In the last step, we obtained one-step-ahead forecasts of the conditional covariance matrix Ht+1. To do so, we did the following:

  • We created a matrix Dt+1 of zeros, using np.zeros.
  • We stored the one-step-ahead forecasts of conditional variances from univariate GARCH models in a list called diag
  • Using np.fill_diagonal, we placed the elements of the list called diag on the diagonal of the matrix  Dt+1.
  • Following equation 3 from the introduction, we obtained the one-step-ahead forecast using matrix multiplication (np.matmul).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.114.230