[Returnanalytics-commits] r2673 - in pkg/PortfolioAnalytics: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 29 23:32:17 CEST 2013


Author: rossbennett34
Date: 2013-07-29 23:32:16 +0200 (Mon, 29 Jul 2013)
New Revision: 2673

Added:
   pkg/PortfolioAnalytics/man/extractWeights.Rd
   pkg/PortfolioAnalytics/man/extractWeights.optimize.portfolio.Rd
   pkg/PortfolioAnalytics/man/extractWeights.optimize.portfolio.rebalancing.Rd
Modified:
   pkg/PortfolioAnalytics/NAMESPACE
   pkg/PortfolioAnalytics/R/extractstats.R
Log:
making extractWeights a generic method to work on objects created from optimize.portfolio as well as optimize.portfolio.rebalancing

Modified: pkg/PortfolioAnalytics/NAMESPACE
===================================================================
--- pkg/PortfolioAnalytics/NAMESPACE	2013-07-29 17:59:32 UTC (rev 2672)
+++ pkg/PortfolioAnalytics/NAMESPACE	2013-07-29 21:32:16 UTC (rev 2673)
@@ -26,7 +26,9 @@
 export(extractStats.optimize.portfolio.random)
 export(extractStats.optimize.portfolio.ROI)
 export(extractStats)
-export(extractWeights.rebal)
+export(extractWeights.optimize.portfolio.rebalancing)
+export(extractWeights.optimize.portfolio)
+export(extractWeights)
 export(fn_map)
 export(generatesequence)
 export(get_constraints)

Modified: pkg/PortfolioAnalytics/R/extractstats.R
===================================================================
--- pkg/PortfolioAnalytics/R/extractstats.R	2013-07-29 17:59:32 UTC (rev 2672)
+++ pkg/PortfolioAnalytics/R/extractstats.R	2013-07-29 21:32:16 UTC (rev 2673)
@@ -151,8 +151,35 @@
   return(result)
 }
 
-#' extract time series of weights from output of optimize.portfolio
+#' extract weights from a portfolio run via \code{optimize.portfolio} or \code{optimize.portfolio.rebalancing}
 #' 
+#' This function will dispatch to the appropriate class handler based on the
+#' input class of the optimize.portfolio or optimize.portfolio.rebalancing output object
+#'  
+#' @param object list returned by optimize.portfolio
+#' @param ... any other passthru parameters
+#' @seealso \code{\link{optimize.portfolio}}, \code{\link{optimize.portfolio.rebalancing}}
+#' @export
+extractWeights <- function (object, ...){
+  UseMethod('extractWeights')
+}
+
+#' extract weights from output of optimize.portfolio
+#' 
+#' @param object object of type optimize.portfolio to extract weights from
+#' @seealso 
+#' \code{\link{optimize.portfolio}}
+#' @author Ross Bennett
+#' @export
+extractWeights.optimize.portfolio <- function(object){
+  if(!inherits(object, "optimize.portfolio")){
+    stop("object must be of class 'optimize.portfolio'")
+  }
+  return(object$weights)
+}
+
+#' extract time series of weights from output of optimize.portfolio.rebalancing
+#' 
 #' \code{\link{optimize.portfolio.rebalancing}} outputs a list of
 #' \code{\link{optimize.portfolio}} objects, one for each rebalancing period
 #' 
@@ -163,8 +190,13 @@
 #' @seealso 
 #' \code{\link{optimize.portfolio.rebalancing}}
 #' @export
-extractWeights.rebal <- function(RebalResults, ...){
+extractWeights.optimize.portfolio.rebalancing <- function(RebalResults, ...){
 # @TODO: add a class check for the input object
+# FIXED
+  if(!inherits(RebalResults, "optimize.portfolio.rebalancing")){
+    stop("Object passed in must be of class 'optimize.portfolio.rebalancing'")
+  }
+  
   numColumns = length(RebalResults[[1]]$weights)
   numRows = length(RebalResults)
 

Added: pkg/PortfolioAnalytics/man/extractWeights.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/extractWeights.Rd	                        (rev 0)
+++ pkg/PortfolioAnalytics/man/extractWeights.Rd	2013-07-29 21:32:16 UTC (rev 2673)
@@ -0,0 +1,22 @@
+\name{extractWeights}
+\alias{extractWeights}
+\title{extract weights from a portfolio run via \code{optimize.portfolio} or \code{optimize.portfolio.rebalancing}}
+\usage{
+  extractWeights(object, ...)
+}
+\arguments{
+  \item{object}{list returned by optimize.portfolio}
+
+  \item{...}{any other passthru parameters}
+}
+\description{
+  This function will dispatch to the appropriate class
+  handler based on the input class of the
+  optimize.portfolio or optimize.portfolio.rebalancing
+  output object
+}
+\seealso{
+  \code{\link{optimize.portfolio}},
+  \code{\link{optimize.portfolio.rebalancing}}
+}
+

Added: pkg/PortfolioAnalytics/man/extractWeights.optimize.portfolio.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/extractWeights.optimize.portfolio.Rd	                        (rev 0)
+++ pkg/PortfolioAnalytics/man/extractWeights.optimize.portfolio.Rd	2013-07-29 21:32:16 UTC (rev 2673)
@@ -0,0 +1,20 @@
+\name{extractWeights.optimize.portfolio}
+\alias{extractWeights.optimize.portfolio}
+\title{extract weights from output of optimize.portfolio}
+\usage{
+  extractWeights.optimize.portfolio(object)
+}
+\arguments{
+  \item{object}{object of type optimize.portfolio to
+  extract weights from}
+}
+\description{
+  extract weights from output of optimize.portfolio
+}
+\author{
+  Ross Bennett
+}
+\seealso{
+  \code{\link{optimize.portfolio}}
+}
+

Added: pkg/PortfolioAnalytics/man/extractWeights.optimize.portfolio.rebalancing.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/extractWeights.optimize.portfolio.rebalancing.Rd	                        (rev 0)
+++ pkg/PortfolioAnalytics/man/extractWeights.optimize.portfolio.rebalancing.Rd	2013-07-29 21:32:16 UTC (rev 2673)
@@ -0,0 +1,26 @@
+\name{extractWeights.optimize.portfolio.rebalancing}
+\alias{extractWeights.optimize.portfolio.rebalancing}
+\title{extract time series of weights from output of optimize.portfolio.rebalancing}
+\usage{
+  extractWeights.optimize.portfolio.rebalancing(RebalResults,
+    ...)
+}
+\arguments{
+  \item{RebalResults}{object of type
+  optimize.portfolio.rebalancing to extract weights from}
+
+  \item{...}{any other passthru parameters}
+}
+\description{
+  \code{\link{optimize.portfolio.rebalancing}} outputs a
+  list of \code{\link{optimize.portfolio}} objects, one for
+  each rebalancing period
+}
+\details{
+  The output list is indexed by the dates of the
+  rebalancing periods, as determined by \code{endpoints}
+}
+\seealso{
+  \code{\link{optimize.portfolio.rebalancing}}
+}
+



More information about the Returnanalytics-commits mailing list