Skip to content

fSeries

3 messages · CYRIL.CAILLAULT@FORTISINVESTMENTS.COM, Diethelm Wuertz

#
1. Currently I'm writing a complete new GARCH package, and as long as it 
is not
yet ready I have added the garch function from Adrian Trapletti's 
tseries package
to the fSeries package.

2. But the error in the output you  observed  comes not from the "garch" 
function,
it comes from my "garchSim" function. Please modify the function 
garchSim() in the
following way ----


garchSim =
function(model = list(omega = 1.0e-06, alpha = 0.1, beta = 0.8, mu = 0),
n = 100, innov = NULL, n.start = 100, start.innov = NULL, rand.gen = 
rnorm, ...)
{    
    # Doesn't work, replace the three following lines ... 
    # if (!exists("model$alpha")) model$alpha = 0
    # if (!exists("model$beta")) model$beta = 0
    # if (!exists("model$mu")) model$mu = 0
   
    # with ...
    if (is.null(model$alpha)) model$alpha = 0
    if (is.null(model$beta)) model$beta = 0
    if (is.null(model$mu)) model$mu = 0

    max.order = max(length(model$alpha), length(model$beta))
    if (n.start < max.order)
        stop("n.start must be greater or equal max(alpha, beta)")
    if (is.null(start.innov))
        start.innov = rand.gen(n.start, ...)
    if (is.null(innov))
        innov = rand.gen(n, ...)
    h = x = z = c(start.innov, innov)
    for (i in 1:max.order) {
        h[i] = model$omega/(1 - sum(model$alpha) - sum(model$beta))
        x[i] = sqrt(h[i]) * z[i] + model$mu
    }
    n.alpha = length(model$alpha)
    n.beta = length(model$beta)
    for (i in (max.order + 1):(n.start + n)) {
        h[i] = model$omega + sum(model$alpha * x[i - (1:n.alpha)]^2) +
            sum(model$beta * h[i - (1:n.beta)])
        x[i] = sqrt(h[i]) * z[i] + model$mu
    }
    as.ts(x[-(1:n.start)])
}


and try the folloowing examples:


require(fSeries)

garchFit(garchSim(n = 1000))

garchFit(garchSim(model = list(omega = 1.0e-06, alpha = 0.1, beta = 0.8,
    mu = 0), n =1000))

garchFit(garchSim(model = list(omega = 1.0e-06, alpha = 0.6), n = 1000))
garchFit(garchSim(model = list(omega = 1.0e-06, alpha = 0.6), n = 1000),
    order=c(0, 1))
   

The code will be updated in the next fSeries package.
I apologize for any inconvenience caused by this bug.

Diethelm Wuertz
CYRIL.CAILLAULT at FORTISINVESTMENTS.COM wrote:

            
#
Diethelm Wuertz wrote:
Tabs removed from the code, makes a nicer printout ....

garchSim =
function(model = list(omega = 1.0e-06, alpha = 0.1, beta = 0.8, mu = 0),
n = 100, innov = NULL, n.start = 100, start.innov = NULL, rand.gen = 
rnorm, ...)
{    
    # Doesn't work, replace the three following three lines ... 
    # if (!exists("model$alpha")) model$alpha = 0
    # if (!exists("model$beta")) model$beta = 0
    # if (!exists("model$mu")) model$mu = 0
   
    # with ...
    if (is.null(model$alpha)) model$alpha = 0
    if (is.null(model$beta)) model$beta = 0
    if (is.null(model$mu)) model$mu = 0

    max.order = max(length(model$alpha), length(model$beta))
    if (n.start < max.order)
        stop("n.start must be greater or equal max(alpha,beta)")
    if (is.null(start.innov))
        start.innov = rand.gen(n.start, ...)
    if (is.null(innov))
        innov = rand.gen(n, ...)
    h = x = z = c(start.innov, innov)
    for (i in 1:max.order) {
        h[i] = model$omega/(1 - sum(model$alpha) - sum(model$beta))
        x[i] = sqrt(h[i]) * z[i] + model$mu
    }
    n.alpha = length(model$alpha)
    n.beta = length(model$beta)
    for (i in (max.order + 1):(n.start + n)) {
        h[i] = model$omega + sum(model$alpha * x[i - (1:n.alpha)]^2) +
            sum(model$beta * h[i - (1:n.beta)])
        x[i] = sqrt(h[i]) * z[i] + model$mu
    }
    as.ts(x[-(1:n.start)])
}