I'm trying to run portfolio optimization problems, everything runs smoothly, except when I try to create the efficient frontier.
I've tried to mess around with all the function parameters, I've installed all packages and plugins recommended by the documentation. But even when I try to run the code in the efficient frontier demo in the package's GitHub repository I get the same error message. I suspect it is a missing plugin or an error in the recommended packages installation. Can someone at least give me a hint on whats going on?
The code I have is pretty simple, but my main conclusion is that I don't have any problems in it since I get the same error while running the code located in: https://github.com/R-Finance/PortfolioAnalytics/blob/master/demo/demo_efficient_frontier.R
my code:
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)
th error message I get is:
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))
Any help would be much appreciated! Thank you!