The problem is in the scaling of the dataset and the optimizer used. Try either:
>temp = UK.R[p:(period+p)]*100 and/or >tmp = hyperbFit(temp, method="nlminb") Also, don't have the hyperbFit inside the qhyperb function (you are estimating the same parameters 4 times!). Instead use something like: >tmp = hyperbFit(temp, method="nlminb")[1]$param >VaR05.UK.qghyp2[p] = qhyperb(probabilities6,param = tmp) Regards, Alexios On 13/05/2014 04:07, Wei-han Liu wrote: > Dear R users: > > I have encountered a problem on R package GeneralizedHyperbolic. It > fails to integrate for the lower tail area but I do not know how to > solve it. Listed below are my coding and the error message: > > require(GeneralizedHyperbolic) > return = > read.csv("d://UK.R.csv",blank.lines.skip=TRUE,stringsAsFactors=FALSE) > # return <- apply(series, function(x) diff(log(x))) > UK= as.numeric(return[,2]) > UK.R=diff(log(na.omit(UK))) > period=50 # moving-window length > n=length(UK.R) > VaR05.UK.qghyp <- numeric(n-period) > for (p in 1:(n-period)) > { > temp = UK.R[p:(period+p)] > probabilities6 <- 0.05 > VaR0001.UK.qghyp[p]<- qhyperb(probabilities6,param > =c(hyperbFit(temp)[1]$param[1],hyperbFit(temp)[1]$param[2],hyperbFit(temp)[1]$param[3],hyperbFit(temp)[1]$param[4]),lower.tail > = TRUE, method = c("spline"),subdivisions = 50) > } > > ERROR message: Error in integrate(dghypInt, q[i], Inf, subdivisions = > subdivisions, rel.tol = intTol, : > the integral is probably divergent > > If I change the method to integrate, it shows the error message below: > Error in uniroot(zeroFun, interval = c(mode, xHigh), ...) : > f() values at end points not of opposite sign > In addition: Warning messages: > 1: In optimize(f = modeFun, interval = range, maximum = TRUE) : > NA/Inf replaced by maximum positive value > 2: In optimize(f = modeFun, interval = range, maximum = TRUE) : > NA/Inf replaced by maximum positive value > 3: In optimize(f = modeFun, interval = range, maximum = TRUE) : > NA/Inf replaced by maximum positive value > 4: In optimize(f = modeFun, interval = range, maximum = TRUE) : > NA/Inf replaced by maximum positive value > 5: In optimize(f = modeFun, interval = range, maximum = TRUE) : > NA/Inf replaced by maximum positive value > 6: In optimize(f = modeFun, interval = range, maximum = TRUE) : > NA/Inf replaced by maximum positive value > > Does any people can help solve this problem? > > Best regards, > > Weihan > > > > _______________________________________________ > R-SIG-Finance@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions > should go. > _______________________________________________ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.