I am currently playing around with PortfolioAnalytics package in R and some data and I am aiming to create different portfolios with different VaR. However, I am struggling first of all, add.objective() is not taking VaR as a risk measure - it does work with "ES".
I am unsure if I am misunderstanding something, but if I want to allow for more risk in the risk objective I assumed that i can just set a higher p (eg p=0.2 instead of p=0.05) - below some code for clarification:
#test data(edhec) returns <- edhec[, 1:4] colnames(returns) <- c("CA", "CTAG", "DS", "EM") fund.names <- colnames(returns) pfx <- portfolio.spec(assets=fund.names) pfx <- add.constraint(portfolio=pfx, type="full_investment") pfx <- add.constraint(portfolio=pfx, type="long_only") pfx <- add.constraint(portfolio=pfx, type="box", min=0.0, max=0.6) pfx <- add.objective(portfolio=pfx, type="return", name="mean", return_target= 0.05) **pfx <- add.objective(portfolio=pfx, type='risk', name='ES', arguments= list(p=0.05))** bt_pfx <- optimize.portfolio.rebalancing(R=returns, portfolio= pfx , optimize_method="ROI", rebalance_on="years", trace= TRUE, training_period= NULL, rolling_window = NULL) chart.Weights(bt_pfx, ylim=c(0, 1),col = rainbow12equal, main="PFX Weights") write.csv(extractObjectiveMeasures(bt_pfx))
Furthermore with a higher p I assumed that the returns should be higher as well, however the opposite is the case.
So I am not sure if I am misunderstanding something or is there an other option to allow for more risk in a portfolio?