[Returnanalytics-commits] r2667 - in pkg/PortfolioAnalytics: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 29 18:42:00 CEST 2013


Author: rossbennett34
Date: 2013-07-29 18:42:00 +0200 (Mon, 29 Jul 2013)
New Revision: 2667

Modified:
   pkg/PortfolioAnalytics/R/constraints.R
   pkg/PortfolioAnalytics/R/optimize.portfolio.R
   pkg/PortfolioAnalytics/man/optimize.portfolio.Rd
Log:
modifying optimize.portfolio to accept constraints and objectives seperately

Modified: pkg/PortfolioAnalytics/R/constraints.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraints.R	2013-07-29 16:05:39 UTC (rev 2666)
+++ pkg/PortfolioAnalytics/R/constraints.R	2013-07-29 16:42:00 UTC (rev 2667)
@@ -568,7 +568,7 @@
 get_constraints <- function(portfolio){
   if(!is.portfolio(portfolio)) stop("portfolio passed in is not of class portfolio")
   
-  if(length(pspec$constraints) == 0) stop("No constraints passed in")
+  if(length(portfolio$constraints) == 0) stop("No constraints passed in")
   
   out <- list()
   out$min_sum <- NA

Modified: pkg/PortfolioAnalytics/R/optimize.portfolio.R
===================================================================
--- pkg/PortfolioAnalytics/R/optimize.portfolio.R	2013-07-29 16:05:39 UTC (rev 2666)
+++ pkg/PortfolioAnalytics/R/optimize.portfolio.R	2013-07-29 16:42:00 UTC (rev 2667)
@@ -510,7 +510,9 @@
 #' If you would like to interface with \code{optimize.portfolio} using matrix formulations, then use \code{ROI_old}. 
 #'  
 #' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns
-#' @param portfolio an object of type "portfolio" specifying the constraints and objectives for the optimization, see \code{\link{constraint}}, if using closed for solver, need to pass a \code{\link{constraint_ROI}} object.
+#' @param portfolio an object of type "portfolio" specifying the constraints and objectives for the optimization
+#' @param constraints default=NULL, a list of constraint objects
+#' @param objectives default=NULL, a list of objective objects
 #' @param optimize_method one of "DEoptim", "random", "ROI","ROI_old", "pso", "GenSA".  For using \code{ROI_old}, need to use a constraint_ROI object in constraints. For using \code{ROI}, pass standard \code{constratint} object in \code{constraints} argument.  Presently, ROI has plugins for \code{quadprog} and \code{Rglpk}.
 #' @param search_size integer, how many portfolios to test, default 20,000
 #' @param trace TRUE/FALSE if TRUE will attempt to return additional information on the path or portfolios searched
@@ -527,6 +529,8 @@
 optimize.portfolio_v2 <- function(
   R,
   portfolio,
+  constraints=NULL,
+  objectives=NULL,
   optimize_method=c("DEoptim","random","ROI","ROI_old","pso","GenSA"),
   search_size=20000,
   trace=FALSE, ...,
@@ -553,6 +557,16 @@
   }
   T <- nrow(R)
   
+  # Check for constraints and objectives passed in separately outside of the portfolio object
+  if(!is.null(constraints)){
+    # Insert the constraints into the portfolio object
+    portfolio <- insert_constraints(portfolio=portfolio, constraints=constraints)
+  }
+  if(!is.null(objectives)){
+    # Insert the objectives into the portfolio object
+    portfolio <- insert_objectives(portfolio=portfolio, objectives=objectives)
+  }
+  
   out <- list()
   
   weights <- NULL

Modified: pkg/PortfolioAnalytics/man/optimize.portfolio.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/optimize.portfolio.Rd	2013-07-29 16:05:39 UTC (rev 2666)
+++ pkg/PortfolioAnalytics/man/optimize.portfolio.Rd	2013-07-29 16:42:00 UTC (rev 2667)
@@ -3,7 +3,8 @@
 \alias{optimize.portfolio_v2}
 \title{version 2 wrapper for constrained optimization of portfolios}
 \usage{
-  optimize.portfolio_v2(R, portfolio,
+  optimize.portfolio_v2(R, portfolio, constraints = NULL,
+    objectives = NULL,
     optimize_method = c("DEoptim", "random", "ROI", "ROI_old", "pso", "GenSA"),
     search_size = 20000, trace = FALSE, ..., rp = NULL,
     momentFUN = "set.portfolio.moments", message = FALSE)
@@ -13,10 +14,14 @@
   or zoo object of asset returns}
 
   \item{portfolio}{an object of type "portfolio" specifying
-  the constraints and objectives for the optimization, see
-  \code{\link{constraint}}, if using closed for solver,
-  need to pass a \code{\link{constraint_ROI}} object.}
+  the constraints and objectives for the optimization}
 
+  \item{constraints}{default=NULL, a list of constraint
+  objects}
+
+  \item{objectives}{default=NULL, a list of objective
+  objects}
+
   \item{optimize_method}{one of "DEoptim", "random",
   "ROI","ROI_old", "pso", "GenSA".  For using
   \code{ROI_old}, need to use a constraint_ROI object in



More information about the Returnanalytics-commits mailing list