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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 5 15:52:31 CEST 2013


Author: rossbennett34
Date: 2013-07-05 15:52:31 +0200 (Fri, 05 Jul 2013)
New Revision: 2503

Modified:
   pkg/PortfolioAnalytics/R/random_portfolios.R
Log:
fixed potential bug in randomize_portfolio that I found with rp_transform. length((weight_seq<=cur_val) & (weight_seq>=min[cur_index])) will always be equal to the length of weight_seq, need to subset first

Modified: pkg/PortfolioAnalytics/R/random_portfolios.R
===================================================================
--- pkg/PortfolioAnalytics/R/random_portfolios.R	2013-07-05 13:34:48 UTC (rev 2502)
+++ pkg/PortfolioAnalytics/R/random_portfolios.R	2013-07-05 13:52:31 UTC (rev 2503)
@@ -116,10 +116,10 @@
           # randomly permute and decrease a random portfolio element
           cur_index<-random_index[i]
           cur_val <- tportfolio[cur_index]
-            if (length(weight_seq<=cur_val & weight_seq>=min[cur_index] )>1) {
-              tportfolio[cur_index]<-sample(weight_seq[which(weight_seq<=cur_val & weight_seq>=min[cur_index] )],1)
+            if (length(weight_seq[(weight_seq<=cur_val) & (weight_seq>=min[cur_index])] )>1) {
+              tportfolio[cur_index]<-sample(weight_seq[(weight_seq<=cur_val) & (weight_seq>=min[cur_index] )],1)
             } else {
-              if (length(weight_seq<=cur_val & weight_seq>=min[cur_index] )==1) {
+              if (length(weight_seq[(weight_seq<=cur_val) & (weight_seq>=min[cur_index])] )==1) {
                 tportfolio[cur_index]<-weight_seq[(weight_seq<=cur_val) & (weight_seq>=min[cur_index])]
               }
             }



More information about the Returnanalytics-commits mailing list