[Returnanalytics-commits] r3606 - in pkg/PortfolioAnalytics: . R inst/tests sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 4 03:26:31 CET 2015


Author: rossbennett34
Date: 2015-03-04 03:26:30 +0100 (Wed, 04 Mar 2015)
New Revision: 3606

Added:
   pkg/PortfolioAnalytics/sandbox/test_cplex_gmv.R
   pkg/PortfolioAnalytics/sandbox/test_cplex_maxMean.R
   pkg/PortfolioAnalytics/sandbox/test_cplex_minES.R
   pkg/PortfolioAnalytics/sandbox/test_cplex_qu.R
Removed:
   pkg/PortfolioAnalytics/inst/tests/test_cplex_gmv.R
   pkg/PortfolioAnalytics/inst/tests/test_cplex_maxMean.R
   pkg/PortfolioAnalytics/inst/tests/test_cplex_minES.R
   pkg/PortfolioAnalytics/inst/tests/test_cplex_qu.R
Modified:
   pkg/PortfolioAnalytics/DESCRIPTION
   pkg/PortfolioAnalytics/R/optimize.portfolio.R
Log:
removing support for ROI.plugin.cplex
moved test scripts that use ROI.plugin.cplex and Rcplex to sandbox

Modified: pkg/PortfolioAnalytics/DESCRIPTION
===================================================================
--- pkg/PortfolioAnalytics/DESCRIPTION	2015-02-24 01:37:13 UTC (rev 3605)
+++ pkg/PortfolioAnalytics/DESCRIPTION	2015-03-04 02:26:30 UTC (rev 3606)
@@ -11,7 +11,7 @@
   , person(given="Guy",family="Yollin",role="ctb")
   , person(given="R. Douglas",family="Martin",role="ctb")
   )
-Version: 0.9.3599
+Version: 0.9.3606
 Date: $Date$
 Maintainer: Brian G. Peterson <brian at braverock.com>
 Description: Portfolio optimization and analysis routines and graphics.
@@ -32,7 +32,6 @@
     ROI.plugin.glpk (>= 0.0.2),
     ROI.plugin.quadprog (>= 0.0.2),
     ROI.plugin.symphony (>= 0.0.2),
-    ROI.plugin.cplex (>= 0.0.2),
     pso,
     GenSA,
     corpcor,

Modified: pkg/PortfolioAnalytics/R/optimize.portfolio.R
===================================================================
--- pkg/PortfolioAnalytics/R/optimize.portfolio.R	2015-02-24 01:37:13 UTC (rev 3605)
+++ pkg/PortfolioAnalytics/R/optimize.portfolio.R	2015-03-04 02:26:30 UTC (rev 3606)
@@ -613,7 +613,7 @@
   .formals <- formals(momentFUN)
   .formals <- modify.args(formals=.formals, arglist=list(...), dots=TRUE)
   # ** pass ROI=TRUE to set.portfolio.moments so the moments are not calculated
