1

I am modelling a time series as a GARCH(1,1)-process:

Garch

And the z_t are t-distributed.

In R, I do this in the fGarch-package via

model <- garchFit(formula = ~garch(1,1), cond.dist = "std", data=r)

Is this correct?

Now, I would like to understand the output of this to check my formula.

Obviously, model@fit$coefs gives me the coefficients and model@fitted gives me the fitted r_t.

But how do I get the fitted sigma_t and z_t?

Claudio Moneo
  • 489
  • 1
  • 4
  • 10

2 Answers2

1

It is a list structure. Can find the structure with

str(model)

From the structure, it is easier to extract with $ or @

model@fit$series$z
model@sigma.t
akrun
  • 874,273
  • 37
  • 540
  • 662
  • So model@sigma_t gives me the sigma_t in above model specification? I am trying to make sure that the model and I are talking about the same objects... also how can I get z_t in the fitted model? – Claudio Moneo Mar 09 '21 at 18:37
  • @ClaudioMoneo I don't find an object named `z_t`. I thought it is the `z` from the 'series' – akrun Mar 09 '21 at 19:41
  • The problem is that if I add up the z_t and sigma_t according to the model formula, I don't arrive at the true value – Claudio Moneo Mar 09 '21 at 21:48
  • @ClaudioMoneo I am not that familiar with the garch model – akrun Mar 09 '21 at 21:49
1

I believe that the best way is to define extractor functions when generics are not available and methods when generics already exist.

The first two functions extract the values of interest from the fitted objects.

get_sigma_t <- function(x, ...){
  x@sigma.t
}
get_z_t <- function(x, ...){
  x@fit$series$z
}

Here a logLik method for objects of class "fGARCH" is defined.

logLik.fGARCH <- function(x, ...){
  x@fit$value
}

Now use the functions, including the method. The data comes from the first example in help("garchFit").

N <- 200
r <- as.vector(garchSim(garchSpec(rseed = 1985), n = N)[,1])
model <- garchFit(~ garch(1, 1), data = r, trace = FALSE)

get_sigma_t(model) # output not shown
get_z_t(model)     # output not shown

logLik(model)
#LogLikelihood 
#    -861.9494 

Note also that methods coef and fitted exist, there is no need for model@fitted or model@fit$coefs, like is written in the question.

fitted(model)  # much simpler
coef(model)
#          mu        omega       alpha1        beta1 
#3.541769e-05 1.081941e-06 8.885493e-02 8.120038e-01 
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66