我试图从网站上复制代码以测试R中的Portfolio Analytics库。但是我收到错误而且我不知道为什么。我得到的错误是:错误:"包:投资回报率" %search in(%||) requireNamespace(" ROI",quietly = TRUE)不为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)