-  if(optimize_method %in% c("ROI", "quadprog", "glpk", "symphony", "ipop", "cplex")){
+  if(optimize_method %in% c("ROI", "quadprog", "glpk", "symphony", "ipop")){
     obj_names <- unlist(lapply(portfolio$objectives, function(x) x$name))
     if(any(obj_names %in% c("CVaR", "ES", "ETL"))){
       .formals <- modify.args(formals=.formals, arglist=list(ROI=TRUE), dots=TRUE)
@@ -869,7 +869,7 @@
     
   } ## end case for random
   
-  roi_solvers <- c("ROI", "quadprog", "glpk", "symphony", "ipop", "cplex")
+  roi_solvers <- c("ROI", "quadprog", "glpk", "symphony", "ipop")
   if(optimize_method %in% roi_solvers){
     # check for a control argument for list of solver control arguments
     if(hasArg(control)) control=match.call(expand.dots=TRUE)$control else control=NULL

Deleted: pkg/PortfolioAnalytics/inst/tests/test_cplex_gmv.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_cplex_gmv.R	2015-02-24 01:37:13 UTC (rev 3605)
+++ pkg/PortfolioAnalytics/inst/tests/test_cplex_gmv.R	2015-03-04 02:26:30 UTC (rev 3606)
@@ -1,166 +0,0 @@
-library(PortfolioAnalytics)
-library(Rcplex)
-library(ROI)
-library(ROI.plugin.cplex)
-library(testthat)
-
-# Test that PortfolioAnalytics with ROI.plugin.cplex solutions equal Rcplex solutions
-context("GMV Portfolios: PortfolioAnalytics with ROI.plugin.cplex and Rcplex")
-
-# args(Rcplex)
-# ?Rcplex
-
-##### Data #####
-data(edhec)
-R <- edhec[, 1:5]
-funds <- colnames(R)
-m <- ncol(R)
-
-##### Parameters #####
-portf <- portfolio.spec(funds)
-portf <- add.constraint(portf, type="full_investment")
-portf <- add.constraint(portf, type="box", min=-Inf, max=Inf)
-portf <- add.objective(portf, type="risk", name="var")
-
-# Quadratic part of objective function
-objQ <- 2 * cov(R)
-
-# Linear part of objective function
-objL <- rep(0, m)
-
-# Constraints matrix
-Amat <- matrix(1, nrow=1, ncol=m)
-
-# right hand side of constraints
-rhs <- 1
-
-# direction of inequality of constraints
-dir <- "E"
-
-##### Unconstrained #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-lb <- rep(-Inf, m)
-ub <- rep(Inf, m)
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-test_that("Unconstrained: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt))
-})
-
-test_that("Unconstrained: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-##### Long Only #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-lb <- rep(0, m)
-ub <- rep(1, m)
-
-# Update box constraints in portfolio
-portf$constraints[[2]]$min <- lb
-portf$constraints[[2]]$max <- ub
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-test_that("Long Only: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt))
-})
-
-test_that("Long Only: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
-})
-
-test_that("Long Only: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
-})
-
-test_that("Long Only: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-##### Box #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-lb <- rep(0.05, m)
-ub <- rep(0.55, m)
-
-# Update box constraints in portfolio
-portf$constraints[[2]]$min <- lb
-portf$constraints[[2]]$max <- ub
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-
-test_that("Box: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt))
-})
-
-test_that("Box: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
-})
-
-test_that("Box: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
-})
-
-test_that("Box: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-##### Box with Shorting #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-lb <- rep(-0.05, m)
-ub <- rep(0.55, m)
-
-# Update box constraints in portfolio
-portf$constraints[[2]]$min <- lb
-portf$constraints[[2]]$max <- ub
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-
-test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt))
-})
-
-test_that("Box with Shorting: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
-})
-
-test_that("Box with Shorting: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
-})
-
-test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-Rcplex.close()

