[Returnanalytics-commits] r3283 - pkg/PortfolioAnalytics/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Dec 16 06:28:37 CET 2013
Author: rossbennett34
Date: 2013-12-16 06:28:36 +0100 (Mon, 16 Dec 2013)
New Revision: 3283
Modified:
pkg/PortfolioAnalytics/R/applyFUN.R
pkg/PortfolioAnalytics/R/extract.efficient.frontier.R
Log:
Cleaning up applyFUN and efficient frontiers
Modified: pkg/PortfolioAnalytics/R/applyFUN.R
===================================================================
--- pkg/PortfolioAnalytics/R/applyFUN.R 2013-12-16 05:26:32 UTC (rev 3282)
+++ pkg/PortfolioAnalytics/R/applyFUN.R 2013-12-16 05:28:36 UTC (rev 3283)
@@ -6,7 +6,7 @@
#' @param R xts object of asset returns
#' @param weights a matrix of weights generated from random_portfolios or \code{optimize.portfolio}
#' @param FUN name of a function
-#' @param ... any passthrough arguments to FUN
+#' @param arguments named list of arguments to FUN
#' @author Ross Bennett
#' @export
applyFUN <- function(R, weights, FUN="mean", arguments){
@@ -92,11 +92,15 @@
#'
#' @param R xts object of asset returns
#' @param FUN name of function
-#' @param ... any passthrough arguments to FUN
+#' @param arguments named list of arguments to FUN
#' @author Ross Bennett
#' @export
-scatterFUN <- function(R, FUN, arguments){
- nargs <- arguments
+scatterFUN <- function(R, FUN, arguments=NULL){
+ if(is.null(arguments)){
+ nargs <- list()
+ } else{
+ nargs <- arguments
+ }
# match the FUN arg to a risk or return function
switch(FUN,
Modified: pkg/PortfolioAnalytics/R/extract.efficient.frontier.R
===================================================================
--- pkg/PortfolioAnalytics/R/extract.efficient.frontier.R 2013-12-16 05:26:32 UTC (rev 3282)
+++ pkg/PortfolioAnalytics/R/extract.efficient.frontier.R 2013-12-16 05:28:36 UTC (rev 3283)
@@ -184,6 +184,7 @@
}
colnames(out) <- c("mean", names(stats))
}
+ out <- na.omit(out)
return(structure(out, class="frontier"))
}
@@ -257,8 +258,7 @@
# length.out is the number of portfolios to create
ret_seq <- seq(from=minret, to=maxret, length.out=n.portfolios)
- out <- matrix(0, nrow=length(ret_seq), ncol=length(extractStats(tmp)))
-
+# out <- matrix(0, nrow=length(ret_seq), ncol=length(extractStats(tmp)))
# for(i in 1:length(ret_seq)){
# portfolio$objectives[[mean_idx]]$target <- ret_seq[i]
# out[i, ] <- extractStats(optimize.portfolio(R=R, portfolio=portfolio, optimize_method="ROI"))
@@ -269,6 +269,7 @@
extractStats(optimize.portfolio(R=R, portfolio=portfolio, optimize_method="ROI", ef=TRUE, ...=...))
}
colnames(out) <- names(stats)
+ out <- na.omit(out)
return(structure(out, class="frontier"))
}
More information about the Returnanalytics-commits
mailing list