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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jul 20 21:09:16 CEST 2013


Author: rossbennett34
Date: 2013-07-20 21:09:16 +0200 (Sat, 20 Jul 2013)
New Revision: 2606

Modified:
   pkg/PortfolioAnalytics/R/constraint_fn_map.R
   pkg/PortfolioAnalytics/R/random_portfolios.R
Log:
correct weight_seq and relax min_sum and max_sum in randomize portfolio. Changed to silent=TRUE for try expresseions in fn_map

Modified: pkg/PortfolioAnalytics/R/constraint_fn_map.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraint_fn_map.R	2013-07-20 13:31:25 UTC (rev 2605)
+++ pkg/PortfolioAnalytics/R/constraint_fn_map.R	2013-07-20 19:09:16 UTC (rev 2606)
@@ -88,7 +88,7 @@
                                       groups=NULL, cLO=NULL, cUP=NULL, 
                                       max_pos=NULL, group_pos=NULL, 
                                       max_pos_long=NULL, max_pos_short=NULL, 
-                                      max_permutations=500), silent=FALSE) # FALSE for testing
+                                      max_permutations=500), silent=TRUE) # FALSE for testing
       if(inherits(tmp_weights, "try-error")){
         # Default to initial weights
         tmp_weights <- weights
@@ -106,7 +106,7 @@
                                       groups=NULL, cLO=NULL, cUP=NULL, 
                                       max_pos=NULL, group_pos=NULL, 
                                       max_pos_long=NULL, max_pos_short=NULL, 
-                                      max_permutations=500), silent=FALSE) # FALSE for testing
+                                      max_permutations=500), silent=TRUE) # FALSE for testing
       if(inherits(tmp_weights, "try-error")){
         # Default to initial weights
         tmp_weights <- weights
@@ -134,7 +134,7 @@
                                             groups=NULL, cLO=NULL, cUP=NULL, 
                                             max_pos=NULL, group_pos=NULL, 
                                             max_pos_long=NULL, max_pos_short=NULL, 
-                                            max_permutations=500), silent=FALSE) # FALSE for testing
+                                            max_permutations=500), silent=TRUE) # FALSE for testing
             # Default to original weights if this fails again
             if(inherits(tmp_weights, "try-error")) tmp_weights <- weights
             i <- i + 1
@@ -161,7 +161,7 @@
                                       groups=groups, cLO=tmp_cLO, cUP=tmp_cUP, 
                                       max_pos=NULL, group_pos=group_pos, 
                                       max_pos_long=NULL, max_pos_short=NULL, 
-                                      max_permutations=500), silent=FALSE) # FALSE for testing
+                                      max_permutations=500), silent=TRUE) # FALSE for testing
       if(inherits(tmp_weights, "try-error")){
         # Default to initial weights
         tmp_weights <- weights
@@ -185,7 +185,7 @@
                                             groups=groups, cLO=tmp_cLO, cUP=tmp_cUP, 
                                             max_pos=NULL, group_pos=group_pos, 
                                             max_pos_long=NULL, max_pos_short=NULL, 
-                                            max_permutations=500), silent=FALSE) # FALSE for testing
+                                            max_permutations=500), silent=TRUE) # FALSE for testing
             if(inherits(tmp_weights, "try-error")) tmp_weights <- weights
             i <- i + 1
           }
@@ -211,7 +211,7 @@
                                       groups=groups, cLO=tmp_cLO, cUP=tmp_cUP, 
                                       max_pos=tmp_max_pos, group_pos=group_pos, 
                                       max_pos_long=tmp_max_pos_long, max_pos_short=tmp_max_pos_short, 
-                                      max_permutations=500), silent=FALSE) # FALSE for testing
+                                      max_permutations=500), silent=TRUE) # FALSE for testing
       if(inherits(tmp_weights, "try-error")){
         # Default to initial weights
         tmp_weights <- weights
@@ -229,7 +229,7 @@
                                             groups=groups, cLO=tmp_cLO, cUP=tmp_cUP, 
                                             max_pos=tmp_max_pos, group_pos=group_pos, 
                                             max_pos_long=tmp_max_pos_long, max_pos_short=tmp_max_pos_short, 
-                                            max_permutations=500), silent=FALSE) # FALSE for testing
+                                            max_permutations=500), silent=TRUE) # FALSE for testing
             if(inherits(tmp_weights, "try-error")) tmp_weights <- weights
             i <- i + 1
           }

Modified: pkg/PortfolioAnalytics/R/random_portfolios.R
===================================================================
--- pkg/PortfolioAnalytics/R/random_portfolios.R	2013-07-20 13:31:25 UTC (rev 2605)
+++ pkg/PortfolioAnalytics/R/random_portfolios.R	2013-07-20 19:09:16 UTC (rev 2606)
@@ -220,7 +220,13 @@
   if(is.null(max_mult)) max_mult <- rep(Inf,nassets)
   min_sum  <- constraints$min_sum
   max_sum  <- constraints$max_sum
-  weight_seq <- constraints$weight_seq
+  # randomize_portfolio will rarely find a feasible portfolio if there is not some 
+  # 'wiggle room' between min_sum and max_sum
+  if((max_sum - min_sum) < 0.02){
+    min_sum <- min_sum - 0.01
+    max_sum <- max_sum + 0.01
+  }
+  weight_seq <- portfolio$weight_seq
   if(is.null(weight_seq)){
     weight_seq <- generatesequence(min=min(constraints$min), max=max(constraints$max), by=0.002)
   }



More information about the Returnanalytics-commits mailing list