[Returnanalytics-commits] r2807 - pkg/PortfolioAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Aug 17 20:01:03 CEST 2013


Author: rossbennett34
Date: 2013-08-17 20:01:02 +0200 (Sat, 17 Aug 2013)
New Revision: 2807

Modified:
   pkg/PortfolioAnalytics/R/extractstats.R
Log:
adding function to extract the $objective_measures slot

Modified: pkg/PortfolioAnalytics/R/extractstats.R
===================================================================
--- pkg/PortfolioAnalytics/R/extractstats.R	2013-08-17 16:39:51 UTC (rev 2806)
+++ pkg/PortfolioAnalytics/R/extractstats.R	2013-08-17 18:01:02 UTC (rev 2807)
@@ -333,3 +333,26 @@
   names(result) <- rnames
   return(result)
 }
+
+#' Extract the objective measures
+#' 
+#' This function will extract the objective measures from the optimal portfolio
+#' run via \code{optimize.portfolio}
+#'  
+#' @param object list returned by optimize.portfolio
+#' @return list of objective measures
+#' @seealso \code{\link{optimize.portfolio}}
+#' @author Ross Bennett
+#' @export
+extractObjectiveMeasures <- function(object){
+  if(!inherits(object, "optimize.portfolio")) stop("object must be of class 'optimize.portfolio'")
+  if(inherits(object, "optimize.portfolio.ROI")){
+    # objective measures returned as $out for ROI solvers
+    out <- object$out
+  } else {
+    # objective measures returned as $objective_measures for all other solvers
+    out <- object$objective_measures
+  }
+  return(out)
+}
+



More information about the Returnanalytics-commits mailing list