1
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Tried running your code. Getting a strange error related to ROI package... $\endgroup$ – AK88 Jan 4 '17 at 15:34
  • $\begingroup$ Thanks. Neglected to load the ROI package--it is loaded now in the post. Should correctly display the error I referenced now. $\endgroup$ – jtryker Jan 4 '17 at 20:44
0
$\begingroup$

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".

$\endgroup$
  • $\begingroup$ Thanks RossB. Reverting to the older versions of ROI and its plugins seemed to solve the issue. Thanks again. $\endgroup$ – jtryker Jan 10 '17 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.