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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Aug 31 02:39:22 CEST 2013


Author: rossbennett34
Date: 2013-08-31 02:39:21 +0200 (Sat, 31 Aug 2013)
New Revision: 2947

Modified:
   pkg/PortfolioAnalytics/R/optimize.portfolio.R
   pkg/PortfolioAnalytics/sandbox/testing_risk_budget.R
Log:
Adding checks to arguments that are passed in to set portfolio moments. Fixing error that was caused when clean='boudt' and dots arguments were passed in to optimize.portfolio

Modified: pkg/PortfolioAnalytics/R/optimize.portfolio.R
===================================================================
--- pkg/PortfolioAnalytics/R/optimize.portfolio.R	2013-08-30 22:02:53 UTC (rev 2946)
+++ pkg/PortfolioAnalytics/R/optimize.portfolio.R	2013-08-31 00:39:21 UTC (rev 2947)
@@ -490,15 +490,33 @@
   constraints <- get_constraints(portfolio)
   
   # set portfolio moments only once
+  # For set.portfolio.moments, we are passing the returns,
+  # portfolio object, and dotargs. dotargs is a list of arguments
+  # that are passed in as dots in optimize.portfolio. This was
+  # causing errors if clean="boudt" was specified in an objective
+  # and an argument such as itermax was passed in as dots to 
+  # optimize.portfolio. See r2931
   if(!is.function(momentFUN)){
     momentFUN <- match.fun(momentFUN)
   }	
   # TODO FIXME should match formals later
   #dotargs <- set.portfolio.moments(R, constraints, momentargs=dotargs)
   .mformals <- dotargs
-  .mformals$R <- R
-  .mformals$portfolio <- portfolio
-  mout <- try((do.call(momentFUN,.mformals)) ,silent=TRUE)	
+  #.mformals$R <- R
+  #.mformals$portfolio <- portfolio
+  .formals <- formals(momentFUN)
+  onames <- names(.formals)
+  if (length(.mformals)) {
+    dargs <- .mformals
+    pm <- pmatch(names(dargs), onames, nomatch = 0L)
+    names(dargs[pm > 0L]) <- onames[pm]
+    .formals[pm] <- dargs[pm > 0L]
+  }
+  .formals$R <- R
+  .formals$portfolio <- portfolio
+  .formals$... <- NULL
+
+  mout <- try((do.call(momentFUN, .formals)) ,silent=TRUE)
   if(inherits(mout,"try-error")) { 
     message(paste("portfolio moment function failed with message",mout))
   } else {

Modified: pkg/PortfolioAnalytics/sandbox/testing_risk_budget.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/testing_risk_budget.R	2013-08-30 22:02:53 UTC (rev 2946)
+++ pkg/PortfolioAnalytics/sandbox/testing_risk_budget.R	2013-08-31 00:39:21 UTC (rev 2947)
@@ -54,12 +54,14 @@
 # clean.boudt.
 # Error in clean.boudt(na.omit(R[, column, drop = FALSE]), alpha = alpha,  : 
 #                       unused argument(s) (itermax = 50)
+
+# The error appears to have been fixed
 set.seed(1234)
 opt <- optimize.portfolio(R=R.clean, portfolio=min_conc_clean, 
                           optimize_method="DEoptim", search_size=5000,
                           itermax=50)
-traceback()
 
+
 # Upon insepecting traceback(), it looks like the error is due to
 # Return.clean(R, method = objective$arguments.clean, ...) where the dots
 # are picking up the dots arguments from optimize.portfolio. Is there a way



More information about the Returnanalytics-commits mailing list