0

当我使用投资组合分析包的 ROI 求解器时,我收到此错误...ROI 仅求解均值、var/StdDev、HHI。但我给它的目标是 stdDev 。一些遇到相同问题的人谈到使用插件库(ROI.plugin.quadprog)库(ROI.plugin.glpk)。但这并不能解决我的问题。我做错了什么?

library(quantmod)
library(PerformanceAnalytics)
library(PortfolioAnalytics)
library(ROI)
library(ROI.plugin.quadprog)
library(ROI.plugin.glpk)


tickers <- c("CCL", "KIE", "KRE", "GRMN", "LOGI", "BAR")

portfolioprices <- NULL
for(ticker in tickers) {portfolioprices <-cbind(portfolioprices,getSymbols.yahoo(ticker , from = "2007-01-01" , periodicity = "daily", auto.assign = F))}

portfolioreturns <-na.omit(ROC(portfolioprices))

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

portf <-add.constraint(portf, type="weight_sum", min_sum=0.99 , max_sum=1.01)
portf <-add.constraint(portf , type="box" , min=.05, max=.40)
portf <-add.objective(portf , type="return" , name="mean")
portf <-add.objective(portf , type="risk" , name="stdDev")

optPort <-optimize.portfolio(portfolioreturns,portf , optimize_method = "ROI" , trace= TRUE)

chart.Weights(optPort)



ef <- extractEfficientFrontier(optPort, match.col = "StdDev" , n.portfolio =25 ,risk_aversion = NULL) 



chart.EfficientFrontier(ef, match.col = "StdDev" , n.portfolio =25 ,risk_aversion = NULL, 
                        xlim = NULL , ylim = NULL , cex.axis = 0.8, element.color = "darkgray" , main = "Efficient Frontier" , RAR.text = "SR" , rf =0, tangent.line = TRUE , cex.legend =0.8 , chart.assets =TRUE , labels.assets =TRUE , pch.assets = 21, cex.assets = 0.8)
4

0 回答 0