R:使用ROI包
我正在尝试使用 R 包 ROI 来解决简单的投资组合优化问题。
我可以使用 Quadprog 求解器“手动”获得结果,但我真的很想了解 ROI 包的工作原理。
不幸的是,我遇到了错误,尽管我坚持使用 Stefan Theussl 在 http://statmath.wu.ac.at/courses/optimization/Presentations/ROI-2011.pdf(幻灯片26,27)
这里是代码:
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")
我收到的错误消息是:
(dir == "<=") | 中出现错误(dir = q = "<") : 可以进行操作 仅适用于数字、逻辑或复杂类型
感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,ROIquadprog 插件中存在一个错误,该错误已被开发人员修复。
It turns out that there was a bug in the ROI quadprog plugin which has been fixed by the developer.