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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 23 23:37:13 CEST 2013


Author: rossbennett34
Date: 2013-09-23 23:37:13 +0200 (Mon, 23 Sep 2013)
New Revision: 3173

Added:
   pkg/PortfolioAnalytics/R/equal.weight.R
   pkg/PortfolioAnalytics/man/equal.weight.Rd
Modified:
   pkg/PortfolioAnalytics/DESCRIPTION
   pkg/PortfolioAnalytics/NAMESPACE
   pkg/PortfolioAnalytics/man/plot.Rd
Log:
Adding function calculate objective_measures for an equal weight portfolio

Modified: pkg/PortfolioAnalytics/DESCRIPTION
===================================================================
--- pkg/PortfolioAnalytics/DESCRIPTION	2013-09-23 21:32:51 UTC (rev 3172)
+++ pkg/PortfolioAnalytics/DESCRIPTION	2013-09-23 21:37:13 UTC (rev 3173)
@@ -59,3 +59,4 @@
     'charts.groups.R'
     'charts.multiple.R'
     'utility.combine.R'
+    'equal.weight.R'

Modified: pkg/PortfolioAnalytics/NAMESPACE
===================================================================
--- pkg/PortfolioAnalytics/NAMESPACE	2013-09-23 21:32:51 UTC (rev 3172)
+++ pkg/PortfolioAnalytics/NAMESPACE	2013-09-23 21:37:13 UTC (rev 3173)
@@ -18,6 +18,7 @@
 export(create.EfficientFrontier)
 export(diversification_constraint)
 export(diversification)
+export(equal.weight)
 export(extract.efficient.frontier)
 export(extractEfficientFrontier)
 export(extractGroups)

Added: pkg/PortfolioAnalytics/R/equal.weight.R
===================================================================
--- pkg/PortfolioAnalytics/R/equal.weight.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/R/equal.weight.R	2013-09-23 21:37:13 UTC (rev 3173)
@@ -0,0 +1,50 @@
+
+
+#' Create an equal weight portfolio
+#' 
+#' This function calculates objective measures for an equal weight portfolio.
+#' 
+#' @details
+#' This function is simply a wrapper around \code{\link{constrained_objective}}
+#' to calculate the objective measures in the given \code{portfolio} object of
+#' an equal weight portfolio. The portfolio object should include all objectives
+#' to be calculated.
+#' 
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns
+#' @param portfolio an object of type "portfolio" specifying the constraints and objectives for the optimization
+#' @param \dots any other passthru parameters to \code{constrained_objective}
+#' @return a list containing the returns, weights, objective measures, call, and portfolio object
+#' @author Ross Bennett
+#' @export
+equal.weight <- function(R, portfolio, ...){
+  # Check for portfolio object passed in
+  if(!is.portfolio(portfolio)) stop("portfolio object passed in must be of class 'portfolio'")
+  
+  # get asset information for equal weight portfolio
+  assets <- portfolio$assets
+  nassets <- length(assets)
+  weights <- rep(1 / nassets, nassets)
+  names(weights) <- names(assets)
+  
+  # make sure the number of columns in R matches the number of assets
+  if(ncol(R) != nassets){
+    if(ncol(R) > nassets){
+      R <- R[, 1:nassets]
+      warning("number of assets is less than number of columns in returns object, subsetting returns object.")
+    } else {
+      stop("number of assets is greater than number of columns in returns object")
+    }
+  }
+  
+  out <- constrained_objective(w=weights, R=R, portfolio=portfolio, trace=TRUE, ...)$objective_measures
+  return(structure(list(
+    R=R,
+    weights=weights,
+    objective_measures=out,
+    call=match.call(),
+    portfolio=portfolio),
+                   class=c("optimize.portfolio.eqwt", "optimize.portfolio"))
+  )
+}
+
+

Added: pkg/PortfolioAnalytics/man/equal.weight.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/equal.weight.Rd	                        (rev 0)
+++ pkg/PortfolioAnalytics/man/equal.weight.Rd	2013-09-23 21:37:13 UTC (rev 3173)
@@ -0,0 +1,35 @@
+\name{equal.weight}
+\alias{equal.weight}
+\title{Create an equal weight portfolio}
+\usage{
+  equal.weight(R, portfolio, ...)
+}
+\arguments{
+  \item{R}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of asset returns}
+
+  \item{portfolio}{an object of type "portfolio" specifying
+  the constraints and objectives for the optimization}
+
+  \item{\dots}{any other passthru parameters to
+  \code{constrained_objective}}
+}
+\value{
+  a list containing the returns, weights, objective
+  measures, call, and portfolio object
+}
+\description{
+  This function calculates objective measures for an equal
+  weight portfolio.
+}
+\details{
+  This function is simply a wrapper around
+  \code{\link{constrained_objective}} to calculate the
+  objective measures in the given \code{portfolio} object
+  of an equal weight portfolio. The portfolio object should
+  include all objectives to be calculated.
+}
+\author{
+  Ross Bennett
+}
+

Modified: pkg/PortfolioAnalytics/man/plot.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/plot.Rd	2013-09-23 21:32:51 UTC (rev 3172)
+++ pkg/PortfolioAnalytics/man/plot.Rd	2013-09-23 21:37:13 UTC (rev 3173)
@@ -1,4 +1,4 @@
-\name{plot}
+\name{plot.optimize}
 \alias{plot.optimize.portfolio}
 \alias{plot.optimize.portfolio.DEoptim}
 \alias{plot.optimize.portfolio.GenSA}



More information about the Returnanalytics-commits mailing list