[Returnanalytics-commits] r2426 - pkg/PortfolioAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 25 05:19:25 CEST 2013


Author: rossbennett34
Date: 2013-06-25 05:19:25 +0200 (Tue, 25 Jun 2013)
New Revision: 2426

Modified:
   pkg/PortfolioAnalytics/R/constraints.R
Log:
adding functionality to specify diversification constraint

Modified: pkg/PortfolioAnalytics/R/constraints.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraints.R	2013-06-25 02:59:57 UTC (rev 2425)
+++ pkg/PortfolioAnalytics/R/constraints.R	2013-06-25 03:19:25 UTC (rev 2426)
@@ -221,6 +221,11 @@
                                                            enabled=enabled,
                                                            ...=...)
          },
+         # Diversification constraint
+         diversification = {tmp_constraint <- diversification_constraint(type=type,
+                                                                         enabled=enabled,
+                                                                         ...=...)
+         },
          # Do nothing and return the portfolio object if type is NULL
          null = {return(portfolio)}
   )
@@ -488,6 +493,22 @@
   return(Constraint)
 }
 
+#' constructor for diversification_constraint
+#' 
+#' This function is called by add.constraint when type="diversification" is specified, \code{\link{add.constraint}}
+#' 
+#' @param type character type of the constraint
+#' @param div.target diversification target value
+#' @param enabled TRUE/FALSE
+#' @param \dots any other passthru parameters to specify box and/or group constraints
+#' @author Ross Bennett
+#' @export
+diversification_constraint <- function(type, div.target, enabled=FALSE, ...){
+  Constraint <- constraint_v2(type, enabled=enabled, ...)
+  Constraint$div <- div.target
+  return(Constraint)
+}
+
 #' function for updating constrints, not well tested, may be broken
 #' 
 #' can we use the generic update.default function?



More information about the Returnanalytics-commits mailing list