Example: stock market

# 1 The rugarch package - Booth School of Business

THE UNIVERSITY OF CHICAGO. Booth School of Business Business 41202, Spring Quarter 2015, Mr. Ruey S. Tsay Introduction to Some R packages We introduce some R packages that are useful for analyzing financial time series. These packages are in addition to those, fGarch, fBasics, nnet, evir, used in the lectures. 1 The rugarch package This is a general R package for univariate financial time series analysis. A model of the package consists of the mean equation and volatility equation. The mean equation can assume ARFIMA. models with ARCH-M characteristics and exogenous variables.

1.4 Model speci cation of the rugarch package To specify a univariate GARCH model in the rugarc package, one uses the command ugarchspec. See below:

### Information

Domain:

Source:

Please notify us if you found a problem with this document:

### Transcription of 1 The rugarch package - Booth School of Business

1 THE UNIVERSITY OF CHICAGO. Booth School of Business Business 41202, Spring Quarter 2015, Mr. Ruey S. Tsay Introduction to Some R packages We introduce some R packages that are useful for analyzing financial time series. These packages are in addition to those, fGarch, fBasics, nnet, evir, used in the lectures. 1 The rugarch package This is a general R package for univariate financial time series analysis. A model of the package consists of the mean equation and volatility equation. The mean equation can assume ARFIMA. models with ARCH-M characteristics and exogenous variables.

2 The volatility equation can assume many volatility models, including exponential GARCH and threshold GARCH and exogenous vari- ables. We describe the format of the mean and variance models used in the package so that readers can understand the commands and the output. The univariate time series model of the rugarch model is (B)(1 B)d (rt t ) = (B)at , at = t t (1). where B is the back-shift (or lag) operator, t is an iid sequence with mean zero and variance 1, t is the volatility, d is a real number satisfying 0 < d < 1, which denotes the long-memory parameter equivalent to the Hurst Exponent H , and (B) and (B) are the usual AR and MA polynomials.

3 The package allows t to follow standard Gaussian, standardized Student t, generalized error distribution, standardized generalized Hyperbolic, and various skew distributions. The function t here is defined as m v X m X. t = + i xit + i xit t + tk , i=1 i=m v+1. where is a constant, xit (for i = 1, .. , m) are exogenous variables and t and k = 1 or 2. From the formulation, the equation for t is rather general. It allows the first m v exogenous variables to affect the conditional mean directly and the last v to affect the conditional mean in conjunction with volatility, the parameter is the ARCH-in-mean effect with k = 1 for volatility in mean and k = 2 for variance in mean.

4 Recall that in the lecture notes, a univariate financial time series is written as rt = t + at , at = t t , (2). where t = E(rt |Ft 1 ) is the conditional mean of the time series rt given the information set Ft 1 and t2 = Var(rt |Ft 1 ) is the conditional variance,and t is the iid innovations with mean zero and variance 1. This definition of t is identical to that of the package in Equation (1) if (B) = (B) = 1. On the other hand, when (B) contains AR lags or contains MA lags, then the two t become different. The difference lies in the fact that t of Equation (1) is conditional mean given exogenous variables xit , not given Ft 1.

5 For the model in Equation (1), we have p X q X. E(rt |Ft 1 ) = i (rt i t i ) + i at i , i=1 i=1. where p and q denote the orders of (B) and (B), respectively. The rugarch package allows for many choices of volatility models. We only introduce those that are commonly used and discussed in the lecture. The standard GARCH model The standard GARCH(q, p) model, denoted by sGARCH, is m X q X p X. t2 = + i vit + i a2t i + 2. i t i , (3). i=1 i=1 i=1. where is the constant term and vit denotes exogenous variables. Even though the package uses (q, p), instead of (p, q) used in the lecture note, the meaning is the same.

6 Specifically, the first element denotes the ARCH order and the second the GARCH order. The exponential GARCH model The exponential GARCH model of Nelson (1991), denoted by eGARCH in the rugarch package , is written as m X q X p X. ln( t2 ) = + i vit + [ i t i + i (| t i | E(| t i |))] + 2. i ln( t i ), (4). i=1 i=1 i=1. where vit denotes exogenous variables. This formulation is slightly different from those used in the lecture notes. In particular, the constant term differs because the mean E(| t i |) is kept in Equation (4). Another difference lies in i and i.

7 To see the difference, the effect of a nonnegative t i on ln( t2 ) is i + i whereas that of a negative t i is i i . Therefore, the leverage-effect parameter is i . The GJR-GARCH model The GJR-GARCH or Threshold GARCH model, denoted by gjrGARCH in the rugarch package , is written as q p m X X X. t2 = + i vit + ( i 2t i + i It i 2t i ) + 2. i t i , (5). i=1 i=1 i=1. where It i = 1 if and only if t i < 0, denoting the indicator variable for negative t i . From the formulation, it is seen that the leverage-effect parameter is i . 2. Model specification of the rugarch package To specify a univariate GARCH model in the rugarc package , one uses the command ugarchspec.

8 See below: > args(ugarchspec). function ( = list(model = "sGARCH", garchOrder = c(1,1), submodel = NULL, = NULL, = FALSE), = list(armaOrder = c(1, 1), = TRUE, archm = FALSE, archpow = 1, arfima = FALSE, = NULL, archex = FALSE), = "norm", = list(), = list(), ..). Thus, the command basically consists of and The is a list that gives the type of volatility model to fit, the order of the volatility model, and the existence of any exogenous variables. The subcommands submodel and vari- are not used in the lectures. Interested readers can consult the vignette associated with the rugarch package .

9 The models commonly used in the lectures are: 1. Standard GARCH model: model = sGARCH'. 2. GARCH-M model with variance in mean: model = sGARCH', archm = TRUE, archpow =. 2. 3. GARCH-M model with standard error in mean: model = sGARCH', archm = TRUE, arch- pow = 1. 4. Exponential GARCH model: model = eGARCH'. 5. GJR-GARCH model: model = gjrGARCH'. The default mean model is ARMA(1,1). This is not typical for financial return series. The most commonly used mean specification is = list(armaOrder=c(0,0), ). Demonstrations In this subsection, I use the data set, , of the lecture to demonstrate fitting various volatility models via the rugarch package and compare the results with those from other packages .

10 > sp5=scan(file=' '). > require( rugarch ). #### Specify a standard GARCH(1,1) model with mean-equation being a constant. > spec1=ugarchspec( (model="sGARCH"), (armaOrder=c(0,0))). 3. ### Estimmation command > fit1=ugarchfit(data=sp5,spec=spec1). > show(fit1). *---------------------------------*. * GARCH Model Fit *. *---------------------------------*. Conditional Variance Dynamics ----------------------------------- GARCH Model : sGARCH(1,1). Mean Model : ARFIMA(0,0,0). Distribution : norm Optimal Parameters ------------------------------------ Estimate Std.