New to using PortfolioAnalytics (and fairly new to R in general) and am encountering an error when running
optimize.portfolio.rebalance -- see below:
Error in UseMethod("extractObjectiveMeasures") : no applicable method for 'extractObjectiveMeasures' applied to an object of class "c('simpleError', 'error', 'condition')"
I've looked at the vignette and package documentation on CRAN, but haven't been able to figure out what might be causing this specific problem.
optimize.portfolio seems to work fine with the same constraints and objectives. Perhaps I haven't loaded all of the required libraries? Open to any other suggestions. Thank you.
# Load packages library(xts) library(ROI) library(doParallel) library(PortfolioAnalytics) # Define pseudo dates and returns (format as xts) dates <- seq(from = as.Date("2016-01-01"), to = as.Date("2016-12-01"), by = "month") returns <- as.xts(data.frame("A" = runif(12, -.05, .05), "B" = runif(12, -.10, .20), "C" = runif(12, -.15, .30)), order.by = dates) # Register doParalell session (PortfolioAnalytics suggests this when running optimizations w/ rebals) registerDoParallel(cores = 2) # Initiate portfolio object port <- portfolio.spec(assets = colnames(returns)) # Add constraints port <- add.constraint(portfolio = port, type = "long_only") port <- add.constraint(portfolio = port, type = "full_investment") port <- add.constraint(portfolio = port, type = "box", min = 0.02, max = 0.40) # Add objectives - want to maximize Sharpe Ratio port <- add.objective(portfolio = port, type = "risk", name = "StdDev") port <- add.objective(portfolio = port, type = "return", name = "mean") # Run optimization WITHOUT rebalancing - THIS SEEMS TO RUN FINE... portOPT <- optimize.portfolio(R = returns, portfolio = port, optimize_method = "ROI", maxSR = TRUE) portOPT # Run optimization with rebalancing portOPT.R <- optimize.portfolio.rebalancing(R = returns, portfolio = port, optimize_method = "ROI", maxSR = TRUE, training_period = 6, rebalance_on = "months") portOPT.R
Also, I'm running Windows 10 and thought it would be helpful to include a list of my currently installed packages: