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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 5 18:59:02 CEST 2013


Author: rossbennett34
Date: 2013-07-05 18:59:01 +0200 (Fri, 05 Jul 2013)
New Revision: 2506

Modified:
   pkg/PortfolioAnalytics/R/constraint_fn_map.R
Log:
Removing constraint_fn_map function in favor of using fn_map function

Modified: pkg/PortfolioAnalytics/R/constraint_fn_map.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraint_fn_map.R	2013-07-05 16:54:52 UTC (rev 2505)
+++ pkg/PortfolioAnalytics/R/constraint_fn_map.R	2013-07-05 16:59:01 UTC (rev 2506)
@@ -1,94 +1,4 @@
-#' Constraint mapping function
-#' 
-#' The purpose of the mapping function is to transform a weights vector
-#' that does not meet all the constraints into a weights vector that
-#' does meet the constraints, if one exists, hopefully with a minimum
-#' of transformation.
 
-#' I think our first step should be to test each constraint type, in
-#' some sort of hierarchy, starting with box constraints (almost all
-#' solvers support box constraints, of course), since some of the other
-#' transformations will violate the box constraints, and we'll need to
-#' transform back again.
-#' 
-#' @param weights vector of weights
-#' @param portfolio object of class portfolio
-#' @author Ross Bennett
-#' @export
-constraint_fn_map <- function(weights, portfolio) {
-  
-  if (!is.portfolio(portfolio)) {
-    stop("Portfolio passed in is not of class portfolio")
-  }
-  
-  # number of assets
-  nassets <- length(portfolio$assets)
-  
-  # This is in a loop so the order of transformation depends on how the constraints are added by the user.
-  # Maybe take this out of a loop because the order of transformation is important
-  for(constraint in portfolio$constraints) {
-    # Check for enabled constraints
-    if(constraint$enabled){
-      
-      ## box constraint
-      if(inherits(constraint, "box_constraint")){
-        min <- constraint$min
-        max <- constraint$max
-        
-        w <- txfrm_box_constraint(weights=weights, min=min, max=max)
-        
-        # The transformation will likely change the sum of weights and violate min_sum or max_sum
-        # Should we normalize here by transforming the entire weights vector?
-        # Normalizing by transforming the entire weights may violate min and max, but will get us *close*
-      } # end box_constraint transformation
-      
-      ## weight_sum constraint
-      if(inherits(constraint, "weight_sum_constraint")){
-        min_sum <- constraint$min_sum
-        max_sum <- constraint$max_sum
-        # print(min_sum)
-        # print(max_sum)
-        
-        w <- txfrm_weight_sum_constraint(weights=weights, min_sum=min_sum, max_sum=max_sum)
-        
-      } # end weight_sum constraint transformation
-      
-      ## group constraint
-      if(inherits(constraint, "group_constraint")){
-        groups <- constraint$groups
-        cLO <- constraint$cLO
-        cUP <- constraint$cUP
-        # print(groups)
-        # print(cLO)
-        # print(cUP)
-        
-        w <- txfrm_group_constraint(weights=weights, groups=groups, cLO=cLO, cUP=cUP)
-        
-        # Normalizing the weights inside the groups changes the sum of the weights.
-        # Should normalizing the sum of weights take place here or somewhere else?
-        # Re-normalizing the weights will get us *close* to satisfying the group constraints.
-        # Maybe then add a penalty in constrained objective for violation of group constraints?
-      } # end group_constraint transformation
-      
-      # Turnover constraints
-      # TODO
-      
-      # Diversification constraints
-      # TODO
-      
-      ## position_limit constraint
-      if(inherits(constraint, "group_constraint")){
-        max_pos <- constraint$max_pos
-        
-        w <- txfrm_position_limit_constraint(weights=weights, max_pos=max_pos, nassets=nassets)
-        
-      } # end position_limit_constraint transformation
-      
-    }
-  }
-  return(w)
-}
-
 #' mapping function to transform or penalize weights that violate constraints
 #' 
 #' The purpose of the mapping function is to transform a weights vector



More information about the Returnanalytics-commits mailing list