计算投资组合中的最佳权重

时间:2020-04-21 08:10:54

标签: r optimization na portfolio r-portfolioanalytics

我想计算给定投资组合的最优权重,我使用ROI优化方法,但最优权重的结果为NA,即使我已将求解器更改为random和genSA,但仍返回NA 我该如何解决这个问题?

tickers2 <- c("FB","AAPL","AMZN","NFLX","GOOGL","SQ","NVDA")
portfolioprices2 <- NULL
for(ticker in tickers2){
 portfolioprices2 <- cbind(portfolioprices2,
                           getSymbols.yahoo(ticker,from='2016-01-03',periodicity = 'daily',auto.assign=FALSE)[,6])
}
portfolioReturns2 <- na.omit(ROC(portfolioprices2))

portf <- portfolio.spec(colnames(portfolioReturns2))
portf

portf <- add.constraint(portf, type="weightt_sum",min_sum=1, max_sum=1)
portf <- add.constraint(portf, type = "box",min=10, max=40)
portf <- add.objective(portf, type = "return",name="mean")
portf <- add.objective(portf, type = "risk", name = "StdDev")

optport <- optimize.portfolio(portfolioReturns2,portf,optimize_method = "ROI",trace = TRUE) # roi is the solver for calculating weights
print(optport)

0 个答案:

没有答案