Deleted: pkg/PortfolioAnalytics/inst/tests/test_cplex_maxMean.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_cplex_maxMean.R	2015-02-24 01:37:13 UTC (rev 3605)
+++ pkg/PortfolioAnalytics/inst/tests/test_cplex_maxMean.R	2015-03-04 02:26:30 UTC (rev 3606)
@@ -1,140 +0,0 @@
-library(PortfolioAnalytics)
-library(Rcplex)
-library(ROI)
-library(ROI.plugin.cplex)
-library(testthat)
-
-# Test that ROI.plugin.cplex solutions equal Rcplex solutions
-context("Maximum Mean Return Portfolios: PortfolioAnalytics with ROI.plugin.cplex and Rcplex")
-
-# args(Rcplex)
-# ?Rcplex
-
-##### Data #####
-data(edhec)
-R <- edhec[, 1:5]
-funds <- colnames(R)
-m <- ncol(R)
-
-##### Parameters #####
-portf <- portfolio.spec(funds)
-portf <- add.constraint(portf, type="full_investment")
-portf <- add.constraint(portf, type="box", min=0, max=1)
-portf <- add.objective(portf, type="return", name="mean")
-
-# Quadratic part of objective function
-objQ <- NULL
-
-# Linear part of objective function
-objL <- -colMeans(R)
-
-# Constraints matrix
-Amat <- matrix(1, nrow=1, ncol=m)
-
-# right hand side of constraints
-rhs <- 1
-
-# direction of inequality of constraints
-dir <- "E"
-
-
-##### Long Only #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-lb <- rep(0, m)
-ub <- rep(1, m)
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-test_that("Long Only: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt))
-})
-
-test_that("Long Only: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
-})
-
-test_that("Long Only: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
-})
-
-test_that("Long Only: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-##### Box #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-lb <- rep(0.05, m)
-ub <- rep(0.55, m)
-
-# Update box constraints in portfolio
-portf$constraints[[2]]$min <- lb
-portf$constraints[[2]]$max <- ub
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-test_that("Box: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt))
-})
-
-test_that("Box: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
-})
-
-test_that("Box: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
-})
-
-test_that("Box: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-##### Box with Shorting #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-lb <- rep(-0.05, m)
-ub <- rep(0.55, m)
-
-# Update box constraints in portfolio
-portf$constraints[[2]]$min <- lb
-portf$constraints[[2]]$max <- ub
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt))
-})
-
-test_that("Box with Shorting: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
-})
-
-test_that("Box with Shorting: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
-})
-
-test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-Rcplex.close()
-

Deleted: pkg/PortfolioAnalytics/inst/tests/test_cplex_minES.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_cplex_minES.R	2015-02-24 01:37:13 UTC (rev 3605)
+++ pkg/PortfolioAnalytics/inst/tests/test_cplex_minES.R	2015-03-04 02:26:30 UTC (rev 3606)
@@ -1,184 +0,0 @@
-library(PortfolioAnalytics)
-library(Rcplex)
-library(ROI)
-library(ROI.plugin.cplex)
-library(testthat)
-
-# Test that ROI.plugin.cplex solutions equal Rcplex solutions
-context("Minimum ES Portfolios: PortfolioAnalytics with ROI.plugin.cplex and Rcplex")
-
-# args(Rcplex)
-# ?Rcplex
-
-##### Data #####
-data(edhec)
-R <- edhec[, 1:5]
-funds <- colnames(R)
-
-##### Parameters #####
-m <- ncol(R)
-n <- nrow(R)
-alpha <- 0.05
-
-portf <- portfolio.spec(funds)
-portf <- add.constraint(portf, type="full_investment")
-portf <- add.constraint(portf, type="box", min=-Inf, max=Inf)
-portf <- add.objective(portf, type="risk", name="ES", arguments=list(p=1-alpha))
-
-# Quadratic part of objective function
-objQ <- NULL
-
-# Linear part of objective function
-objL <- c(rep(0, m), rep(1 / (alpha * n), n), 1)
-
-# Constraints matrix
-Amat <- cbind(rbind(1, zoo::coredata(R)), 
-              rbind(0, cbind(diag(n), 1)))
-
-# right hand side of constraints
-rhs <- c(1, rep(0, n))
-
-# direction of inequality of constraints
-dir <- c("E", rep("G", n))
-
-##### Unconstrained #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-min_box <- rep(-Inf, m)
-max_box <- rep(Inf, m)
-
-lb <- c(min_box, rep(0, n), -1)
-ub <- c(max_box, rep(Inf, n), 1)
-
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-
-test_that("Unconstrained: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt[1:m]))
-})
-
-test_that("Unconstrained: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-
-##### Long Only #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-min_box <- rep(0, m)
-max_box <- rep(1, m)
-
-lb <- c(min_box, rep(0, n), -1)
-ub <- c(max_box, rep(Inf, n), 1)
-
-# Update box constraints in portfolio
-portf$constraints[[2]]$min <- min_box
-portf$constraints[[2]]$max <- max_box
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-test_that("Long Only: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt[1:m]))
-})
-
-test_that("Long Only: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= min_box) & all(weights <= max_box), is_true())
-})
-
-test_that("Long Only: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt[1:m] >= min_box) & all(opt.rcplex$xopt[1:m] <= max_box), is_true())
-})
-
-test_that("Long Only: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-##### Box #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-min_box <- rep(0.05, m)
-max_box <- rep(0.55, m)
-
-lb <- c(min_box, rep(0, n), -1)
-ub <- c(max_box, rep(Inf, n), 1)
-
-# Update box constraints in portfolio
-portf$constraints[[2]]$min <- min_box
-portf$constraints[[2]]$max <- max_box
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-test_that("Box: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt[1:m]))
-})
-
-test_that("Box: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= min_box) & all(weights <= max_box), is_true())
-})
-
-test_that("Box: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt[1:m] >= min_box) & all(opt.rcplex$xopt[1:m] <= max_box), is_true())
-})
-
-test_that("Box: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-##### Box with Shorting #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-min_box <- rep(-0.05, m)
-max_box <- rep(0.55, m)
-
-lb <- c(min_box, rep(0, n), -1)
-ub <- c(max_box, rep(Inf, n), 1)
-
-# Update box constraints in portfolio
-portf$constraints[[2]]$min <- min_box
-portf$constraints[[2]]$max <- max_box
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt[1:m]))
-})
-
-test_that("Box with Shorting: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= min_box) & all(weights <= max_box), is_true())
-})
-
-test_that("Box with Shorting: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt[1:m] >= min_box) & all(opt.rcplex$xopt[1:m] <= max_box), is_true())
-})
-
-test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-Rcplex.close()
-

