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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Aug 24 22:12:25 CEST 2013


Author: rossbennett34
Date: 2013-08-24 22:12:25 +0200 (Sat, 24 Aug 2013)
New Revision: 2876

Removed:
   pkg/PortfolioAnalytics/man/chart.Weights.EF.Rd
Modified:
   pkg/PortfolioAnalytics/NAMESPACE
   pkg/PortfolioAnalytics/R/charts.efficient.frontier.R
Log:
Making chart.Weights.EF a generic method to work on efficient.frontier and optimize.portfolio objects.

Modified: pkg/PortfolioAnalytics/NAMESPACE
===================================================================
--- pkg/PortfolioAnalytics/NAMESPACE	2013-08-24 19:38:40 UTC (rev 2875)
+++ pkg/PortfolioAnalytics/NAMESPACE	2013-08-24 20:12:25 UTC (rev 2876)
@@ -19,6 +19,8 @@
 export(chart.Scatter.ROI)
 export(chart.Scatter.RP)
 export(chart.Weights.DE)
+export(chart.Weights.EF.efficient.frontier)
+export(chart.Weights.EF.optimize.portfolio)
 export(chart.Weights.EF)
 export(chart.Weights.GenSA)
 export(chart.Weights.optimize.portfolio.DEoptim)

Modified: pkg/PortfolioAnalytics/R/charts.efficient.frontier.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.efficient.frontier.R	2013-08-24 19:38:40 UTC (rev 2875)
+++ pkg/PortfolioAnalytics/R/charts.efficient.frontier.R	2013-08-24 20:12:25 UTC (rev 2876)
@@ -184,6 +184,8 @@
 #' @param object object of class 'efficient.frontier' created by \code{\link{create.EfficientFrontier}}.
 #' @param colorset color palette to use.
 #' @param ... passthrough parameters to \code{barplot}.
+#' @param n.portfolios number of portfolios to extract along the efficient frontier.
+#' This is only used for objects of class \code{optimize.portfolio}
 #' @param match.col match.col string name of column to use for risk (horizontal axis).
 #' Must match the name of an objective.
 #' @param main main title used in the plot.
@@ -194,7 +196,13 @@
 #' @param element.color provides the color for drawing less-important chart elements, such as the box lines, axis lines, etc.
 #' @author Ross Bennett
 #' @export
-chart.Weights.EF <- function(object, colorset=NULL, ..., match.col="ES", main="EF Weights", cex.lab=0.8, cex.axis=0.8, cex.legend=0.8, legend.labels=NULL, element.color="darkgray"){
+chart.Weights.EF <- function(object, colorset=NULL, ..., n.portfolios=25, match.col="ES", main="EF Weights", cex.lab=0.8, cex.axis=0.8, cex.legend=0.8, legend.labels=NULL, element.color="darkgray"){
+UseMethod("chart.Weights.EF")
+}
+
+#' @rdname chart.Weights.EF
+#' @export
+chart.Weights.EF.efficient.frontier <- function(object, colorset=NULL, ..., n.portfolios=25, match.col="ES", main="EF Weights", cex.lab=0.8, cex.axis=0.8, cex.legend=0.8, legend.labels=NULL, element.color="darkgray"){
   # using ideas from weightsPlot.R in fPortfolio package
   
   if(!inherits(object, "efficient.frontier")) stop("object must be of class 'efficient.frontier'")
@@ -283,6 +291,20 @@
   box(col=element.color)
 }
 
+#' @rdname chart.Weights.EF
+#' @export
+chart.Weights.EF.optimize.portfolio <- function(object, colorset=NULL, ..., n.portfolios=25, match.col="ES", main="EF Weights", cex.lab=0.8, cex.axis=0.8, cex.legend=0.8, legend.labels=NULL, element.color="darkgray"){
+  # chart the weights along the efficient frontier of an objected created by optimize.portfolio
+  
+  if(!inherits(object, "optimize.portfolio")) stop("object must be of class optimize.portfolio")
+  
+  frontier <- extractEfficientFrontier(object=object, match.col=match.col, n.portfolios=n.portfolios)
+  PortfolioAnalytics:::chart.Weights.EF(object=frontier, colorset=colorset, ..., 
+                                        match.col=match.col, main=main, cex.lab=cex.lab, 
+                                        cex.axis=cex.axis, cex.legend=cex.legend, 
+                                        legend.labels=legend.labels, element.color=element.color)
+}
+
 #' @rdname chart.EfficientFrontier
 #' @export
 chart.EfficientFrontier.efficient.frontier <- function(object, chart.assets=TRUE, match.col="ES", n.portfolios=NULL, xlim=NULL, ylim=NULL, cex.axis=0.8, element.color="darkgray", main="Efficient Frontier", ...){

Deleted: pkg/PortfolioAnalytics/man/chart.Weights.EF.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/chart.Weights.EF.Rd	2013-08-24 19:38:40 UTC (rev 2875)
+++ pkg/PortfolioAnalytics/man/chart.Weights.EF.Rd	2013-08-24 20:12:25 UTC (rev 2876)
@@ -1,49 +0,0 @@
-\name{chart.Weights.EF}
-\alias{chart.Weights.EF}
-\title{chart the weights along the efficient frontier}
-\usage{
-  chart.Weights.EF(object, colorset = NULL, ...,
-    match.col = "ES", main = "EF Weights", cex.lab = 0.8,
-    cex.axis = 0.8, cex.legend = 0.8, legend.labels = NULL,
-    element.color = "darkgray")
-}
-\arguments{
-  \item{object}{object of class 'efficient.frontier'
-  created by \code{\link{create.EfficientFrontier}}.}
-
-  \item{colorset}{color palette to use.}
-
-  \item{...}{passthrough parameters to \code{barplot}.}
-
-  \item{match.col}{match.col string name of column to use
-  for risk (horizontal axis). Must match the name of an
-  objective.}
-
-  \item{main}{main title used in the plot.}
-
-  \item{cex.lab}{The magnification to be used for x- and
-  y-axis labels relative to the current setting of 'cex'.}
-
-  \item{cex.axis}{The magnification to be used for sizing
-  the axis text relative to the current setting of 'cex',
-  similar to \code{\link{plot}}.}
-
-  \item{cex.legend}{The magnification to be used for sizing
-  the legend relative to the current setting of 'cex',
-  similar to \code{\link{plot}}.}
-
-  \item{legend.labels}{character vector to use for the
-  legend labels}
-
-  \item{element.color}{provides the color for drawing
-  less-important chart elements, such as the box lines,
-  axis lines, etc.}
-}
-\description{
-  This creates a stacked column chart of the weights of
-  portfolios along the efficient frontier.
-}
-\author{
-  Ross Bennett
-}
-



More information about the Returnanalytics-commits mailing list