[Returnanalytics-commits] r2598 - pkg/PortfolioAnalytics/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jul 19 04:23:33 CEST 2013
Author: rossbennett34
Date: 2013-07-19 04:23:32 +0200 (Fri, 19 Jul 2013)
New Revision: 2598
Modified:
pkg/PortfolioAnalytics/R/constraint_fn_map.R
Log:
modified for individual checks NULL for max_pos_long or max_pos_short
Modified: pkg/PortfolioAnalytics/R/constraint_fn_map.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraint_fn_map.R 2013-07-19 01:58:31 UTC (rev 2597)
+++ pkg/PortfolioAnalytics/R/constraint_fn_map.R 2013-07-19 02:23:32 UTC (rev 2598)
@@ -408,13 +408,16 @@
tmp_w[not_index] <- 0
# set some tmp_min values equal to zero so the while loops do not see a
- # violation of any(tmp_w < tmp_min)
- tmp_min[not_index] <- 0
+ # violation of any(tmp_w < tmp_min). This tends to force weights to 0 and
+ # works well for long only, but we may want to allow negative weights.
+ # tmp_min[not_index] <- 0
+ # Only set values of tmp_min that are greater than 0 to 0
+ tmp_min[not_index[which(tmp_min[not_index] > 0)]] <- 0
# Transform weights to satisfy max_pos_long and max_pos_short before being
# passed into the main loops
# Both max_pos_long and max_pos_short should be specified
- if(!is.null(max_pos_long) & !is.null(max_pos_short)){
+ if(!is.null(max_pos_long)){
pos_idx <- which(tmp_w > 0)
neg_idx <- which(tmp_w < 0)
@@ -433,6 +436,8 @@
}
}
}
+ }
+ if(!is.null(max_pos_short)){
# Check if number of negative weights exceeds max_pos_short
if(length(neg_idx) > max_pos_short){
# Randomly sample negative weights that cause violation of max_pos_short
More information about the Returnanalytics-commits
mailing list