[Returnanalytics-commits] r2556 - in pkg/PortfolioAnalytics: R sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 12 05:27:33 CEST 2013


Author: rossbennett34
Date: 2013-07-12 05:27:32 +0200 (Fri, 12 Jul 2013)
New Revision: 2556

Modified:
   pkg/PortfolioAnalytics/R/optimize.portfolio.R
   pkg/PortfolioAnalytics/sandbox/testing_optimize.portfolio_v2.R
Log:
fixed call to fn_map to only return the weights and added comments in testing script

Modified: pkg/PortfolioAnalytics/R/optimize.portfolio.R
===================================================================
--- pkg/PortfolioAnalytics/R/optimize.portfolio.R	2013-07-12 03:15:58 UTC (rev 2555)
+++ pkg/PortfolioAnalytics/R/optimize.portfolio.R	2013-07-12 03:27:32 UTC (rev 2556)
@@ -613,7 +613,7 @@
       itermax <- round(search_size / NP)
       if(itermax < 50) itermax <- 50 #set minimum number of generations
     }
-    print(NP)
+    
     #check to see whether we need to disable foreach for parallel optimization, esp if called from inside foreach
     if(hasArg(parallel)) parallel <- match.call(expand.dots=TRUE)$parallel else parallel <- TRUE
     if(!isTRUE(parallel) && 'package:foreach' %in% search()){
@@ -669,7 +669,7 @@
     
     # We are passing fn_map to the optional fnMap function to do the 
     # transformation so we need to force normalize=FALSE in call to constrained_objective
-    minw = try(DEoptim( constrained_objective_v2,  lower=lower[1:N], upper=upper[1:N], control=controlDE, R=R, portfolio=portfolio, nargs = dotargs , ...=..., normalize=FALSE, fnMap=function(x) fn_map(x, portfolio=portfolio))) # add ,silent=TRUE here?
+    minw = try(DEoptim( constrained_objective_v2,  lower=lower[1:N], upper=upper[1:N], control=controlDE, R=R, portfolio=portfolio, nargs = dotargs , ...=..., normalize=FALSE, fnMap=function(x) fn_map(x, portfolio=portfolio)$weights)) # add ,silent=TRUE here?
     
     if(inherits(minw, "try-error")) { minw=NULL }
     if(is.null(minw)){
@@ -680,6 +680,7 @@
     if(isTRUE(tmptrace)) trace <- tmptrace
     
     weights <- as.vector(minw$optim$bestmem)
+    print(weights)
     # is it necessary to normalize the weights here?
     weights <- normalize_weights(weights)
     names(weights) <- colnames(R)

Modified: pkg/PortfolioAnalytics/sandbox/testing_optimize.portfolio_v2.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/testing_optimize.portfolio_v2.R	2013-07-12 03:15:58 UTC (rev 2555)
+++ pkg/PortfolioAnalytics/sandbox/testing_optimize.portfolio_v2.R	2013-07-12 03:27:32 UTC (rev 2556)
@@ -35,6 +35,9 @@
 all.equal(opt_out_de$weights, opt_de$weights)
 all.equal(opt_out_de$objective_measures, opt_de$objective_measures)
 
+# Note that values are now different since I added fnMap=fn_map to DEoptim in optimize.portfolio_v2
+# This is likely due to how normalization/transformation is handled
+
 ##### Simple test for random method with optimize.portfolio_v2 #####
 
 set.seed(123)



More information about the Returnanalytics-commits mailing list