[R-SIG-Finance] R-SIG-Finance Digest, Vol 108, Issue 12

alexios ghalanos alexios at 4dscape.com
Tue May 14 19:35:01 CEST 2013


1. You may have encountered an error in the intergation (you should use 
"try-catch", and option stop.on.error in integrate set to FALSE..after 
which you would check for any NA's etc)...but send the code so that we 
may see. Did you set the length (N) of "ES" to the same length as your 
conditional forecasts?

2. NO. ONE SIDED test. When uncertain about something, either read up on 
the original reference or try for yourself:

e.g.
t.test(rnorm(1000, mean=0.1, sd=0.02), alternative="greater")
t.test(rnorm(1000), alternative="greater")


Regards,
-Alexios

On 14/05/2013 17:53, Alexandra Allexa wrote:
> Hi again,
>
>
>
> I run the code wrote by Alexios and I have this error messege:
> 'Error in integrate(f, 0, 0.05, mu = mu[i], sigma = sigma[i], shape = shape[i],  :
>    evaluation of function gave a result of wrong length"
>
> I tried to figure out but I didn't find any solution. May you help me with this?
>
> Also, I tried the ESTest for 2 different series. One series proposed in the vignette of the test and my series and I got 2 antagonist results.
>
> For dji30ret i have the following output:
> $expected.exceed
> [1] 75
>
> $actual.exceed
> [1] 74
>
> $H1
> [1] "Mean of Excess Violations of VaR is greater than zero"
>
> $boot.p.value
> [1] 0.9663557
>
> $p.value
> [1] 0.9655261
>
> $Decision
> [1] "Fail to Reject H0"
>
>
> For my series I have:
> $expected.exceed
> [1] 80
>
> $actual.exceed
> [1] 87
>
> $H1
> [1] "Mean of Excess Violations of VaR is greater than zero"
>
> $boot.p.value
> [1] 0.06042038
>
> $p.value
> [1] 0.05122453
>
> $Decision
> [1] "Fail to Reject H0"
>
> What seems to me bizarre is the fact that for my series the $p.value and $boot.p.value are under 10% and for dji30ret I have this propabilites are approx. 95% and for the both cases I got the same Decision.
>
> In the vignette is mentioned that ESTet is  sided t-test, since I remember (I'm not sure) for this types of tests, Ho is accepted for a p value lower or equal to the  threshold of 1%/5%/10%. Why I have this extrange results?
>
> Thank you!
>
> Alexandra
>
>
>
>
>
>
> From: "r-sig-finance-request at r-project.org" <r-sig-finance-request at r-project.org>
> To: r-sig-finance at r-project.org
> Sent: Monday, May 13, 2013 1:00 PM
> Subject: R-SIG-Finance Digest, Vol 108, Issue 12
>
>
> Send R-SIG-Finance mailing list submissions to
>      r-sig-finance at r-project.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>      https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> or, via email, send a message with subject or body 'help' to
>      r-sig-finance-request at r-project.org
>
> You can reach the person managing the list at
>      r-sig-finance-owner at r-project.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of R-SIG-Finance digest..."
>
>
> Today's Topics:
>
>     1. CVaR with NIG- GARCH(1,1) (Alexandra Allexa)
>     2. Re: CVaR with NIG- GARCH(1,1) (Brian G. Peterson)
>     3. Re: CVaR with NIG- GARCH(1,1) (alexios ghalanos)
>     4. Re: CVaR with NIG- GARCH(1,1) (alexios ghalanos)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sun, 12 May 2013 15:20:34 -0700 (PDT)
>
> To: "r-sig-finance at r-project.org" <r-sig-finance at r-project.org>
> Subject: [R-SIG-Finance] CVaR with NIG- GARCH(1,1)
> Message-ID:
>      <1368397234.30486.YahooMailNeo at web122406.mail.ne1.yahoo.com>
> Content-Type: text/plain
>
>
>
> Hello,
>
> My name is Alexandra and I have a very tight deadline for my MSc dissertation. My intention is to do a CVaR/ES using a NIG_GARCH model for estimating the volatility.
>
> With the Alexios's help I did a part of the following code (Thank you very much for your help, Alexios Ghalanos!):
>
> library(timeSeries)
> library(timeDate)
> library(Rcpp)
> library(RcppArmadillo)
> library(parallel)
> library(chron)
> library(Rsolnp)
> library(truncnorm)
> library(rugarch)
> library(fGarch)
> library(timeDate)
> library(PerformanceAnalytics)
> library(AER)
> library(fGarch)
>
> eur_all=timeSeries(eur_2001)
> r_eur1=getReturns(eur_all)
> rand_eur1=r_eur1*100
>
> #-NIG_GARCH
>
> #I. Specification Model and Fitting
>
> spec1 = ugarchspec(variance.model = list(model = 'sGARCH',
>                                           garchOrder = c(1,1)), mean.model =
>                       list(armaOrder = c(1,1), include.mean = TRUE),
>                     distribution.model = "nig")
>
>
>
> #Fit the model
>
>
> tmp = ugarchroll(spec1, rand_eur1, forecast.length = 1500, refit.every = 50,
>                   refit.window = 'moving', windows.size = 1500, solver ='hybrid',
>                   calculate.VaR = TRUE,VaR.alpha = c(0.01, 0.025, 0.05), keep.coef = TRUE)
>
> if (!is.null(tmp at model$noncidx)) {
>
>    tmp = resume(tmp, solver = "solnp", fit.control = list(scale = 1), solver.control = list(tol = 1e-07,
>                                                                                             delta = 1e-06))
>
>    if (!is.null(tmp at model$noncidx))
>
>      fitlist1 = NA
> } else {
>
>    fitlist1 = as.data.frame(tmp, which = 'density')
>
>
> }
>
>
> # Defining NIG distribution
>
> mu=fitlist1[, 'Mu']
> sigma=fitlist1[, 'Sigma']
> shape=fitlist1[, 'Shape']
> skew=fitlist1[, 'Skew']
> lambda =fitlist1[, 'Shape.GIG']
>
> dist=ddist(distribution = "nig", y, mu = mu, sigma = sigma, lambda = lambda, skew = skew,
>             shape = shape)
> pd=pdist(distribution = "nig", q, mu = mu, sigma = sigma, lambda = lambda, skew = skew,
>           shape = shape)
> qst=qdist(distribution = "nig", p, mu = mu, sigma = sigma, lambda = lambda, skew = skew,
>            shape = shape)
> r=rdist(distribution = "nig", n, mu = mu, sigma = sigma, lambda = lambda, skew = skew,
>          shape = shape)
> fitdist(distribution = "nig", fitlist1, control=list())
>
> distplot(distribution = "snig", skewbounds = NULL, shapebounds = NULL,
>           n.points = NULL)
>
> #CVaR/ES
>
> EURLOSS <- timeSeries(-1.0*rand_eur1,
>                        char.vec = time(eur_all))
>
> ESgarch <- function(rand_eur1, p = 0.99){
>    sigma <-fitlist1[, 'Sigma']
>    df <- fitlist1[,"Shape"]
>    ES <- sigma * (dist(qst(p, df), df)/(1 - p)) *
>      ((df + (qst(p, df))^2)/(df - 1))
>    return(ES)
> }
>
>
> from <- time(EURLOSS)[-c((nrow(EURLOSS) - 999) : nrow(EURLOSS))]
> to <- time(EURLOSS)[-c(1:1000)]
> EURSEES <- fapply(EURLOSS, from = from, to = to, FUN = ESgarch)
> EURSEESL1 <- lag(EURSEES, k = 1)
> res <- na.omit(cbind(EURSELOSS, EURSEESL1))
> colnames(res) <- c("EURSELOSS", "ES99")
> plot(res[, 2], col = "red", ylim = range(res),
>       main = "EUR: NIG-GARCH(1,1) ES 99%",
>       ylab = "percentages", xlab = "")
> points(res[, 1], type = "p", cex = 0.2, pch = 19, col = "blue")
> legend("topleft", legend = c("Loss", "ES"),
>         col = c("blue", "pink"), lty = c(NA, 1), pch = c(19, NA))
>
>
>
> My problem is how to define the NIG distribution for such a model?
> How I set the parameters/ vectors: y,p,q and n?
>
> In this situation, it is possible to use the function CVaR or ETL provided by the package {PerformanceAnalytics}? How?
>
> I can applied the same principle used in computing CVaR for CDD/CDaR?
>
> Thank you in advance,
>
> Alexandra Rautoiu
>      [[alternative HTML version deleted]]
>
>
>
> ------------------------------
>
> Message: 2
> Date: Sun, 12 May 2013 17:43:23 -0500
> From: "Brian G. Peterson" <brian at braverock.com>
> To: r-sig-finance at r-project.org
> Subject: Re: [R-SIG-Finance] CVaR with NIG- GARCH(1,1)
> Message-ID: <51901B0B.5010200 at braverock.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 05/12/2013 05:20 PM, Alexandra Allexa wrote:
>> My problem is how to define the NIG distribution for such a model?
>> How I set the parameters/ vectors: y,p,q and n?
>>
>> In this situation, it is possible to use the function CVaR or ETL
>> provided by the package {PerformanceAnalytics}? How?
>>
>> I can applied the same principle used in computing CVaR for
>> CDD/CDaR?
>>
>> Thank you in advance,
>>
>> Alexandra Rautoiu
>
> CVaR/ETL in PerformanceAnalytics don't have NIG distribution options.
>
> I'm not sure if the NIG distribution has p,d,q,r functions as is common
> in R for discrete distributions.
>
> If you have the q(uantile) function, you should be able to adapt the
> code from PerformanceAnalytics with relative ease, since it is only
> required to know the quantile, and then integrate over the tail, to
> compute the CVaR for a continuous distribution.
>
> Regards,
>
> Brian
>
>
>
>
> _______________________________________________
> R-SIG-Finance at 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.
>



More information about the R-SIG-Finance mailing list