Taming the Market Beast: Predicting Volatility with GARCH Models

Taming the Market Beast: Predicting Volatility with GARCH Models

Volatility is a key factor in risk management, as higher volatility often implies higher risk. When asset prices exhibit larger fluctuations, the likelihood of incurring losses increases, making those periods riskier. Conversely, periods with lower volatility, which have more stable price movements, are generally considered less risky. Quantifying volatility allows us to determine the size of our position in a trading strategy. In this article, we discuss two methods for predicting volatility: the GARCH (Generalised Autoregressive Conditional Heteroskedastic) model and the SVR (Support Vector Regression) model. We'll demonstrate these methods by predicting Ethereum's volatility for the following day.

Realised volatility is the standard deviation of an asset's return over a specific time period. Daily volatility can be calculated using sums of intra-daily squared hourly returns. For instance, the figure below shows daily volatility of Ethereum from 2018, with noticeable peaks during the COVID outbreak and LUNA collapse.

GARCH Model

The GARCH model, one of the simplest volatility prediction models in the ARCH family, estimates volatility using past returns and volatilities:

No alt text provided for this image

This equation reflects a fundamental property of volatility called "volatility clustering," meaning that volatility tends to persist over time. Periods of high volatility tend to be followed by more high volatility, and the same applies to low volatility. If the sum of the coefficients $\alpha$ and $\beta$ is smaller than one, then volatility is guaranteed to be mean-reverting.

Fitting a GARCH(1,1) model on the daily return series of Ethereum up until 365 days ago (leaving the last 365 days for testing) can be done with the following Python code:

from arch import arch_model
garch = arch_model(df['ret'][:-365], mean='zero', vol='GARCH', p=1, o=0, q=1).fit(disp='off')
print(garch.summary())        
No alt text provided for this image

To choose the best order (p,q) for the model, we can use the Akaike Information Criterion (AIC) for model selection. We iterate over all values of p and q from 1 to 4 and select the model with the lowest AIC score.

import numpy as n


aic_garch = []
for p in range(1, 5):
? ? for q in range(1, 5):
? ? ? ? garch = arch_model(df['ret'][:-365], mean='zero', vol='GARCH', p=p, o=0, q=q).fit(disp='off')
? ? ? ? aic_garch.append(garch.aic)
? ? ? ? if garch.aic == np.min(aic_garch):
? ? ? ? ? ? best_param = p, q
garch = arch_model(df['ret'][:-365], mean='zero', vol='GARCH', p=best_param[0], o=0, q=best_param[1]).fit(disp='off')
print(garch.summary())        
No alt text provided for this image

Unlike the simpler (1,1) model, this (4,1) model has some non-significant coefficients, indicating the presence of overfitting. For this reason, we use the former model for making prediction. The following figure shows the predicted volatility versus the true volatility of ETH in the last 365 days. We see that we are able to predict some peaks in volatility with great precision.?


No alt text provided for this image

To measure the discrepancy between the predicted values and the true values, we use the following loss function:

No alt text provided for this image

The advantage of this loss function over the usual mean square error is that it is scale-invariant. The mean value of this loss function for the above prediction is 0.14144.

SVR Model

Next, let's explore the SVR model. SVR is a variation of the Support Vector Machines (SVM) algorithm, commonly used for classification tasks. The main idea behind SVR is to identify a hyperplane with the smallest possible margin while still ensuring that a certain fraction of the data points, known as support vectors, lie within a certain distance from the hyperplane. In SVR, the objective is to minimise the prediction error, also known as the epsilon-insensitive loss function, subject to the margin constraint. The margin constraint is controlled by a hyperparameter called the regularisation parameter or C, which determines the trade-off between achieving a smaller margin and allowing more training points to be outside the margin. SVR uses a kernel function to map the input features into a higher-dimensional space, where non-linear relationships can be better captured. In the following example, we use a linear kernel for illustration purposes.

The code below implements a grid search to find the optimal values of the hyperparameters in SVR.

from sklearn.svm import SVR
from scipy.stats import uniform as sp_rand
from sklearn.model_selection import RandomizedSearchCV
?
svr_lin = SVR(kernel='linear')?
? ? ? ??
X_train = df[['vol_lag', 'ret']][:-365]
Y_train = df[['vol']][:-365]
X_test? = df[['vol_lag', 'ret']][-365:]
para_grid = {'gamma': sp_rand(),
? ? ? ? ? ? ? 'C': sp_rand(),
? ? ? ? ? ? ? 'epsilon': sp_rand()}?
clf = RandomizedSearchCV(svr_lin, para_grid)?
clf.fit(X_train.values, Y_train.values.reshape(-1,))?
predict_svr = clf.predict(X_test)
        

Here, we use past volatility and return as input features, just like in the GARCH model. The figure below displays the predicted value versus the true value of Ethereum's daily volatility. Compared to the GARCH model, the SVR model overshoots the peaks. However, in milder market conditions, SVR predictions overlap more with the true value compared to GARCH predictions. This is reflected in a smaller value of the loss function, which is 0.10689.

No alt text provided for this image

Summary

In this article, we presented and compared two methods for predicting volatility: GARCH and SVR. For the task of predicting Ethereum's daily volatility, the GARCH model captures the peaks very well but has a higher overall loss function compared to the SVR model in the past 365 days. However, the SVR model performs better in milder market conditions, resulting in a smaller loss function value. Both models have their strengths and weaknesses, and the choice between them may depend on the specific context and requirements of a given trading strategy.

要查看或添加评论,请登录

DFI Labs的更多文章

社区洞察

其他会员也浏览了