VaR calculation warning with rugarch

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

VaR calculation warning with rugarch

Mingersming
This post was updated on .
Hi all,

there is one issue I can´t go one myself. I try to fit a nig-distribution in a rolling window method to a time-series with the fantastic rugarch package. I use the option 'calculate.VaR' for several other distributions and it works fine, but if I switch to the nig-distribution, I receive the following warning:

In ans[i] = mu[i] + sigma[i] * .qsnigC(p, rho = skew[i],  ... :number of items to replace is not a multiple of replacement length

I tried to turn off the option and calculate the quantile on my own. I think there is an mistake with the number of the parameters, but what can I change to get over?

For code, see below

Best regards

library(quantmod)
library(rugarch)
library(PerformanceAnalytics)

bi <- getSymbols('^GDAXI', from = "2004-01-01", to = "2015-08-01")
bi <- Ad(get(bi[1]))
bi_tlr <- Return.calculate(bi, method = "log")
bi_tlr <- na.omit(bi_tlr)

ctrl = list(rho = 1, delta = 1e-11, outer.iter = 1000, tol = 1e-12)
cl = makePSOCKcluster(10)

T = nrow(bi_tlr)
t_bt <- nrow(as.xts(bi_tlr)["2006-01-01/2015-08-01"])
t_est <- T - t_bt

spec_nig = ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1,1)),
mean.model = list(armaOrder = c(0,0), include.mean = FALSE), distribution.model = "nig")

bi.backtest.nig = ugarchroll(spec_nig, data = bi_tlr, n.ahead = 1, forecast.length = 10, refit.every = 1, refit.window = "moving", solver = "hybrid", fit.control = list(), solver.control = ctrl, calculate.VaR = TRUE, VaR.alpha = c(0.01,0.05), cluster = cl,keep.coef = TRUE)

Reply | Threaded
Open this post in threaded view
|

Re: VaR calculation warning with rugarch

alexios
You can ignore the warning. You can calculate the values yourself and
check that the results are the same:

df = as.data.frame(bi.backtest.nig)

q = quantile(bi.backtest.nig,0.01)
q10 =
qdist("nig",0.01,mu=0,sigma=df[10,"Sigma"],skew=df[10,"Skew"],shape=df[10,"Shape"])
as.numeric(q[10])==q10
 > TRUE
q5 =
qdist("nig",0.01,mu=0,sigma=df[5,"Sigma"],skew=df[5,"Skew"],shape=df[5,"Shape"])
as.numeric(q[5])==q5
 > TRUE

The warning will be fixed in the development version (...soon).

Alexios

On 16/08/2015 17:55, Mingersming wrote:

> Hi all,
>
> there is one issue I can´t go one myself. I try to fit a nig-distribution in
> a rolling window method to a time-series with the fantastic rugarch package.
> I use the option 'calculate.VaR' for several other distributions and it
> works fine, but if I switch to the nig-distribution, I recieve the following
> warning:
>
> In ans[i] = mu[i] + sigma[i] * .qsnigC(p, rho = skew[i],  ... :number of
> items to replace is not a multiple of replacement length
>
> I tried to turn off the option and calculate the quantile on my own. I think
> there is an misstake with the number of the parameters, but what can I
> change to get over?
>
> For code, see below
>
> Best regards
>
> library(quantmod)
> library(rugarch)
> library(PerformanceAnalytics)
>
> bi <- getSymbols('^GDAXI', from = "2004-01-01", to = "2015-08-01")
> bi <- Ad(get(bi[1]))
> bi_tlr <- Return.calculate(bi, method = "log")
> bi_tlr <- na.omit(bi_tlr)
>
> ctrl = list(rho = 1, delta = 1e-11, outer.iter = 1000, tol = 1e-12)
> cl = makePSOCKcluster(10)
>
> T = nrow(bi_tlr)
> t_bt <- nrow(as.xts(bi_tlr)["2006-01-01/2015-08-01"])
> t_est <- T - t_bt
>
> spec_nig = ugarchspec(variance.model = list(model = "sGARCH", garchOrder =
> c(1,1)),
> mean.model = list(armaOrder = c(0,0), include.mean = FALSE),
> distribution.model = "nig")
>
> bi.backtest.nig = ugarchroll(spec_nig, data = bi_tlr, n.ahead = 1,
> forecast.length = 10, refit.every = 1, refit.window = "moving", solver =
> "hybrid", fit.control = list(), solver.control = ctrl, calculate.VaR = TRUE,
> VaR.alpha = c(0.01,0.05), cluster = cl,keep.coef = TRUE)
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/VaR-calculation-warning-with-rugarch-tp4711164.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> [hidden email] 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.
>

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: VaR calculation warning with rugarch

Mingersming
This post was updated on .
Okay, I thought there was a generally mistake by myself. Because I saw the same warnings with my quantil approach. But now it´s clear, after I saw the same warnings with your code.
I was confused about the running time compared to the "easier" distributions, and thought the calculation was stucked. I saw the CPU-usage running down after a few minutes. So, i suggested the tasks run into a overflow or something like that.
For my clarity: the solver extract firstly the model parameters (with 100 percent CPU-usage) and calculate afterwards the quantile?

After some benchmarking I think the "nig" model takes 9x of the time it does take to fit the "norm" model.

Thank you, for your quick response!

Best Regards
Mingersming