Reputation: 113
I am trying to optimize the edhec data with the following code, but getting only NAs as optimized weights
library(openxlsx)
library(PortfolioAnalytics)
library(PerformanceAnalytics)
library(plyr)
library(dplyr)
library(reshape2)
library(ROI)
library(ggplot2)
library(plotly)
library(car)
library(quantmod)
library(quadprog)
library(ROI.plugin.symphony)
require(ROI.plugin.glpk)
require(ROI.plugin.quadprog)
library(ROI.plugin.lpsolve)
library(Rglpk)
library(DEoptim)
library(fGarch)
library(pso)
library(GenSA)
library(nloptr)
data(edhec)
returns <- edhec[, 1:4]
colnames(returns) <- c("CA", "CTAG", "DS", "EM")
funds <- colnames(returns)
portf_maxret <- portfolio.spec(assets=funds)
portf_maxret <- add.constraint(portfolio=portf_maxret, type="return", return_target=.0075)
portf_maxret<-add.objective(portfolio=portf_maxret, type="risk", name="StdDev")
opt_maxret <- optimize.portfolio(R=returns, portfolio=portf_maxret,optimize_method="ROI", trace=TRUE)
The output of opt_maxret is
***********************************
PortfolioAnalytics Optimization
***********************************
Call:
optimize.portfolio(R = returns, portfolio = portf_maxret, optimize_method = "ROI",
trace = TRUE)
Optimal Weights:
CA CTAG DS EM
NA NA NA NA
Objective Measure:
StdDev
NA
The same is happening with any data and happening only if I am trying to set type="risk"
in optimize.portfolio
i.e. trying to optimize the portfolio according to the risk associated with it.
Upvotes: 1
Views: 555
Reputation: 21
The propblem may be caused when you try to give the same name to your portfolios in the line:
portf_maxret<-add.objective(portfolio=portf_maxret, type="risk", name="StdDev")
Try to change portf_maxret
into something else and use that as your portfolio name in optimization
Upvotes: 1