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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 20 20:53:26 CEST 2012


Author: hezkyvaron
Date: 2012-08-20 20:53:26 +0200 (Mon, 20 Aug 2012)
New Revision: 2257

Added:
   pkg/PortfolioAnalytics/sandbox/extractStats.dev.R
Log:
- added a file to develop extractStats routines

Added: pkg/PortfolioAnalytics/sandbox/extractStats.dev.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/extractStats.dev.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/sandbox/extractStats.dev.R	2012-08-20 18:53:26 UTC (rev 2257)
@@ -0,0 +1,42 @@
+#' extract some stats from a portfolio list run with ROI via
+#' \code{\link{optimize.portfolio}}
+#' 
+#' This function will take everything in the objective_measures slot and \code{unlist} it.  
+#' This may produce a very large number of columns or strange column names.
+#' 
+#' @param object list returned by optimize.portfolio
+#' @param prefix prefix to add to output row names
+#' @param ... any other passthru parameters
+#' @seealso \code{\link{optimize.portfolio}}
+#' @export 
+extractStats.optimize.portfolio.ROI <- function(object, prefix=NULL, ...) {
+  
+  trow<-c(out=object$out, object$weights)
+  result<-trow
+  
+  rnames<-c('out',paste('w',names(object$weights),sep='.'))
+  names(result)<-rnames
+  return(result)
+}
+
+
+#' extract some stats from a portfolio list run with pso via
+#' \code{\link{optimize.portfolio}}
+#' 
+#' This function will take everything in the objective_measures slot and \code{unlist} it.  
+#' This may produce a very large number of columns or strange column names.
+#' 
+#' @param object list returned by optimize.portfolio
+#' @param prefix prefix to add to output row names
+#' @param ... any other passthru parameters
+#' @seealso \code{\link{optimize.portfolio}}
+#' @export 
+extractStats.optimize.portfolio.pso <- function(object, prefix=NULL, ...) {
+  
+  trow<-c(out=object$out, object$weights)
+  result<-trow
+  
+  rnames<-c('out',paste('w',names(object$weights),sep='.'))
+  names(result)<-rnames
+  return(result)
+}
\ No newline at end of file



More information about the Returnanalytics-commits mailing list