[Returnanalytics-commits] r2783 - pkg/PortfolioAnalytics/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Aug 14 18:24:03 CEST 2013
Author: rossbennett34
Date: 2013-08-14 18:24:03 +0200 (Wed, 14 Aug 2013)
New Revision: 2783
Modified:
pkg/PortfolioAnalytics/R/constrained_objective.R
Log:
adding code in constrained_objective_v2 to penalize weights that do not satisfy the factor exposure constraint
Modified: pkg/PortfolioAnalytics/R/constrained_objective.R
===================================================================
--- pkg/PortfolioAnalytics/R/constrained_objective.R 2013-08-14 16:15:37 UTC (rev 2782)
+++ pkg/PortfolioAnalytics/R/constrained_objective.R 2013-08-14 16:24:03 UTC (rev 2783)
@@ -526,6 +526,23 @@
mult <- 1
out = out + penalty * mult * abs(mean_return - return_target)
} # End return constraint penalty
+
+ # penalize weights that violate factor exposure constraints
+ if(!is.null(constraints$B)){
+ t.B <- t(constraints$B)
+ lower <- constraints$lower
+ upper <- constraints$upper
+ mult <- 1
+ for(i in 1:nrow(t.B)){
+ tmpexp <- as.numeric(t(w) %*% t.B[i, ])
+ if(tmpexp < lower[i]){
+ out <- out + penalty * mult * (lower[i] - tmpexp)
+ }
+ if(tmpexp > upper[i]){
+ out <- out + penalty * mult * (tmpexp - upper[i])
+ }
+ }
+ } # End factor exposure constraint penalty
nargs <- list(...)
if(length(nargs)==0) nargs <- NULL
More information about the Returnanalytics-commits
mailing list