Deleted: pkg/PortfolioAnalytics/inst/tests/test_cplex_qu.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_cplex_qu.R	2015-02-24 01:37:13 UTC (rev 3605)
+++ pkg/PortfolioAnalytics/inst/tests/test_cplex_qu.R	2015-03-04 02:26:30 UTC (rev 3606)
@@ -1,171 +0,0 @@
-library(PortfolioAnalytics)
-library(Rcplex)
-library(ROI)
-library(ROI.plugin.cplex)
-library(testthat)
-
-# Test that PortfolioAnalytics with ROI.plugin.cplex solutions equal Rcplex solutions
-context("Maximum Quadratic Utility Portfolios: PortfolioAnalytics with ROI.plugin.cplex and Rcplex")
-
-# args(Rcplex)
-# ?Rcplex
-
-##### Data #####
-data(edhec)
-R <- edhec[, 1:5]
-funds <- colnames(R)
-m <- ncol(R)
-
-##### Parameters #####
-
-# risk aversion parameter
-lambda <- 1
-
-portf <- portfolio.spec(funds)
-portf <- add.constraint(portf, type="full_investment")
-portf <- add.constraint(portf, type="box", min=-Inf, max=Inf)
-portf <- add.objective(portf, type="risk", name="var", risk_aversion=lambda)
-portf <- add.objective(portf, type="return", name="mean")
-
-# Quadratic part of objective function
-objQ <- lambda * 2 * cov(R)
-
-# Linear part of objective function
-objL <- -colMeans(R)
-
-# Constraints matrix
-Amat <- matrix(1, nrow=1, ncol=m)
-
-# right hand side of constraints
-rhs <- 1
-
-# direction of inequality of constraints
-dir <- "E"
-
-##### Unconstrained #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-lb <- rep(-Inf, m)
-ub <- rep(Inf, m)
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-test_that("Unconstrained: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt))
-})
-
-test_that("Unconstrained: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-##### Long Only #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-lb <- rep(0, m)
-ub <- rep(1, m)
-
-# Update box constraints in portfolio
-portf$constraints[[2]]$min <- lb
-portf$constraints[[2]]$max <- ub
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-test_that("Long Only: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt))
-})
-
-test_that("Long Only: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
-})
-
-test_that("Long Only: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
-})
-
-test_that("Long Only: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-##### Box #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-lb <- rep(0.05, m)
-ub <- rep(0.55, m)
-
-# Update box constraints in portfolio
-portf$constraints[[2]]$min <- lb
-portf$constraints[[2]]$max <- ub
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-
-test_that("Box: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt))
-})
-
-test_that("Box: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
-})
-
-test_that("Box: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
-})
-
-test_that("Box: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-##### Box with Shorting #####
-# Upper and lower bounds (i.e. box constraints)
-# Rcplex bounds
-lb <- rep(-0.05, m)
-ub <- rep(0.55, m)
-
-# Update box constraints in portfolio
-portf$constraints[[2]]$min <- lb
-portf$constraints[[2]]$max <- ub
-
-# Solve optimization with Rcplex
-opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
-                     sense=dir, control=list(trace=0))
-
-# Solve optimization with PortfolioAnalytics
-opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
-weights <- as.numeric(extractWeights(opt.pa))
-
-
-test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution weights are equal", {
-  expect_that(weights, equals(opt.rcplex$xopt))
-})
-
-test_that("Box with Shorting: PortfolioAnalytics bounds are respected", {
-  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
-})
-
-test_that("Box with Shorting: Rcplex bounds are respected", {
-  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
-})
-
-test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution objective values are equal", {
-  expect_that(opt.pa$out, equals(opt.rcplex$obj))
-})
-
-Rcplex.close()

