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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 28 20:51:05 CEST 2013


Author: rossbennett34
Date: 2013-06-28 20:51:05 +0200 (Fri, 28 Jun 2013)
New Revision: 2466

Modified:
   pkg/PortfolioAnalytics/R/constrained_objective.R
   pkg/PortfolioAnalytics/R/objective.R
Log:
revised minmax_objective in constrained_objective to only penalize if max is violated to the upside or min is violated to the downside

Modified: pkg/PortfolioAnalytics/R/constrained_objective.R
===================================================================
--- pkg/PortfolioAnalytics/R/constrained_objective.R	2013-06-28 18:35:17 UTC (rev 2465)
+++ pkg/PortfolioAnalytics/R/constrained_objective.R	2013-06-28 18:51:05 UTC (rev 2466)
@@ -257,7 +257,12 @@
           
           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))
+              if(tmp_measure > objective$max){
+                out = out + penalty * objective$multiplier * (tmp_measure - objective$max)
+              }
+              if(tmp_measure < objective$min){
+                out = out + penalty * objective$multiplier * (objective$min - tmp_measure)
+              }
             }
           } # temporary minmax objective
           

Modified: pkg/PortfolioAnalytics/R/objective.R
===================================================================
--- pkg/PortfolioAnalytics/R/objective.R	2013-06-28 18:35:17 UTC (rev 2465)
+++ pkg/PortfolioAnalytics/R/objective.R	2013-06-28 18:51:05 UTC (rev 2466)
@@ -113,6 +113,11 @@
                                                           arguments=arguments,
                                                           ...=...)
            },
+           tmp_minmax = {tmp_objective = minmax_objective(name=name,
+                                                          enabled=enabled,
+                                                          arguments=arguments,
+                                                          ...=...)
+           },
           
         null =
           {return(constraints)} # got nothing, default to simply returning



More information about the Returnanalytics-commits mailing list