How could I use GARCH model to detect if the volatility is constant during all the series(time series)?
I can't do a visual check, I need to detect if the volatility is constant using R and GARCH function of tseries
package
You can use the classic Engle test for ARCH effects. The test is implemented as follows (copy from Ch. Brooks, "Introductory Econometrics for Finance").
Estimate the model
$$y_t=\beta_0+x_{1t}\beta_1+...+x_{kt}\beta_k + u_t, \quad t=1,...,T$$ using OLS and save the residuals $\hat{u}_i$. (If you do not have any explanatory variables, simply demean $y$.)
Square the residuals and estimate the following regression:
$$\hat{u_t}^2=\gamma_0+\hat{u}_{t-1}^2\gamma_1+\hat{u}_{t-2}^2\gamma_2+...+\hat{u}_{t-q}^2\gamma_q+v_t,$$
Obtain $R^2$ from this regression.
The test statistic, which is defined as $T\cdot R^2$, is distributed as $\chi^2(q)$.
The null hypothesis is $\gamma_i=0$, $i=1,\ldots,q,$ against the alternative $\exists j: \gamma_j\neq 0$.
This can be implemented in R as follows. Supposing we have $\hat{u}$, the p-value for the hypothesis is
> set.seed(13)
> u<-rnorm(100)
> 1-pchisq(summary(lm(X1~.,data=data.frame(embed(u^2,5))))$r.squared*100,4)
[1] 0.6867667
Naturally you will need to decide how many lags to include. Since usually GARCH models use small numbers of lags, some predefined number may entirely appropriate. I would do some MC simulations to determine which works best.
garch
. The answer to the second question is yes, with the usual caveats of interpreting p-values. The number of lags here is 4. So if your number of lags is $p$, change 4 to $p$ and 5 to $p+1$.
$\endgroup$
p
. This is an argument to pchisq, which is the number of degrees of freedom of chi square distribution.
$\endgroup$