Source: http://www.dataguru.cn/article-794-1.html
The Rugarch package is a package in R that is used to fit and test the GARCH model. The package was first published on Http://rgarch.r-forge.r-project.org and has now been published on Cran. In simple terms, the package consists of four functions:
- Fitting Garch Family Model
- Garch Family Model Diagnosis
- Garch Family Model Prediction
- Analog Garch Sequence
- Fitting sequence Distributions
Let's say it separately.
first, fitting Garch family model
The fitting Garch family model is divided into three steps:
(1) Set the model form by Ugarchspec function
(2) Fitting model by Ugarchfit function
set the Model form
A typical garch (P,Q) model is as follows:
The model consists of three parts, the mean equation corresponding formula (1), the distribution hypothesis (2), the variance equation (3), the appropriate deformation of three parts can form Egarch model, egarch-ged model, EGARCH-T model, Igarch model, GARCH-M models and Qgarch models. Therefore, setting the model form is to set the mean equation, the variance equation and the distribution respectively.
The advantages of the Rugarch package are here. The parameters of the Ugarchspec function are also decomposed into three main parts, namely Variance.model, corresponding formula (3), Mean.model, corresponding formula (1), and $\epsilon$ in Distribution.model counterpart (2). The user constructs the model that they want to use by setting the parameters of the three parts separately.
As an example:
Variance.model = List (model = "Sgarch", Garchorder = C (1, 1), submodel = null, external.regressors = NULL, Variance.targeti ng = FALSE),
The variance model representing the fitting is Sgarch, and the autoregressive order of the variance model is (-), and the exogenous variable is not introduced in the variance model.
Mean.model = List (Armaorder = C (1, 1), Include.mean = TRUE, Archm = False, Archpow = 1, Arfima = False, External.regressor s = NULL, Archex = FALSE)
The mean equation is an arma model, and the equation independent variable contains the mean value, and no exogenous variable is introduced.
Distribution.model = "Norm"
Indicates that the model distribution is assumed to be normal.
The model settings for a sgarch-norm model can be completed by loading the three parts into the ugarchspec parameters.
Myspec=ugarchspec (Variance.model = list (model = "Sgarch", Garchorder = C (1, 1), submodel = NULL, external.regressors = NUL L, variance.targeting = False), Mean.model = List (Armaorder = C (1, 1), Include.mean = TRUE, Archm = False, Archpow = 1, AR Fima = False, External.regressors = NULL, Archex = False), Distribution.model = "norm")
Fit Model
The function to fit the model is ugarchfit. The parameters of the Ugarchfit are as follows:
Ugarchfit (spec, data, Out.sample = 0, Solver = "SOLNP", Solver.control = List (), Fit.control = List (stationarity = 1, fixed . SE = 0, scale = 0), ...)
Where spec is the result of the UGARCHSPEC function, data is the object. Solver is the optimization algorithm. Solver.control set the optimization parameters, Fit.control set the fitting parameters.
Take the example above:
Myfit=ugarchfit (myspec,data=sp500ret,solver= "SOLNP")
Here a garch model is done.
View Results
Type the following code to view the model's fit results:
Extracting model Results
The extraction of model results in Rugarch packets depends on the As.data.frame function. For example, to extract the fitted values of a model
As.data.frame (myfit,which= "fitted")
Extract the residuals sequence:
As.data.frame (myfit,which= "residuals")
Extract Variance sequence:
As.data.frame (myfit,which= "Sigma")
Of course, you can also view all at the same time:
As.data.frame (Myfit,which=all)
Or
As.data.frame (Myfit)
Two statements are equivalent.
second, model diagnosis
Plot (Myfit) allows you to graphically diagnose the results of a model:
> Plot (myfit)
Make a plot selection (or 0 to exit):
1:
2:
3:
4:
5:
6:
7:
8:
9: Qq-plot of standardized RESIDUALS10: ACF of standardized RESIDUALS11: ACF of squared standardized RESIDUALS12: news-impact curveselection:1
three, model prediction
If the model passes the test, the future can be predicted with the Ugarchforcast function:
You can use FPM or plot to view the predicted results of the model. Like what:
> Plot (Fore)
1: Time Series Prediction (unconditional)
2: Time Series prediction (rolling)
3: Conditional SD Predictionselection:1
The Garch family model in Rugarch package and R language