Added: pkg/PortfolioAnalytics/sandbox/test_cplex_gmv.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/test_cplex_gmv.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/sandbox/test_cplex_gmv.R	2015-03-04 02:26:30 UTC (rev 3606)
@@ -0,0 +1,166 @@
+library(PortfolioAnalytics)
+library(Rcplex)
+library(ROI)
+library(ROI.plugin.cplex)
+library(testthat)
+
+# Test that PortfolioAnalytics with ROI.plugin.cplex solutions equal Rcplex solutions
+context("GMV Portfolios: PortfolioAnalytics with ROI.plugin.cplex and Rcplex")
+
+# args(Rcplex)
+# ?Rcplex
+
+##### Data #####
+data(edhec)
+R <- edhec[, 1:5]
+funds <- colnames(R)
+m <- ncol(R)
+
+##### Parameters #####
+portf <- portfolio.spec(funds)
+portf <- add.constraint(portf, type="full_investment")
+portf <- add.constraint(portf, type="box", min=-Inf, max=Inf)
+portf <- add.objective(portf, type="risk", name="var")
+
+# Quadratic part of objective function
+objQ <- 2 * cov(R)
+
+# Linear part of objective function
+objL <- rep(0, m)
+
+# Constraints matrix
+Amat <- matrix(1, nrow=1, ncol=m)
+
+# right hand side of constraints
+rhs <- 1
+
+# direction of inequality of constraints
+dir <- "E"
+
+##### Unconstrained #####
+# Upper and lower bounds (i.e. box constraints)
+# Rcplex bounds
+lb <- rep(-Inf, m)
+ub <- rep(Inf, m)
+
+# Solve optimization with Rcplex
+opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
+                     sense=dir, control=list(trace=0))
+
+# Solve optimization with PortfolioAnalytics
+opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
+weights <- as.numeric(extractWeights(opt.pa))
+
+test_that("Unconstrained: PortfolioAnalytics and Rcplex solution weights are equal", {
+  expect_that(weights, equals(opt.rcplex$xopt))
+})
+
+test_that("Unconstrained: PortfolioAnalytics and Rcplex solution objective values are equal", {
+  expect_that(opt.pa$out, equals(opt.rcplex$obj))
+})
+
+##### Long Only #####
+# Upper and lower bounds (i.e. box constraints)
+# Rcplex bounds
+lb <- rep(0, m)
+ub <- rep(1, m)
+
+# Update box constraints in portfolio
+portf$constraints[[2]]$min <- lb
+portf$constraints[[2]]$max <- ub
+
+# Solve optimization with Rcplex
+opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
+                     sense=dir, control=list(trace=0))
+
+# Solve optimization with PortfolioAnalytics
+opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
+weights <- as.numeric(extractWeights(opt.pa))
+
+test_that("Long Only: PortfolioAnalytics and Rcplex solution weights are equal", {
+  expect_that(weights, equals(opt.rcplex$xopt))
+})
+
+test_that("Long Only: PortfolioAnalytics bounds are respected", {
+  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
+})
+
+test_that("Long Only: Rcplex bounds are respected", {
+  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
+})
+
+test_that("Long Only: PortfolioAnalytics and Rcplex solution objective values are equal", {
+  expect_that(opt.pa$out, equals(opt.rcplex$obj))
+})
+
+##### Box #####
+# Upper and lower bounds (i.e. box constraints)
+# Rcplex bounds
+lb <- rep(0.05, m)
+ub <- rep(0.55, m)
+
+# Update box constraints in portfolio
+portf$constraints[[2]]$min <- lb
+portf$constraints[[2]]$max <- ub
+
+# Solve optimization with Rcplex
+opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
+                     sense=dir, control=list(trace=0))
+
+# Solve optimization with PortfolioAnalytics
+opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
+weights <- as.numeric(extractWeights(opt.pa))
+
+
+test_that("Box: PortfolioAnalytics and Rcplex solution weights are equal", {
+  expect_that(weights, equals(opt.rcplex$xopt))
+})
+
+test_that("Box: PortfolioAnalytics bounds are respected", {
+  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
+})
+
+test_that("Box: Rcplex bounds are respected", {
+  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
+})
+
+test_that("Box: PortfolioAnalytics and Rcplex solution objective values are equal", {
+  expect_that(opt.pa$out, equals(opt.rcplex$obj))
+})
+
+##### Box with Shorting #####
+# Upper and lower bounds (i.e. box constraints)
+# Rcplex bounds
+lb <- rep(-0.05, m)
+ub <- rep(0.55, m)
+
+# Update box constraints in portfolio
+portf$constraints[[2]]$min <- lb
+portf$constraints[[2]]$max <- ub
+
+# Solve optimization with Rcplex
+opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
+                     sense=dir, control=list(trace=0))
+
+# Solve optimization with PortfolioAnalytics
+opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
+weights <- as.numeric(extractWeights(opt.pa))
+
+
+test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution weights are equal", {
+  expect_that(weights, equals(opt.rcplex$xopt))
+})
+
+test_that("Box with Shorting: PortfolioAnalytics bounds are respected", {
+  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
+})
+
+test_that("Box with Shorting: Rcplex bounds are respected", {
+  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
+})
+
+test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution objective values are equal", {
+  expect_that(opt.pa$out, equals(opt.rcplex$obj))
+})
+
+Rcplex.close()

