Diagnosing an ROI Rebalancing Optimization Error in PortfolioAnalytics
Summary
The document concerns an error encountered when running a rebalancing optimization in R’s PortfolioAnalytics package. The example uses monthly return data, long-only, full-investment, and box constraints, with risk and return objectives. A non-rebalancing optimization using ROI succeeds, while the corresponding rebalancing call returns an error while extracting objective measures. The answer attributes the problem to breaking changes in version 0.2 of the ROI packages.
As a temporary workaround for the package state described in the discussion, the answer suggests downgrading ROI and its plugins to earlier versions. It also proposes using another optimization method, such as random search or differential evolution, instead of ROI. This is troubleshooting guidance tied to historical package versions, not a general portfolio construction method. The document provides no confirmation that either workaround resolved the original user’s setup, and its version-specific advice may not apply to current software.
Key ideas
- The reported failure occurs in a rebalancing optimization call using ROI.
- The example’s non-rebalancing optimization succeeds with the same portfolio specification.
- The accepted answer links the error to breaking changes in ROI package versions.
- Suggested workarounds are downgrading ROI components or changing the optimization method.
- The advice is specific to the package versions discussed and is not verified for current releases.
Tags
Full text
# PortfolioAnalytics [R] - optimize.portfolio.rebalancing error
# PortfolioAnalytics [R] - optimize.portfolio.rebalancing error
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
```
EDIT
Also, I'm running Windows 10 and thought it would be helpful to include a list of my currently installed packages:
https://docs.google.com/spreadsheets/d/1JLauyCpmDg3DOztRJKntoZ2LFMxV4_ouLOKYUVenEAA/edit?usp=sharing
## Answer by RossB (score 0, accepted)
https://quant.stackexchange.com/a/31860
The 0.2 versions of the ROI packages made breaking changes. We're working on a fix. In the meantime, I would suggest downgrading to ROI v0.1-0 and and ROI.plugin.* to 0.0-2.
You could also run the optimization with a different optimization method, e.g. `optimize_method = "random"` or `optimize_method = "DEoptim"`.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.