I have spent multiple hours trying to understand what is required to successfully utilize the optimize.portfolio() function from the PortfolioAnalytics package, but I receive multiple errors, despite trying various optimize_methods (e.g., "DEoptim","ROI").
After installing PortfolioAnalytics, I attempted running optimize.portfolio() after specifying the portfolio constraints, but I received the following error:
Error: paste0("package:", plugin) %in% search() || requireNamespace(plugin, .... is not TRUE
Tried downloading "plugin", but I receive:
Warning in install.packages : package ‘plugin’ is not available (for R version 3.3.1)
My preferred optimize_method is "ROI," and I have installed the "ROI" package yet I still receive the error requiring "plugin."
I tried working around this issue by manually installing "DEoptim," but I am still not successfully able to run optimize.portfolio():
pspec <- portfolio.spec(assets=names(fxreturns))
pspec <- add.constraint(pspec,type = "diversification", div_target = 0.5)
pspec <- add.constraint(pspec,type = "return",return_target=0.05)
pspec <- add.constraint(pspec,type = "leverage")
optimize.portfolio(fxreturns,portfolio = pspec,optimize_method = "DEoptim")
Despite downloading multiple packages (why wouldn't R automatically install the required packages when I first installed "PortfolioAnalytics"?), I receive the following error when I run "DEoptim":
Error in seq.default(from = round(min, rounding), to = round(max, rounding), : 'from' cannot be NA, NaN or infinite
For reference, here are all of the packages I have loaded:
library(quantmod)
library(tseries)
library(PerformanceAnalytics)
library(PortfolioAnalytics)
library(xts)
library(timeSeries)
library(TTR)
require(Rblpapi)
require(reshape2)
require(xlsx)
require(Hmisc)
require(ROI)
require(data.table)
require(DEoptim)
I had the same problem, went to the PortfolioAnalytics cran page and installed all of their suggests:
Not sure sure which one did the trick but I suspect it's the ROI plugin packages.