[Returnanalytics-commits] r1938 - pkg/PortfolioAnalytics/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu May 3 22:58:29 CEST 2012
Author: braverock
Date: 2012-05-03 22:58:29 +0200 (Thu, 03 May 2012)
New Revision: 1938
Modified:
pkg/PortfolioAnalytics/R/optimize.portfolio.R
Log:
- add momentFUN argument to optimize.portfolio
Modified: pkg/PortfolioAnalytics/R/optimize.portfolio.R
===================================================================
--- pkg/PortfolioAnalytics/R/optimize.portfolio.R 2012-05-03 09:55:09 UTC (rev 1937)
+++ pkg/PortfolioAnalytics/R/optimize.portfolio.R 2012-05-03 20:58:29 UTC (rev 1938)
@@ -41,6 +41,7 @@
#' @param trace TRUE/FALSE if TRUE will attempt to return additional information on the path or portfolios searched
#' @param \dots any other passthru parameters
#' @param rp matrix of random portfolio weights, default NULL, mostly for automated use by rebalancing optimization or repeated tests on same portfolios
+#' @param momentFUN the name of a function to call to set portfolio moments, default \code{\link{set.portfolio.moments}}
#' @callGraph
#' @return a list containing the optimal weights, some summary statistics, the function call, and optionally trace information
#' @author Kris Boudt, Peter Carl, Brian G. Peterson
@@ -72,8 +73,21 @@
dotargs <-list(...)
# set portfolio moments only once
- dotargs <- set.portfolio.moments(R, constraints, momentargs=dotargs)
-
+ 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$constraints <- constraints
+ mout <- try((do.call(momentFUN,.mformals)) ,silent=TRUE)
+ if(inherits(mout,"try-error")) {
+ message(paste("portfolio moment function failed with message",mout))
+ } else {
+ dotargs <- mout
+ }
+
normalize_weights <- function(weights){
# normalize results if necessary
if(!is.null(constraints$min_sum) | !is.null(constraints$max_sum)){
More information about the Returnanalytics-commits
mailing list