Quantopian Lecture Series: ARCH, GARCH, and GMM

Developed in collaboration with Professor Andrei Kirilenko at MIT Sloan. This notebook gives an intro to ARCH and GARCH models, which are commonly used in volatility forecasting. We also cover using maximum likelihood estimation and Generalized Method of Moments (GMM) to estimate parameters for a GARCH model. For more information about our involvement with top-tier universities, please contact me at [email protected]

Find all of our lectures hosted permanently with videos at www.quantopian.com/lectures.

948
Loading notebook preview...
Notebook previews are currently unavailable.
Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

26 responses

Videos will be released at some point in the future.

Thanks Delaney for this notebook. Do you have a similar implementation using GMM for multivariate GARCH? I want to forecast the covariance matrix of a bunch of stocks and cannot find an easily available implementation in python.

Q lectures are extremely good and useful. It will be useful if you release backtests also along with with Notebooks to they can easily be adopted for trading.

Pravin, this is currently the only implementation I have. GARCH seems to be one of those methods that is very poorly implemented as of right now, MATLAB is the only other place I've seen an implementation.

Suminda, thanks for the kind words. We're working on releasing more backtests that use the concepts presented in the notebooks. Some of the notebooks already have backtests attached, see here.

Do we have access to https://pypi.python.org/pypi/arch/3.0 in the IDE?

We don't currently whitelist that module. I've put in a request to have it whitelisted, we have to check and make sure there are no potential security holes opened by importing code from there.

Found this paper that shows how to get Multivariate GARCH from univariate GARCH in case someone is interested. http://www.burns-stat.com/pages/Working/multgarchuni.pdf

This looks very useful paper Pravin! Have you found some python implementation for the covariance matrix estimation?

@Tom, I haven't found one. Maybe time to implement one.

@Delaney A couple thoughts on interpretation:

1. GMM is given the theta from the MLE as a starting point, and happened (in my random sample) to improve the JB test for normality. Should I interpret the GMM as a model-free way of fine-tuning theta (i.e. the estimated model parameters)?
2. Both the MLE and GMM estimated the constant term in the model (alpha_0) as c0.8, which is under the actual figure of 1.0. Should I interpret this as noise, or is there a chance these estimates are biased?

There are a lot of GARCH implementations in R. Professor Robert Engle has many examples on the Stern VLab

@Dan

1. Using theta from the MLE is just an initial guess. Often it's also good to add your prior knowledge into the guess, picking something that is close enough to the real optima that you're more likely to get there without getting stuck. GMM is just a numerical optimization over the residuals, trying to fit the standard moments to a given set, often the moments of a normal distribution. In that sense yes, it is a model-agnostic fitting function. In practice it's better to use MLE methods first as there is a greater chance you might find a closed form solution, or can use the structure of the MLE to pick an initial guess that will avoid local optima. GMM tends to be a technique reserved for when the MLE isn't available. You can also use it to fine tune and see if the guess stays consistent, as if the GMM gave you a totally different answer from the MLE that's an indication something might be off.

2. I am honestly unsure and suspect the bias (if real) would depend on what type of model is being fit. I would chalk that up to noise barring further evidence.

I am comparing two methods for predicting volatility:

1. Standard deviation of last 10 days of daily returns: model free; one parameter
2. GARCH(1,1) on last year of daily returns: model with 3 parameters

I use method 1 in my trading, but I see can it gets carried away in periods of elevated volatility. It just assumes the current volatility continues. In reality, elevated volatility typical reverts to the mean rather quickly. This is neatly solved by GARCH(1,1), at the expense of two further parameters to estimate.

Reading a few papers, it seems clear that the GARCH model does better with longer lookbacks than one year. Intuitively this makes sense, as method 1 needs at least 10 days and has only one parameter, so method 2 might need 10**3 days (4 years) for 3 parameters (assuming orthogonal etc).

Combining the above two thoughts, and the re-formulation of GARCH(1,1) in this paper:

Prediction of tomorrow's variance = unconditional variance + beta * (today's prediction of variance - unconditional variance)

