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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 28 19:58:10 CEST 2013


Author: rossbennett34
Date: 2013-06-28 19:58:10 +0200 (Fri, 28 Jun 2013)
New Revision: 2463

Modified:
   pkg/PortfolioAnalytics/R/constrained_objective.R
   pkg/PortfolioAnalytics/R/objective.R
Log:
adding a temporary minmax objective for testing to understand how the objective function responds to specifying min and max values instead of a target

Modified: pkg/PortfolioAnalytics/R/constrained_objective.R
===================================================================
--- pkg/PortfolioAnalytics/R/constrained_objective.R	2013-06-28 17:29:38 UTC (rev 2462)
+++ pkg/PortfolioAnalytics/R/constrained_objective.R	2013-06-28 17:58:10 UTC (rev 2463)
@@ -255,6 +255,12 @@
             out = out + abs(objective$multiplier)*tmp_measure
           } #  univariate turnover objectives
           
+          if(inherits(objective,"minmax_objective")){
+            if (!is.null(objective$min) & !is.null(objective$max)){ # we have a min and max
+              out = out + penalty * objective$multiplier * ((tmp_measure - objective$max) + (objective$min - tmp_measure))
+            }
+          } # temporary minmax objective
+          
           if(inherits(objective,"risk_budget_objective")){
             # setup
             

Modified: pkg/PortfolioAnalytics/R/objective.R
===================================================================
--- pkg/PortfolioAnalytics/R/objective.R	2013-06-28 17:29:38 UTC (rev 2462)
+++ pkg/PortfolioAnalytics/R/objective.R	2013-06-28 17:58:10 UTC (rev 2463)
@@ -191,6 +191,11 @@
                                                         arguments=arguments,
                                                         ...=...)
          },
+         tmp_minmax = {tmp_objective = minmax_objective(name=name,
+                                                        enabled=enabled,
+                                                        arguments=arguments,
+                                                        ...=...)
+         },
          
          null = 
            {return(portfolio)} # got nothing, default to simply returning
@@ -333,3 +338,39 @@
   if(!hasArg(multiplier)) multiplier=1
   return(objective(name=name, target=target, arguments=arguments, enabled=enabled, multiplier=multiplier,objclass=c("turnover_objective","objective"), ... ))
 } # end turnover_objective constructor
+
+#' constructor for class tmp_minmax_objective
+#'
+#' I am add this as a temporary objective allowing for a min and max to be specified. Testing
+#' to understand how the objective function responds to a range of allowable values. I will
+#' likely add this to the turnover, diversification, and volatility constraints 
+#' allowing the user to specify a range of values.
+#' 
+#' if target is null, we'll try to minimize the metric
+#' 
+#' if target is set, we'll try to meet the metric
+#' 
+#' If max is violated to the upside, penalize the metric
+#' If min is violated to the downside, penalize the metric
+#' Try to meet the range between min and max
+#'  
+#' @param name name of the objective, should correspond to a function, though we will try to make allowances
+#' @param target univariate target for the objective
+#' @param min minimum value
+#' @param max maximum value
+#' @param arguments default arguments to be passed to an objective function when executed
+#' @param multiplier multiplier to apply to the objective, usually 1 or -1
+#' @param enabled TRUE/FALSE
+#' @param \dots any other passthru parameters 
+#' @author Ross Bennett
+#' @export
+minmax_objective <- function(name, target=NULL, arguments=NULL, multiplier=1, enabled=FALSE, ..., min, max )
+{
+  if(!hasArg(target)) target = NULL
+  ##' if target is null, we'll try to minimize the metric
+  if(!hasArg(multiplier)) multiplier=1
+  Objective <- objective(name=name, target=target, arguments=arguments, enabled=enabled, multiplier=multiplier,objclass=c("minmax_objective","objective"), ... )
+  Objective$min <- min
+  Objective$max <- max
+  return(Objective)
+} # end minmax_objective constructor
\ No newline at end of file



More information about the Returnanalytics-commits mailing list