[R-SIG-Finance] Problems using garchFit() in package fseries
Diethelm Wuertz
wuertz at itp.phys.ethz.ch
Thu Aug 24 23:20:36 CEST 2006
Stefan Westermair wrote:
>Dear list members,
>
>how can i make the garchFit() function accept variables in the formula.mean or formula.var expressions?
>I was trying to run something like the following (shorter but produceses the same error message) example:
>
>
>
>>my_Garch <- function(data,p,q) {
>>
>>
>+ fit <- garchFit(series=data, formula.var= ~garch(p,q))
>+ return(fit)
>+ }
>
>
Use:
require(fSeries)
myGarch = function(data, p, q)
{
form = as.formula(paste("~garch(", p, ",", q, ")"))
garchFit(formula.var = form, series = data)
}
myGarch(data = garchSim(n = 1000, rseed = 4711), p = 1, q = 1)
DW
>##simulate testdata and run the function
>
>
>
>>testdata <- garchSim(n=1000)@.Data
>>testfit <- my_Garch(testdata,1,2)
>>
>>
>
>##produced the following error message
>
>Fehler in if (p + q == 0) stop("Misspecified GARCH Model: Both Orders are zero!") :
> Fehlender Wert, wo TRUE/FALSE nötig ist
>Zusätzlich: Warning message:
>NAs durch Umwandlung erzeugt
>
>It seems that .garchInitSeries reads the parameter from the formula.var expression and the then checks for positivity. In my case not "1" and "2" but "p" and "q" were read (?).
>
>Did anybody ever try to use variables in the garchFit() function? I am intending to fit GARCH models for several parameter constellations and then select the best fit according to some information criterion.
>
>Thanks a lot in advance,
>
>Stefan
>
>
>
More information about the R-SIG-Finance
mailing list