You can then substitute the unconditional variance with the long-term sample variance of, for example, the last 4 years of daily returns. You substitute today's prediction of variance with the short-term sample variance of, for example, the last 10 days of daily returns. You then run a simple linear regression to determine beta. I'm only estimating one parameter, but of course, there are two implicit in the model (4 years and 10 days).

Prediction of tomorrow's variance = var_4_years + beta * ( var_10_days - var_4_years )

This all makes sense to me. I would also add that usually what you'd do to actually make the prediction is simulate 1000 or so future time series based on your estimated GARCH parameters, then use that as a range of potential values.

I use this version:

var_t+1= long_term_average+ alpha*(residual_today) ^2 +beta*(var_t)

Couple questions on this lecture:

1. Where does the F-statistic formula come from? Is that Engle's Arch test? Would love get some additional information.
2. Any timeline on a video?

Hello Ian,

1. Could you give me a little more information about what part of the lecture you're referring to?
2. My earlier comment stating that it will be released at "some point in the future" seems a little useless now in retrospect. I apologize for the delay. We've been prioritizing production of other content based on demand and gaps in users' knowledge. We will get to this video at some point, I unfortunately don't have any updated ETA at this point in time. The more people who request it, the higher up our queue it moves.

Thanks,
Delaney

Hey Delaney,

Thanks for the reply! Answers below.

1. This bit:

### Testing for ARCH Behavior

The first step is to test for ARCH conditions....

We use OLS to estimate  θ̂ =(â 0,â 1,…,â p)θ^=(a^0,a^1,…,a^p)  and the covariance matrix  Ω̂ Ω^ . We can then compute the test statistic
F=θ̂ Ω̂ −1θ̂ ′
We will reject if  F is greater than the 95% confidence bars in the  (X)2(p)(X)2(p)  distribution.


It looks like that is without a doubt, Engle's ARCH test. This MIT Sloan Finance Lecture confirmed my suspicions. I would still be interested in hearing you guys explain it though – I've learned a lot from your lectures!

1. No worries, I'd give it a watch when you release it though!

Ah yes, seems like you found the documentation that supported the original creation of the lecture. We'll see when we can create a video explaining it a bit more, but no promises about timeframe.

@ Delaney Mackenzie was a video ever released?

Hi Michael, we have not yet released a video, but we have added many more new videos for a fair chunk of our other lectures. We will be adding one for this as soon as we can.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thanks Maxwell - will wait for the posted video

I think there may be something wrong with the code block after "TESTING FOR ARCH BEHAVIOR". The value of the test-statistic F seems to be very high. I tried putting in random samples from distributions that don't have arch behavior(uniform, normal) and the p-value was still 0(very high F). I tried many different lag values also. I couldn't find a way to make the p-value change. Am I missing something?

Hey Seamus,

Can you provide the version of the notebook in which you put in the other distributions? It would be helpful to figure out what's going on here.

Thanks,
Delaney

Hi Delaney,

Thank you so much for this helpful notebook. I am just a bit confused about the part 'GMM for estimating GARCH(1,1) parameters'.

At the second step, when updating the covariance matrix W, the gmm_variance function calculates the squared moments and then calculates G*G.T., which means the function actually calculates the square of the squared moments? Should it be just calculating the moments (without the square) and then calculates G*G.T?

Many thanks,

Bowen

Hello Bowen,

Thanks for your question. It's been a little while since I worked with GMM, so some of the details are a little fuzzy, but I can address the intuition.

The point of W is to allow the method to focus more on moments which are providing more information (have a higher signal-to-noise ratio). It measures which moments are more noisy, and then weights those moments less in the next optimization step. G is a 4x1 matrix, and G.T is a 1x4, so the product is a 4x4 matrix in our case.. The wikipedia page on GMM has some good info on why W is computed this way.

https://en.wikipedia.org/wiki/Generalized_method_of_moments

I actually spent some time looking at the materials and I'm not sure whether or not that's a bug you found. It's not clear to me whether it's correct to square the moments before constructing the G matrices. I don't have time in the immediate future to check in on this, and unfortunately many of the sources are pretty unclear. Do you have a source which indicates that the G matrix should be on the un-squared moments?