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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 29 18:57:32 CEST 2013


Author: rossbennett34
Date: 2013-07-29 18:57:32 +0200 (Mon, 29 Jul 2013)
New Revision: 2670

Modified:
   pkg/PortfolioAnalytics/R/optimize.portfolio.R
   pkg/PortfolioAnalytics/man/optimize.portfolio.rebalancing.Rd
Log:
modifying optimize.portfolio.rebalancing to work with separate constraints and objectives

Modified: pkg/PortfolioAnalytics/R/optimize.portfolio.R
===================================================================
--- pkg/PortfolioAnalytics/R/optimize.portfolio.R	2013-07-29 16:52:00 UTC (rev 2669)
+++ pkg/PortfolioAnalytics/R/optimize.portfolio.R	2013-07-29 16:57:32 UTC (rev 2670)
@@ -984,6 +984,8 @@
 #' 
 #' @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
+#' @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", or "ROI"
 #' @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
@@ -995,11 +997,21 @@
 #' @return a list containing the optimal weights, some summary statistics, the function call, and optionally trace information 
 #' @author Kris Boudt, Peter Carl, Brian G. Peterson
 #' @export
-optimize.portfolio.rebalancing <- function(R, portfolio, optimize_method=c("DEoptim","random","ROI"), search_size=20000, trace=FALSE, ..., rp=NULL, rebalance_on=NULL, training_period=NULL, trailing_periods=NULL)
+optimize.portfolio.rebalancing <- function(R, portfolio, constraints=NULL, objectives=NULL, optimize_method=c("DEoptim","random","ROI"), search_size=20000, trace=FALSE, ..., rp=NULL, rebalance_on=NULL, training_period=NULL, trailing_periods=NULL)
 {
   stopifnot("package:foreach" %in% search() || require("foreach",quietly=TRUE))
   start_t<-Sys.time()
   
+  # 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)
+  }
+  
   #store the call for later
   call <- match.call()
   if(optimize_method=="random"){

Modified: pkg/PortfolioAnalytics/man/optimize.portfolio.rebalancing.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/optimize.portfolio.rebalancing.Rd	2013-07-29 16:52:00 UTC (rev 2669)
+++ pkg/PortfolioAnalytics/man/optimize.portfolio.rebalancing.Rd	2013-07-29 16:57:32 UTC (rev 2670)
@@ -3,6 +3,7 @@
 \title{portfolio optimization with support for rebalancing or rolling periods}
 \usage{
   optimize.portfolio.rebalancing(R, portfolio,
+    constraints = NULL, objectives = NULL,
     optimize_method = c("DEoptim", "random", "ROI"),
     search_size = 20000, trace = FALSE, ..., rp = NULL,
     rebalance_on = NULL, training_period = NULL,
@@ -15,6 +16,12 @@
   \item{portfolio}{an object of type "portfolio" specifying
   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", or
   "ROI"}
 



More information about the Returnanalytics-commits mailing list