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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 14 18:38:34 CET 2013


Author: peter_carl
Date: 2013-03-14 18:38:34 +0100 (Thu, 14 Mar 2013)
New Revision: 2326

Modified:
   pkg/PortfolioAnalytics/R/constrained_objective.R
Log:
- fixes targeting by calculating abs values of differences in out


Modified: pkg/PortfolioAnalytics/R/constrained_objective.R
===================================================================
--- pkg/PortfolioAnalytics/R/constrained_objective.R	2013-03-05 22:09:35 UTC (rev 2325)
+++ pkg/PortfolioAnalytics/R/constrained_objective.R	2013-03-14 17:38:34 UTC (rev 2326)
@@ -227,9 +227,7 @@
           # now set the new value of the objective output
           if(inherits(objective,"return_objective")){ 
               if (!is.null(objective$target) & is.numeric(objective$target)){ # we have a target
-                  if(tmp_measure<objective$target){
-                      out = out + penalty*objective$multiplier*(tmp_measure-objective$target)
-                  } 
+                  out = out + penalty*objective$multiplier*abs(tmp_measure-objective$target)
               }  
               # target is null or doesn't exist, just maximize, or minimize violation of constraint
               out = out + objective$multiplier*tmp_measure
@@ -237,9 +235,7 @@
 
           if(inherits(objective,"portfolio_risk_objective")){
             if (!is.null(objective$target) & is.numeric(objective$target)){ # we have a target
-                if(tmp_measure>objective$target){
-                    out = out + penalty*objective$multiplier*(tmp_measure-objective$target)
-                } 
+                out = out + penalty*objective$multiplier*abs(tmp_measure-objective$target)
                 #should we also penalize risk too low for risk targets? or is a range another objective?
                 #    # half penalty for risk lower than target
                 #    if(  prw < (.9*Riskupper) ){ out = out + .5*(penalty*( prw - Riskupper)) }
@@ -257,9 +253,7 @@
               #in addition to a risk budget constraint, we have a univariate target
               # the first element of the returned list is the univariate measure
               # we'll use the  univariate measure exactly like we would as a separate objective
-              if(tmp_measure[[1]]>objective$target){
-                out = out + penalty*objective$multiplier*(tmp_measure[[1]]-objective$target)
-              }
+                out = out + penalty*objective$multiplier*abs(tmp_measure[[1]]-objective$target)
               #should we also penalize risk too low for risk targets? or is a range another objective?
               #    # half penalty for risk lower than target
               #    if(  prw < (.9*Riskupper) ){ out = out + .5*(penalty*( prw - Riskupper)) }



More information about the Returnanalytics-commits mailing list