Reader small image

You're reading from  Python for Finance Cookbook - Second Edition

Product typeBook
Published inDec 2022
PublisherPackt
ISBN-139781803243191
Edition2nd Edition
Right arrow
Author (1)
Eryk Lewinson
Eryk Lewinson
author image
Eryk Lewinson

Eryk Lewinson received his master's degree in Quantitative Finance from Erasmus University Rotterdam. In his professional career, he has gained experience in the practical application of data science methods while working in risk management and data science departments of two "big 4" companies, a Dutch neo-broker and most recently the Netherlands' largest online retailer. Outside of work, he has written over a hundred articles about topics related to data science, which have been viewed more than 3 million times. In his free time, he enjoys playing video games, reading books, and traveling with his girlfriend.
Read more about Eryk Lewinson

Right arrow

Modeling Volatility with GARCH Class Models

In Chapter 6, Time Series Analysis and Forecasting, we looked at various approaches to modeling time series. However, models such as ARIMA (Autoregressive Integrated Moving Average) cannot account for volatility that is not constant over time (heteroskedastic). We have already explained that some transformations (such as log or Box-Cox transformations) can be used to adjust for modest changes in volatility, but we would like to go a step further and model it.

In this chapter, we focus on conditional heteroskedasticity, which is a phenomenon caused when an increase in volatility is correlated with a further increase in volatility. An example might help to understand this concept. Imagine the price of an asset going down significantly due to some breaking news related to the company. Such a sudden price drop could trigger certain risk management tools of investment funds, which start selling the stocks as a result of the previous decrease...

Modeling stock returns’ volatility with ARCH models

In this recipe, we approach the problem of modeling the conditional volatility of stock returns with the Autoregressive Conditional Heteroskedasticity (ARCH) model.

To put it simply, the ARCH model expresses the variance of the error term as a function of past errors. To be a bit more precise, it assumes that the variance of the errors follows an autoregressive model. The entire logic of the ARCH method can be represented by the following equations:

The first equation represents the return series as a combination of the expected return μ and the unexpected return . has white noise properties—the conditional mean equal to zero and the time-varying conditional variance .

Error terms are serially uncorrelated but do not need to be serially independent, as they can exhibit conditional heteroskedasticity.

is also known as the mean-corrected return, error term, innovations...

Modeling stock returns’ volatility with GARCH models

In this recipe, we present how to work with an extension of the ARCH model, namely the Generalized Autoregressive Conditional Heteroskedasticity (GARCH) model. GARCH can be considered an ARMA model applied to the variance of a time series—the AR component was already expressed in the ARCH model, while GARCH additionally adds the moving average part.

The equation of the GARCH model can be presented as:

While the interpretation is very similar to the ARCH model presented in the previous recipe, the difference lies in the last equation, where we can observe an additional component. Parameters are constrained to meet the following: , and .

In the GARCH model, there are additional constraints on coefficients. For example, in the case of a GARCH(1,1) model, must be less than 1. Otherwise, the model is unstable.

The two hyperparameters of the GARCH model can be described as:

...

Feedback

We are constantly looking at improving our content, so what could be better than listening to what you as a reader have to say? Your feedback is important to us and we will do our best to incorporate it. Could you take two mins to fill out the feedback form for this book and let us know what your thoughts are about it? Here's the link: https://forms.office.com/r/sYbSyLm2cX.

Thank you in advance.

In Chapter 6, Time Series Analysis and Forecasting, we looked at various approaches to modeling time series. However, models such as ARIMA (Autoregressive Integrated Moving Average) cannot account for volatility that is not constant over time (heteroskedastic). We have already explained that some transformations (such as log or Box-Cox transformations) can be used to adjust for modest changes in volatility, but we would like to go a step further and model it.

In this chapter, we focus on conditional heteroskedasticity, which is a phenomenon caused when an increase in volatility is...

Modeling stock returns' volatility with ARCH models

In this recipe, we approach the problem of modeling the conditional volatility of stock returns with the Autoregressive Conditional Heteroskedasticity (ARCH) model.

To put it simply, the ARCH model expresses the variance of the error term as a function of the past errors. To be a bit more precise, it assumes that the variance of the errors follows an autoregressive (AR) model. The entire logic of the ARCH method can be represented by the following equations:

The first equation represents the return series as a combination of the expected return μ and the unexpected return 𝝐t. 𝝐t has white noise properties—the conditional mean equal to zero and the time-varying conditional variance 𝜎2t. Error terms are serially uncorrelated but do not need to be serially independent, as they can exhibit conditional heteroskedasticity.

is also known as the mean-corrected return, error term, innovations...

Modeling stock returns' volatility with GARCH models

In this recipe, we present how to work with an extension of the ARCH model, namely the Generalized Autoregressive Conditional Heteroskedasticity (GARCH) model. GARCH can be considered an ARMA model applied to the variance of a time series—the AR component was already expressed in the ARCH model, while GARCH additionally adds the moving average part.

The equation of the GARCH model can be presented as:

While the interpretation is very similar to the ARCH model presented in the previous recipe, the difference lies in the last equation, where we can observe an additional component. Parameters are constrained to meet the following:
, and
.

In the GARCH model, there are additional constraints on coefficients. For example, in the case of a GARCH(1,1) model,

must be less than 1, otherwise, the model is unstable.

The two hyperparameters of the GARCH model can be described as:

  • p: The number of lag variances
  • q...

Forecasting volatility using GARCH models

In the previous recipes, we have seen how to fit ARCH/GARCH models to a return series. However, the most interesting/relevant case of using ARCH class models would be to forecast the future values of the volatility.

There are three approaches to forecasting volatility using GARCH class models:

  • Analytical – due to the inherent structure of ARCH class models, analytical forecasts are always available for the 1-step ahead forecast. Multi-step analytical forecasts can be obtained using a forward recursion, however, that is only possible for models which are linear in the square of the residuals (such as GARCH or Heterogeneous ARCH).
  • Simulation – simulation-based forecasts use the structure of an ARCH class model to forward simulate possible volatility paths using the assumed distribution of residuals. In other words, they use random number generators (assuming specific distributions) to draw the standardized residuals. This approach...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Python for Finance Cookbook - Second Edition
Published in: Dec 2022Publisher: PacktISBN-13: 9781803243191
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Eryk Lewinson

Eryk Lewinson received his master's degree in Quantitative Finance from Erasmus University Rotterdam. In his professional career, he has gained experience in the practical application of data science methods while working in risk management and data science departments of two "big 4" companies, a Dutch neo-broker and most recently the Netherlands' largest online retailer. Outside of work, he has written over a hundred articles about topics related to data science, which have been viewed more than 3 million times. In his free time, he enjoys playing video games, reading books, and traveling with his girlfriend.
Read more about Eryk Lewinson