[Returnanalytics-commits] r2532 - pkg/PortfolioAnalytics/sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jul 10 04:26:09 CEST 2013


Author: rossbennett34
Date: 2013-07-10 04:26:09 +0200 (Wed, 10 Jul 2013)
New Revision: 2532

Modified:
   pkg/PortfolioAnalytics/sandbox/leverage_transformation_testing.R
Log:
modify to allow changin values of min

Modified: pkg/PortfolioAnalytics/sandbox/leverage_transformation_testing.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/leverage_transformation_testing.R	2013-07-10 02:07:15 UTC (rev 2531)
+++ pkg/PortfolioAnalytics/sandbox/leverage_transformation_testing.R	2013-07-10 02:26:09 UTC (rev 2532)
@@ -11,7 +11,9 @@
 ##### Random Portfolios: 50 assets 5,000 portfolios
 nassets <- 50
 npermutations <- 500
-min <- rep(0.02, nassets)
+min <- rep(0, nassets)
+# random_index <- sample(1:nassets, 5)
+# min[random_index] <- 0.01
 max <- rep(0.5, nassets)
 rp <- list()
 for(i in 1:10){
@@ -20,7 +22,7 @@
 
 cset <- constraint(assets=nassets, min=min, max=max, 
                    min_sum=min_sum, max_sum=max_sum,
-                   weight_seq=generatesequence(min=0.02, max=0.4, by=0.005))
+                   weight_seq=generatesequence(min=0, max=0.5, by=0.005))
 
 rp[[i]] <- random_portfolios(rpconstraints=cset, permutations=npermutations)
 }
@@ -42,6 +44,8 @@
 nassets <- 250
 npermutations <- 500
 min <- rep(0, nassets)
+random_index <- sample(1:nassets, 10)
+min[random_index] <- 0.01
 max <- rep(0.5, nassets)
 rp <- list()
 for(i in 1:10){
@@ -59,7 +63,7 @@
 
 # transform the entire vector to meet leverage constraints
 tmp_rp <- t(apply(rp, 1, txfrm_weight_sum_constraint, min_sum=0.99, max_sum=1.01))
-summary(rowSums(tmp_rp))
+
 # percentage of portfolios that satisfy box constraints after the simple transformation
 sum(apply(tmp_rp, 1, function(x) all(x >= min & x <= max))) / (nrow(tmp_rp)) * 100
 



More information about the Returnanalytics-commits mailing list