[Returnanalytics-commits] r2328 - pkg/PortfolioAnalytics/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Mar 15 22:51:06 CET 2013
Author: peter_carl
Date: 2013-03-15 22:51:06 +0100 (Fri, 15 Mar 2013)
New Revision: 2328
Modified:
pkg/PortfolioAnalytics/R/constrained_objective.R
Log:
- using Herfindahl sum of squares to measure concentration
- combine min_concentration and min_difference methods
Modified: pkg/PortfolioAnalytics/R/constrained_objective.R
===================================================================
--- pkg/PortfolioAnalytics/R/constrained_objective.R 2013-03-14 17:43:15 UTC (rev 2327)
+++ pkg/PortfolioAnalytics/R/constrained_objective.R 2013-03-15 21:51:06 UTC (rev 2328)
@@ -264,18 +264,21 @@
if(!is.null(RBupper) | !is.null(RBlower)){
out = out + penalty * objective$multiplier * sum( (percrisk-RBupper)*( percrisk > RBupper ),na.rm=TRUE ) + penalty*sum( (RBlower-percrisk)*( percrisk < RBlower ),na.rm=TRUE )
}
- if(!is.null(objective$min_concentration)){
- if(isTRUE(objective$min_concentration)){
- max_conc<-max(tmp_measure[[2]]) #second element is the contribution in absolute terms
- # out=out + penalty * objective$multiplier * max_conc
- out = out + objective$multiplier * max_conc
- }
- }
- if(!is.null(objective$min_difference)){
+# if(!is.null(objective$min_concentration)){
+# if(isTRUE(objective$min_concentration)){
+# max_conc<-max(tmp_measure[[2]]) #second element is the contribution in absolute terms
+# # out=out + penalty * objective$multiplier * max_conc
+# out = out + objective$multiplier * max_conc
+# }
+# }
+ # Combined min_con and min_dif to take advantage of a better concentration obj measure
+ if(!is.null(objective$min_difference) || !is.null(objective$min_concentration)){
if(isTRUE(objective$min_difference)){
- max_diff<-max(tmp_measure[[2]]-(sum(tmp_measure[[2]])/length(tmp_measure[[2]]))) #second element is the contribution in absolute terms
+# max_diff<-max(tmp_measure[[2]]-(sum(tmp_measure[[2]])/length(tmp_measure[[2]]))) #second element is the contribution in absolute terms
+ # Uses Herfindahl index to calculate concentration; added scaling perc diffs back to univariate numbers
+ max_diff <- sqrt(sum(tmp_measure[[3]]^2))/100 #third element is the contribution in percentage terms
# out = out + penalty * objective$multiplier * max_diff
- out = out + objective$multiplier * max_diff
+ out = out + penalty*objective$multiplier * max_diff
}
}
} # end handling of risk_budget objective
More information about the Returnanalytics-commits
mailing list