GeoBosh/cvar

ES: level ignored for numeric input

mariusbommert opened this issue · 1 comments

In the ES function, the level x seems to be ignored for numeric inputs. In the following example both levels of x lead to the same results:

library(cvar)
ES(1:100, x = 0.05) 
# -3
ES(1:100, x = 0.01)
# -3

It seems necessary to update the following part of the function:

if (is.numeric(dist)) {
  v <- VaR.numeric(dist, x = 0.05, ..., intercept = intercept, 
                   slope = slope)
  bad <- dist[dist <= -v]
  res <- -mean(bad)
  return(res)
}

Here x = x is required instead of x = 0.05:

if (is.numeric(dist)) {
  v <- VaR.numeric(dist, x = x, ..., intercept = intercept, 
                   slope = slope)
  bad <- dist[dist <= -v]
  res <- -mean(bad)
  return(res)
}

Thanks for the detailed report and the fix. I have implemented it and will submit v0.4.1 to CRAN shortly.