R: use of ROI package

3k views Asked by At

I am trying to use the R package ROI for a simple portfolio optimization problem.
I can get the results using the quadprog solver "manually", but I'd really like to understand how the ROI package works.
Unfortunately I run into an error, even though I am sticking to the provided example by Stefan Theussl at http://statmath.wu.ac.at/courses/optimization/Presentations/ROI-2011.pdf (slide 26,27)

Here is the code:

library(fPortfolio)  
library(ROI)

data(LPP2005.RET)  
lppData <- 100 * LPP2005.RET[, 1:6]
r <- mean(lppData)  
foo <- Q_objective(Q = cov(lppData), L = rep(0, ncol(lppData)))  
full_invest <- L_constraint(rep(1, ncol(lppData)), "==", 1)  
target_return <- L_constraint(apply(lppData, 2, mean), "==",r)
op <- OP(objective = foo, constraints = rbind(full_invest, target_return))   
sol <- ROI_solve(op, solver = "quadprog")

The error message I get is:

Error in (dir == "<=") | (dir = q = "<") : operations are possible only for numeric, logical or complex types

Thanks for your help!

1

There are 1 answers

1
bigsleep On BEST ANSWER

It turns out that there was a bug in the ROI quadprog plugin which has been fixed by the developer.