I have been looking at
CVaR function in the
PerformanceAnalytics package as an option to use in portfolio optimization. However, I cannot figure out the reason behind discrepancy that the function is giving for my test portfolio.
Here is a reproducable example:
library(PerformanceAnalytics) set.seed(1234) a = rnorm(n = 10, mean = 0, sd = 0.02) b = rnorm(n = 10, mean = 0, sd = 0.03) wght = c(0.4, 0.6) ## assign weights dt = cbind(a, b) startDate = as.Date("2016-01-01") h = seq(1:10) myDates = startDate + h dt = as.data.frame(dt) ## dataframe of single assets rownames(dt) = myDates tmp = sweep(dt, 2, wght, `*`) P = as.data.frame(rowSums(tmp)) ## resultant portfolio colnames(P) = "Portfolio"
My issue arises here:
MES1 = ES(dt, p = 0.95, method = "modified", portfolio_method = "component", weights = wght) MES1$MES MES2 = ES(P, p = 0.95, method = "modified", portfolio_method = "component", weights = 1) MES2$MES
I get the same results of
CVaR for the portfolio in both cases. However, when I do not mention
portfolio_method = "component" and
weights = 1 should I not get the same result?
ES(P, p = 0.95, method = "modified")
Here the function returns completely different result. I am currently inspecting the code on the authors' page, but would also like to know the views of those who went through this.