Error when trying to optimize with Portfolio Analytics

拟墨画扇 提交于 2019-12-11 17:11:38

问题


I'm trying to copy the code from a website to test Portfolio Analytics library in R. But I getting an error and I don't have a clue why. The error I am getting is: Error: "package:ROI" %in% search() || requireNamespace("ROI", quietly = TRUE) is not TRUE

library(PortfolioAnalytics)

data(edhec)
returns <- edhec[, 1:6]
funds <- colnames(returns)

init.portfolio <- portfolio.spec(assets = funds)

init.portfolio <- add.constraint(portfolio = init.portfolio, 
                                 type = "full_investment")

init.portfolio <- add.constraint(portfolio = init.portfolio, 
                                 type = "long_only")

minSD.portfolio <- add.objective(portfolio=init.portfolio, 
                                 type="risk", 
                                 name="StdDev")

minSD.opt <- optimize.portfolio(R = returns, portfolio = minSD.portfolio, 
                                optimize_method = "ROI", trace = TRUE)

来源:https://stackoverflow.com/questions/45201485/error-when-trying-to-optimize-with-portfolio-analytics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!