我正在尝试解决投资组合优化问题,一切都运行顺利,除非我尝试创建有效边界。
我试图弄乱所有的函数参数,我已经安装了文档推荐的所有包和插件。但即使我尝试在包的 GitHub 存储库中运行有效前沿演示中的代码时,我也会收到相同的错误消息。我怀疑它是缺少插件或推荐的软件包安装中的错误。有人至少可以给我一个关于发生了什么的提示吗?
我拥有的代码非常简单,但我的主要结论是我没有任何问题,因为我在运行位于以下位置的代码时遇到了同样的错误:https ://github.com/R-Finance/PortfolioAnalytics/ blob/master/demo/demo_efficient_frontier.R
我的代码:
base_pf <- portfolio.spec(colnames(monthly_returns_with_rf[,-selic_col]))
base_pf <- add.constraint(portfolio = base_pf, type = 'full_investment')
base_pf <- add.constraint(portfolio = base_pf, type = 'long_only')
moments <- set.portfolio.moments(monthly_returns_with_rf[,-selic_col], portfolio = base_pf, method = 'boudt', k = 3)
base_pf <- add.constraint(portfolio = base_pf, type = 'box', min = 0, max = 0.4)
base_pf <- add.objective(portfolio = base_pf, type = 'return', name = 'mean')
base_pf <- add.objective(portfolio = base_pf, type = 'risk', name = 'var')
ef_fr <- create.EfficientFrontier(R=monthly_returns_with_rf[,-selic_col], portfolio=base_pf, type="mean-StdDev", match.col = 'StdDev')
opt_base <- optimize.portfolio(monthly_returns_with_rf[,- selic_col], portfolio = base_pf, optimize_method = 'ROI')
print(opt_base)
我得到的错误信息是:
Error in maxret_opt(R = R, constraints = constraints, moments = moments, : paste0("package:", plugin) %in% search() || requireNamespace(plugin, .... is not TRUE
Traceback:
1. create.EfficientFrontier(R = monthly_returns_with_rf[, -selic_col],
. portfolio = base_pf, type = "mean-StdDev", match.col = "StdDev")
2. meanvar.efficient.frontier(portfolio = portfolio, R = R, n.portfolios = n.portfolios,
. risk_aversion = risk_aversion, ... = ...)
3. optimize.portfolio(R = R, portfolio = portfolio, optimize_method = "ROI",
. ... = ...)
4. maxret_opt(R = R, constraints = constraints, moments = moments,
. target = target, solver = solver, control = control)
5. stopifnot(paste0("package:", plugin) %in% search() ||
requireNamespace(plugin,
. quietly = TRUE))
任何帮助将非常感激!谢谢!