Loading...

Plus+ Python

How To Develop a GARCH Volatility Model for Bitcoin Prices

How To Develop a GARCH Volatility Model for Bitcoin Prices


GARCH Volatility Modeling
It has been shown and well documented that financial time series have changing periods of variance (volatility) and often exhibit fat tailed distributions, and Bitcoin is no exception. Due to the change in volatility over different time periods (a technical term referred to as "heteroskedasticity"), GARCH (which stands for the Generalized AutoRegressive Conditional Heteroskedasticity) takes into account a long run average of volatility, a previous periods' volatility, and an error term. We will quote directly from the research published by Robert Engle below:

    The GARCH model that has been described is typically called the GARCH(1,1) model. The (1,1) in parentheses is a standard notation in which 8 the first number refers to how many autoregressive lags or ARCH terms appear in the equation, while the second number refers to how many moving average lags are specified which here is often called the number of GARCH terms. Sometimes models with more than one lag are needed to find good variance forecasts.
    Although this model is directly set up to forecast for just one period, it turns out that based on the one period forecast a two period forecast can be made. Ultimately by repeating this step, long horizon forecasts can be constructed. For the GARCH(1,1) the two step forecast is a little closer to the long run average variance than the one step forecast and ultimately, the distant horizon forecast is the same for all time periods as long as a + b < 1. This is just the unconditional variance. Thus the GARCH models are mean reverting and conditionally heteroskedastic but have a constant unconditional variance.


Model Implementation in Python

We are going to use the Bitcoin time series from FTX on our site in order to construct our model. (*Consider how this could be extended for other cryptocurrencies!) We will also use help from the arch library. One of the first steps in our process (after loading the data), is to compute the log returns over each time period. In this model example, we will use all previous data to train the model and make a forecast for the following day. (There are multiple theories and practices for the best way to fine tune the parameters and build a model.) Of course, all of our code is commented line by line so that you can follow what is going on! Also, this working example with Bitcoin can be easily extended to other cryptocurrencies and fit to your purpose.

Plus+ membership required

Create a Plus+ account to view the live codebase.

This article has a fully working, notebook-ready code block. Sign up for Plus+ to access it and the rest of the 20+ premium articles.

Subscribe to Plus+ Browse Plus+ articles