Added: pkg/PortfolioAnalytics/sandbox/test_cplex_maxMean.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/test_cplex_maxMean.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/sandbox/test_cplex_maxMean.R	2015-03-04 02:26:30 UTC (rev 3606)
@@ -0,0 +1,140 @@
+library(PortfolioAnalytics)
+library(Rcplex)
+library(ROI)
+library(ROI.plugin.cplex)
+library(testthat)
+
+# Test that ROI.plugin.cplex solutions equal Rcplex solutions
+context("Maximum Mean Return Portfolios: PortfolioAnalytics with ROI.plugin.cplex and Rcplex")
+
+# args(Rcplex)
+# ?Rcplex
+
+##### Data #####
+data(edhec)
+R <- edhec[, 1:5]
+funds <- colnames(R)
+m <- ncol(R)
+
+##### Parameters #####
+portf <- portfolio.spec(funds)
+portf <- add.constraint(portf, type="full_investment")
+portf <- add.constraint(portf, type="box", min=0, max=1)
+portf <- add.objective(portf, type="return", name="mean")
+
+# Quadratic part of objective function
+objQ <- NULL
+
+# Linear part of objective function
+objL <- -colMeans(R)
+
+# Constraints matrix
+Amat <- matrix(1, nrow=1, ncol=m)
+
+# right hand side of constraints
+rhs <- 1
+
+# direction of inequality of constraints
+dir <- "E"
+
+
+##### Long Only #####
+# Upper and lower bounds (i.e. box constraints)
+# Rcplex bounds
+lb <- rep(0, m)
+ub <- rep(1, m)
+
+# Solve optimization with Rcplex
+opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
+                     sense=dir, control=list(trace=0))
+
+# Solve optimization with PortfolioAnalytics
+opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
+weights <- as.numeric(extractWeights(opt.pa))
+
+test_that("Long Only: PortfolioAnalytics and Rcplex solution weights are equal", {
+  expect_that(weights, equals(opt.rcplex$xopt))
+})
+
+test_that("Long Only: PortfolioAnalytics bounds are respected", {
+  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
+})
+
+test_that("Long Only: Rcplex bounds are respected", {
+  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
+})
+
+test_that("Long Only: PortfolioAnalytics and Rcplex solution objective values are equal", {
+  expect_that(opt.pa$out, equals(opt.rcplex$obj))
+})
+
+##### Box #####
+# Upper and lower bounds (i.e. box constraints)
+# Rcplex bounds
+lb <- rep(0.05, m)
+ub <- rep(0.55, m)
+
+# Update box constraints in portfolio
+portf$constraints[[2]]$min <- lb
+portf$constraints[[2]]$max <- ub
+
+# Solve optimization with Rcplex
+opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
+                     sense=dir, control=list(trace=0))
+
+# Solve optimization with PortfolioAnalytics
+opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
+weights <- as.numeric(extractWeights(opt.pa))
+
+test_that("Box: PortfolioAnalytics and Rcplex solution weights are equal", {
+  expect_that(weights, equals(opt.rcplex$xopt))
+})
+
+test_that("Box: PortfolioAnalytics bounds are respected", {
+  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
+})
+
+test_that("Box: Rcplex bounds are respected", {
+  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
+})
+
+test_that("Box: PortfolioAnalytics and Rcplex solution objective values are equal", {
+  expect_that(opt.pa$out, equals(opt.rcplex$obj))
+})
+
+##### Box with Shorting #####
+# Upper and lower bounds (i.e. box constraints)
+# Rcplex bounds
+lb <- rep(-0.05, m)
+ub <- rep(0.55, m)
+
+# Update box constraints in portfolio
+portf$constraints[[2]]$min <- lb
+portf$constraints[[2]]$max <- ub
+
+# Solve optimization with Rcplex
+opt.rcplex <- Rcplex(cvec=objL, Amat=Amat, bvec=rhs, Qmat=objQ, lb=lb, ub=ub, 
+                     sense=dir, control=list(trace=0))
+
+# Solve optimization with PortfolioAnalytics
+opt.pa <- optimize.portfolio(R, portf, optimize_method="cplex")
+weights <- as.numeric(extractWeights(opt.pa))
+
+test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution weights are equal", {
+  expect_that(weights, equals(opt.rcplex$xopt))
+})
+
+test_that("Box with Shorting: PortfolioAnalytics bounds are respected", {
+  expect_that(all(weights >= lb) & all(weights <= ub), is_true())
+})
+
+test_that("Box with Shorting: Rcplex bounds are respected", {
+  expect_that(all(opt.rcplex$xopt >= lb) & all(opt.rcplex$xopt <= ub), is_true())
+})
+
+test_that("Box with Shorting: PortfolioAnalytics and Rcplex solution objective values are equal", {
+  expect_that(opt.pa$out, equals(opt.rcplex$obj))
+})
+
+Rcplex.close()
+

[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/returnanalytics -r 3606


More information about the Returnanalytics-commits mailing list