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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 20 19:05:15 CEST 2013


Author: rossbennett34
Date: 2013-08-20 19:05:15 +0200 (Tue, 20 Aug 2013)
New Revision: 2837

Added:
   pkg/PortfolioAnalytics/R/chart.RiskReward.R
   pkg/PortfolioAnalytics/R/chart.Weights.R
   pkg/PortfolioAnalytics/man/chart.RiskReward.Rd
Modified:
   pkg/PortfolioAnalytics/DESCRIPTION
   pkg/PortfolioAnalytics/NAMESPACE
   pkg/PortfolioAnalytics/R/charts.DE.R
   pkg/PortfolioAnalytics/R/charts.GenSA.R
   pkg/PortfolioAnalytics/R/charts.PSO.R
   pkg/PortfolioAnalytics/R/charts.ROI.R
   pkg/PortfolioAnalytics/R/charts.RP.R
   pkg/PortfolioAnalytics/man/chart.Scatter.DE.Rd
   pkg/PortfolioAnalytics/man/chart.Scatter.ROI.Rd
   pkg/PortfolioAnalytics/man/chart.Scatter.RP.Rd
   pkg/PortfolioAnalytics/man/chart.Scatter.pso.Rd
Log:
adding chart.RiskReward as a generic function

Modified: pkg/PortfolioAnalytics/DESCRIPTION
===================================================================
--- pkg/PortfolioAnalytics/DESCRIPTION	2013-08-20 15:36:33 UTC (rev 2836)
+++ pkg/PortfolioAnalytics/DESCRIPTION	2013-08-20 17:05:15 UTC (rev 2837)
@@ -51,3 +51,4 @@
     'charts.PSO.R'
     'charts.GenSA.R'
     'chart.Weights.R'
+    'chart.RiskReward.R'

Modified: pkg/PortfolioAnalytics/NAMESPACE
===================================================================
--- pkg/PortfolioAnalytics/NAMESPACE	2013-08-20 15:36:33 UTC (rev 2836)
+++ pkg/PortfolioAnalytics/NAMESPACE	2013-08-20 17:05:15 UTC (rev 2837)
@@ -3,6 +3,12 @@
 export(applyFUN)
 export(box_constraint)
 export(CCCgarch.MM)
+export(chart.RiskReward.optimize.portfolio.DEoptim)
+export(chart.RiskReward.optimize.portfolio.GenSA)
+export(chart.RiskReward.optimize.portfolio.pso)
+export(chart.RiskReward.optimize.portfolio.random)
+export(chart.RiskReward.optimize.portfolio.ROI)
+export(chart.RiskReward)
 export(chart.Scatter.DE)
 export(chart.Scatter.GenSA)
 export(chart.Scatter.pso)

Added: pkg/PortfolioAnalytics/R/chart.RiskReward.R
===================================================================
--- pkg/PortfolioAnalytics/R/chart.RiskReward.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/R/chart.RiskReward.R	2013-08-20 17:05:15 UTC (rev 2837)
@@ -0,0 +1,19 @@
+
+
+#' classic risk reward scatter
+#' 
+#' @param object optimal portfolio created by \code{\link{optimize.portfolio}}
+#' @param neighbors set of 'neighbor' portfolios to overplot, see Details in \code{\link{charts.DE}}
+#' @param ... any other passthru parameters 
+#' @param rp TRUE/FALSE. If TRUE, random portfolios are generated by \code{\link{random_portfolios}} to view the feasible space 
+#' @param return.col string matching the objective of a 'return' objective, on vertical axis
+#' @param risk.col string matching the objective of a 'risk' objective, on horizontal axis
+#' @param cex.axis The magnification to be used for axis annotation relative to the current setting of \code{cex}
+#' @param element.color color for the default plot scatter points
+#' @seealso \code{\link{optimize.portfolio}}
+#' @export
+chart.RiskReward <- function(object, neighbors, ..., rp=FALSE, return.col="mean", risk.col="ES", element.color = "darkgray", cex.axis=0.8){
+  UseMethod("chart.RiskReward")
+}
+
+

Added: pkg/PortfolioAnalytics/R/chart.Weights.R
===================================================================
--- pkg/PortfolioAnalytics/R/chart.Weights.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/R/chart.Weights.R	2013-08-20 17:05:15 UTC (rev 2837)
@@ -0,0 +1,26 @@
+
+#' boxplot of the weights of the optimal portfolios
+#' 
+#' Chart the optimal weights and upper and lower bounds on weights of a portfolio run via \code{\link{optimize.portfolio}}
+#' 
+#' @param object optimal portfolio object created by \code{\link{optimize.portfolio}}
+#' @param neighbors set of 'neighbor' portfolios to overplot
+#' @param las numeric in \{0,1,2,3\}; the style of axis labels
+#'       \describe{
+#'         \item{0:}{always parallel to the axis [\emph{default}],}
+#'         \item{1:}{always horizontal,}
+#'         \item{2:}{always perpendicular to the axis,}
+#'         \item{3:}{always vertical.}
+#'       }
+#' @param xlab a title for the x axis: see \code{\link{title}}
+#' @param cex.lab The magnification to be used for x and y labels relative to the current setting of \code{cex}
+#' @param cex.axis The magnification to be used for axis annotation relative to the current setting of \code{cex}
+#' @param element.color color for the default plot lines
+#' @param ... any other passthru parameters 
+#' @param main an overall title for the plot: see \code{\link{title}}
+#' @seealso \code{\link{optimize.portfolio}}
+#' @export
+chart.Weights <- function(object, neighbors = NULL, ..., main="Weights", las = 3, xlab=NULL, cex.lab = 1, element.color = "darkgray", cex.axis=0.8){
+  UseMethod("chart.Weights")
+}
+

Modified: pkg/PortfolioAnalytics/R/charts.DE.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.DE.R	2013-08-20 15:36:33 UTC (rev 2836)
+++ pkg/PortfolioAnalytics/R/charts.DE.R	2013-08-20 17:05:15 UTC (rev 2837)
@@ -75,27 +75,18 @@
 #' @export
 chart.Weights.optimize.portfolio.DEoptim <- chart.Weights.DE
 
-#' classic risk return scatter of DEoptim results
-#' 
-#' @param DE set of portfolios created by \code{\link{optimize.portfolio}}
-#' @param neighbors set of 'neighbor' portfolios to overplot, see Details in \code{\link{charts.DE}}
-#' @param return.col string matching the objective of a 'return' objective, on vertical axis
-#' @param risk.col string matching the objective of a 'risk' objective, on horizontal axis
-#' @param ... any other passthru parameters 
-#' @param cex.axis The magnification to be used for axis annotation relative to the current setting of \code{cex}
-#' @param element.color color for the default plot scatter points
-#' @seealso \code{\link{optimize.portfolio}}
+#' @rdname chart.RiskReward
 #' @export
-chart.Scatter.DE <- function(DE, neighbors = NULL, return.col='mean', risk.col='ES', ..., element.color = "darkgray", cex.axis=0.8){
+chart.Scatter.DE <- function(object, neighbors = NULL, ..., return.col='mean', risk.col='ES', element.color = "darkgray", cex.axis=0.8){
   # more or less specific to the output of the DEoptim portfolio code with constraints
   # will work to a point with other functions, such as optimize.porfolio.parallel
   # there's still a lot to do to improve this.
   
-  if(!inherits(DE, "optimize.portfolio.DEoptim")) stop("DE must be of class 'optimize.portfolio.DEoptim'")
+  if(!inherits(object, "optimize.portfolio.DEoptim")) stop("object must be of class 'optimize.portfolio.DEoptim'")
   
-  R <- DE$R
-  portfolio <- DE$portfolio
-  xtract = extractStats(DE)
+  R <- object$R
+  portfolio <- object$portfolio
+  xtract = extractStats(object)
   columnnames = colnames(xtract)
   #return.column = grep(paste("objective_measures",return.col,sep='.'),columnnames)
   return.column = pmatch(return.col,columnnames)
@@ -176,8 +167,8 @@
   }
   
   #     points(xtract[1,risk.column],xtract[1,return.column], col="orange", pch=16) # overplot the equal weighted (or seed)
-  #check to see if portfolio 1 is EW  DE$random_portoflios[1,] all weights should be the same
-  #     if(!isTRUE(all.equal(DE$random_portfolios[1,][1],1/length(DE$random_portfolios[1,]),check.attributes=FALSE))){
+  #check to see if portfolio 1 is EW  object$random_portoflios[1,] all weights should be the same
+  #     if(!isTRUE(all.equal(object$random_portfolios[1,][1],1/length(object$random_portfolios[1,]),check.attributes=FALSE))){
   #show both the seed and EW if they are different 
   #NOTE the all.equal comparison could fail above if the first element of the first portfolio is the same as the EW weight, 
   #but the rest is not, shouldn't happen often with real portfolios, only toy examples
@@ -186,7 +177,7 @@
   
   ## Draw solution trajectory
   if(!is.null(R) & !is.null(portfolio)){
-    w.traj = unique(DE$DEoutput$member$bestmemit)
+    w.traj = unique(object$DEoutput$member$bestmemit)
     rows = nrow(w.traj)
     rr = matrix(nrow=rows, ncol=2)
     ## maybe rewrite as an apply statement by row on w.traj
@@ -227,12 +218,12 @@
   
   
   ## @TODO: Generalize this to find column containing the "risk" metric
-  if(length(names(DE)[which(names(DE)=='constrained_objective')])) {
+  if(length(names(object)[which(names(object)=='constrained_objective')])) {
     result.slot<-'constrained_objective'
   } else {
     result.slot<-'objective_measures'
   }
-  objcols<-unlist(DE[[result.slot]])
+  objcols<-unlist(object[[result.slot]])
   names(objcols)<-name.replace(names(objcols))
   return.column = pmatch(return.col,names(objcols))
   if(is.na(return.column)) {
@@ -250,7 +241,7 @@
     return.col <- gsub("\\..*", "", return.col)
     risk.col <- gsub("\\..*", "", risk.col)
     # warning(return.col,' or ', risk.col, ' do  not match extractStats output of $objective_measures slot')
-    opt_weights <- DE$weights
+    opt_weights <- object$weights
     ret <- as.numeric(applyFUN(R=R, weights=opt_weights, FUN=return.col))
     risk <- as.numeric(applyFUN(R=R, weights=opt_weights, FUN=risk.col))
     points(risk, ret, col="blue", pch=16) #optimal
@@ -262,6 +253,9 @@
   box(col = element.color)
 }
 
+#' @rdname chart.RiskReward
+#' @export
+chart.RiskReward.optimize.portfolio.DEoptim <- chart.Scatter.DE
 
 #' scatter and weights chart  for random portfolios
 #' 
@@ -290,9 +284,9 @@
     op <- par(no.readonly=TRUE)
     layout(matrix(c(1,2)),height=c(2,1.5),width=1)
     par(mar=c(4,4,4,2))
-    chart.Scatter.DE(DE, risk.col=risk.col, return.col=return.col, neighbors=neighbors, main=main, ...)
+    chart.Scatter.DE(object=DE, risk.col=risk.col, return.col=return.col, neighbors=neighbors, main=main, ...)
     par(mar=c(2,4,0,2))
-    chart.Weights.DE(DE, main="", neighbors=neighbors, ...)
+    chart.Weights.DE(object=DE, main="", neighbors=neighbors, ...)
     par(op)
 }
 

Modified: pkg/PortfolioAnalytics/R/charts.GenSA.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.GenSA.R	2013-08-20 15:36:33 UTC (rev 2836)
+++ pkg/PortfolioAnalytics/R/charts.GenSA.R	2013-08-20 17:05:15 UTC (rev 2837)
@@ -63,38 +63,22 @@
 #' @export
 chart.Weights.optimize.portfolio.GenSA <- chart.Weights.GenSA
 
-#' classic risk return scatter of random portfolios
-#' 
-#' The GenSA optimizer does not store the portfolio weights like DEoptim or random
-#' portfolios so we will generate random portfolios for the scatter plot. 
-#' 
-#' \code{return.col} must be the name of a function used to compute the return metric on the random portfolio weights
-#' \code{risk.col} must be the name of a function used to compute the risk metric on the random portfolio weights
-#' 
-#' @param GenSA object created by \code{\link{optimize.portfolio}}
-#' @param rp set of weights generated by \code{\link{random_portfolio}}
-#' @param return.col string matching the objective of a 'return' objective, on vertical axis
-#' @param risk.col string matching the objective of a 'risk' objective, on horizontal axis
-#' @param ... any other passthru parameters 
-#' @param cex.axis The magnification to be used for axis annotation relative to the current setting of \code{cex}
-#' @param element.color color for the default plot scatter points
-#' @seealso \code{\link{optimize.portfolio}}
-#' @author Ross Bennett
+#' @rdname chart.RiskReward
 #' @export
-chart.Scatter.GenSA <- function(GenSA, rp=NULL, return.col="mean", risk.col="StdDev", ..., element.color = "darkgray", cex.axis=0.8, main=""){
+chart.Scatter.GenSA <- function(object, neighbors=NULL, ..., rp=FALSE, return.col="mean", risk.col="ES", element.color="darkgray", cex.axis=0.8){
   
-  if(!inherits(GenSA, "optimize.portfolio.GenSA")) stop("GenSA must be of class 'optimize.portfolio.GenSA'")
+  if(!inherits(object, "optimize.portfolio.GenSA")) stop("object must be of class 'optimize.portfolio.GenSA'")
   
-  R <- GenSA$R
+  R <- object$R
   # If the user does not pass in rp, then we will generate random portfolios
-  if(is.null(rp)){
+  if(rp){
     permutations <- match.call(expand.dots=TRUE)$permutations
     if(is.null(permutations)) permutations <- 2000
-    rp <- random_portfolios(portfolio=GenSA$portfolio, permutations=permutations)
+    rp <- random_portfolios(portfolio=object$portfolio, permutations=permutations)
   }
   
   # Get the optimal weights from the output of optimize.portfolio
-  wts <- GenSA$weights
+  wts <- object$weights
   
   # cbind the optimal weights and random portfolio weights
   rp <- rbind(wts, rp)
@@ -102,13 +86,17 @@
   returnpoints <- applyFUN(R=R, weights=rp, FUN=return.col, ...=...)
   riskpoints <- applyFUN(R=R, weights=rp, FUN=risk.col, ...=...)
   
-  plot(x=riskpoints, y=returnpoints, xlab=risk.col, ylab=return.col, col="darkgray", axes=FALSE, main=main)
+  plot(x=riskpoints, y=returnpoints, xlab=risk.col, ylab=return.col, col="darkgray", axes=FALSE, ...)
   points(x=riskpoints[1], y=returnpoints[1], col="blue", pch=16) # optimal
   axis(1, cex.axis = cex.axis, col = element.color)
   axis(2, cex.axis = cex.axis, col = element.color)
   box(col = element.color)
 }
 
+#' @rdname chart.RiskReward
+#' @export
+chart.RiskReward.optimize.portfolio.GenSA <- chart.Scatter.GenSA
+
 #' scatter and weights chart for portfolios
 #' 
 #' \code{return.col} must be the name of a function used to compute the return metric on the random portfolio weights
@@ -126,15 +114,15 @@
 #' @seealso \code{\link{optimize.portfolio}}
 #' @author Ross Bennett
 #' @export
-charts.GenSA <- function(GenSA, rp=NULL, return.col="mean", risk.col="StdDev",
+charts.GenSA <- function(GenSA, rp=FALSE, return.col="mean", risk.col="StdDev",
                        cex.axis=0.8, element.color="darkgray", neighbors=NULL, main="GenSA.Portfolios", ...){
   # Specific to the output of the optimize_method=GenSA
   op <- par(no.readonly=TRUE)
   layout(matrix(c(1,2)),height=c(2,2),width=1)
   par(mar=c(4,4,4,2))
-  chart.Scatter.GenSA(GenSA=GenSA, rp=rp, return.col=return.col, risk.col=risk.col, element.color=element.color, cex.axis=cex.axis, main=main, ...=...)
+  chart.Scatter.GenSA(object=GenSA, rp=rp, return.col=return.col, risk.col=risk.col, element.color=element.color, cex.axis=cex.axis, main=main, ...=...)
   par(mar=c(2,4,0,2))
-  chart.Weights.GenSA(GenSA=GenSA, neighbors=neighbors, las=3, xlab=NULL, cex.lab=1, element.color=element.color, cex.axis=cex.axis, ...=..., main="")
+  chart.Weights.GenSA(object=GenSA, neighbors=neighbors, las=3, xlab=NULL, cex.lab=1, element.color=element.color, cex.axis=cex.axis, ...=..., main="")
   par(op)
 }
 
@@ -155,6 +143,6 @@
 #' @seealso \code{\link{optimize.portfolio}}
 #' @author Ross Bennett
 #' @export
-plot.optimize.portfolio.GenSA <- function(GenSA, rp=NULL, return.col="mean", risk.col="StdDev", cex.axis=0.8, element.color="darkgray", neighbors=NULL, main="GenSA.Portfolios", ...){
+plot.optimize.portfolio.GenSA <- function(GenSA, rp=FALSE, return.col="mean", risk.col="StdDev", cex.axis=0.8, element.color="darkgray", neighbors=NULL, main="GenSA.Portfolios", ...){
   charts.GenSA(GenSA=GenSA, rp=rp, return.col=return.col, risk.col=risk.col, cex.axis=cex.axis, element.color=element.color, neighbors=neighbors, main=main, ...=...)
 }

Modified: pkg/PortfolioAnalytics/R/charts.PSO.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.PSO.R	2013-08-20 15:36:33 UTC (rev 2836)
+++ pkg/PortfolioAnalytics/R/charts.PSO.R	2013-08-20 17:05:15 UTC (rev 2837)
@@ -63,27 +63,14 @@
 #' @export
 chart.Weights.optimize.portfolio.pso <- chart.Weights.pso
 
-#' classic risk return scatter of random portfolios
-#' 
-#' 
-#' \code{return.col} must be the name of a function used to compute the return metric on the portfolio weights
-#' \code{risk.col} must be the name of a function used to compute the risk metric on the portfolio weights
-#' 
-#' @param pso object created by \code{\link{optimize.portfolio}}
-#' @param return.col string matching the objective of a 'return' objective, on vertical axis
-#' @param risk.col string matching the objective of a 'risk' objective, on horizontal axis
-#' @param ... any other passthru parameters 
-#' @param cex.axis The magnification to be used for axis annotation relative to the current setting of \code{cex}
-#' @param element.color color for the default plot scatter points
-#' @seealso \code{\link{optimize.portfolio}}
-#' @author Ross Bennett
+#' @rdname chart.RiskReward
 #' @export
-chart.Scatter.pso <- function(pso, return.col="mean", risk.col="StdDev", ..., element.color = "darkgray", cex.axis=0.8, main=""){
-  if(!inherits(pso, "optimize.portfolio.pso")) stop("pso must be of class 'optimize.portfolio.pso'")
-  R <- pso$R
+chart.Scatter.pso <- function(object, neighbors=NULL, ..., return.col="mean", risk.col="ES", element.color = "darkgray", cex.axis=0.8){
+  if(!inherits(object, "optimize.portfolio.pso")) stop("object must be of class 'optimize.portfolio.pso'")
+  R <- object$R
   # Object with the "out" value in the first column and the normalized weights
   # The first row is the optimal "out" value and the optimal weights
-  tmp <- extractStats(pso)
+  tmp <- extractStats(object)
   
   # Get the weights
   wts <- tmp[,-1]
@@ -91,13 +78,17 @@
   returnpoints <- applyFUN(R=R, weights=wts, FUN=return.col, ...=...)
   riskpoints <- applyFUN(R=R, weights=wts, FUN=risk.col, ...=...)
   
-  plot(x=riskpoints, y=returnpoints, xlab=risk.col, ylab=return.col, col="darkgray", axes=FALSE, main=main)
+  plot(x=riskpoints, y=returnpoints, xlab=risk.col, ylab=return.col, col="darkgray", axes=FALSE, ...)
   points(x=riskpoints[1], y=returnpoints[1], col="blue", pch=16) # optimal
   axis(1, cex.axis = cex.axis, col = element.color)
   axis(2, cex.axis = cex.axis, col = element.color)
   box(col = element.color)
 }
 
+#' @rdname chart.RiskReward
+#' @export
+chart.RiskReward.optimize.portfolio.pso <- chart.Scatter.pso
+
 #' scatter and weights chart for portfolios
 #' 
 #' \code{return.col} must be the name of a function used to compute the return metric on the random portfolio weights
@@ -120,9 +111,9 @@
   op <- par(no.readonly=TRUE)
   layout(matrix(c(1,2)),height=c(2,2),width=1)
   par(mar=c(4,4,4,2))
-  chart.Scatter.pso(pso=pso, return.col=return.col, risk.col=risk.col, element.color=element.color, cex.axis=cex.axis, main=main, ...=...)
+  chart.Scatter.pso(object=pso, return.col=return.col, risk.col=risk.col, element.color=element.color, cex.axis=cex.axis, main=main, ...=...)
   par(mar=c(2,4,0,2))
-  chart.Weights.pso(pso=pso, neighbors=neighbors, las=3, xlab=NULL, cex.lab=1, element.color=element.color, cex.axis=cex.axis, ...=..., main="")
+  chart.Weights.pso(object=pso, neighbors=neighbors, las=3, xlab=NULL, cex.lab=1, element.color=element.color, cex.axis=cex.axis, ...=..., main="")
   par(op)
 }
 

Modified: pkg/PortfolioAnalytics/R/charts.ROI.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.ROI.R	2013-08-20 15:36:33 UTC (rev 2836)
+++ pkg/PortfolioAnalytics/R/charts.ROI.R	2013-08-20 17:05:15 UTC (rev 2837)
@@ -63,38 +63,22 @@
 #' @export
 chart.Weights.optimize.portfolio.ROI <- chart.Weights.ROI
 
-#' classic risk return scatter of random portfolios
-#' 
-#' The ROI optimizers do not store the portfolio weights like DEoptim or random
-#' portfolios so we will generate random portfolios for the scatter plot. 
-#' 
-#' \code{return.col} must be the name of a function used to compute the return metric on the random portfolio weights
-#' \code{risk.col} must be the name of a function used to compute the risk metric on the random portfolio weights
-#' 
-#' @param ROI object created by \code{\link{optimize.portfolio}}
-#' @param rp matrix of random portfolios generated by \code{\link{random_portfolio}}
-#' @param return.col string matching the objective of a 'return' objective, on vertical axis
-#' @param risk.col string matching the objective of a 'risk' objective, on horizontal axis
-#' @param ... any other passthru parameters 
-#' @param cex.axis The magnification to be used for axis annotation relative to the current setting of \code{cex}
-#' @param element.color color for the default plot scatter points
-#' @seealso \code{\link{optimize.portfolio}}
-#' @author Ross Bennett
+#' @rdname chart.RiskReward
 #' @export
-chart.Scatter.ROI <- function(ROI, rp=NULL, return.col="mean", risk.col="StdDev", ..., element.color = "darkgray", cex.axis=0.8, main=""){
+chart.Scatter.ROI <- function(object, neighbors=NULL, ..., rp=FALSE, return.col="mean", risk.col="ES", element.color = "darkgray", cex.axis=0.8){
   
-  if(!inherits(ROI, "optimize.portfolio.ROI")) stop("ROI must be of class 'optimize.portfolio.ROI'")
+  if(!inherits(object, "optimize.portfolio.ROI")) stop("object must be of class 'optimize.portfolio.ROI'")
   
-  R <- ROI$R
+  R <- object$R
   # If the user does not pass in rp, then we will generate random portfolios
-  if(is.null(rp)){
+  if(rp){
     permutations <- match.call(expand.dots=TRUE)$permutations
     if(is.null(permutations)) permutations <- 2000
-    rp <- random_portfolios(portfolio=ROI$portfolio, permutations=permutations)
+    rp <- random_portfolios(portfolio=object$portfolio, permutations=permutations)
   }
   
   # Get the optimal weights from the output of optimize.portfolio
-  wts <- ROI$weights
+  wts <- object$weights
   
   # cbind the optimal weights and random portfolio weights
   rp <- rbind(wts, rp)
@@ -102,13 +86,17 @@
   returnpoints <- applyFUN(R=R, weights=rp, FUN=return.col, ...=...)
   riskpoints <- applyFUN(R=R, weights=rp, FUN=risk.col, ...=...)
   
-  plot(x=riskpoints, y=returnpoints, xlab=risk.col, ylab=return.col, col="darkgray", axes=FALSE, main=main)
+  plot(x=riskpoints, y=returnpoints, xlab=risk.col, ylab=return.col, col="darkgray", axes=FALSE, ...)
   points(x=riskpoints[1], y=returnpoints[1], col="blue", pch=16) # optimal
   axis(1, cex.axis = cex.axis, col = element.color)
   axis(2, cex.axis = cex.axis, col = element.color)
   box(col = element.color)
 }
 
+#' @rdname chart.RiskReward
+#' @export
+chart.RiskReward.optimize.portfolio.ROI <- chart.Scatter.ROI
+
 #' scatter and weights chart for portfolios
 #' 
 #' The ROI optimizers do not store the portfolio weights like DEoptim or random
@@ -129,7 +117,7 @@
 #' @seealso \code{\link{optimize.portfolio}}
 #' @author Ross Bennett
 #' @export
-charts.ROI <- function(ROI, rp=NULL, risk.col="StdDev", return.col="mean", 
+charts.ROI <- function(ROI, rp=FALSE, risk.col="StdDev", return.col="mean", 
                       cex.axis=0.8, element.color="darkgray", neighbors=NULL, main="ROI.Portfolios", ...){
   # Specific to the output of the optimize_method=ROI
   R <- ROI$R
@@ -162,6 +150,6 @@
 #' @seealso \code{\link{optimize.portfolio}}
 #' @author Ross Bennett
 #' @export
-plot.optimize.portfolio.ROI <- function(ROI, rp=NULL, risk.col="StdDev", return.col="mean", element.color="darkgray", neighbors=NULL, main="ROI.Portfolios", ...){
+plot.optimize.portfolio.ROI <- function(ROI, rp=FALSE, risk.col="StdDev", return.col="mean", element.color="darkgray", neighbors=NULL, main="ROI.Portfolios", ...){
   charts.ROI(ROI=ROI, rp=rp, risk.col=risk.col, return.col=return.col, main=main, ...)
 }

Modified: pkg/PortfolioAnalytics/R/charts.RP.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.RP.R	2013-08-20 15:36:33 UTC (rev 2836)
+++ pkg/PortfolioAnalytics/R/charts.RP.R	2013-08-20 17:05:15 UTC (rev 2837)
@@ -79,26 +79,17 @@
 #' @export
 chart.Weights.optimize.portfolio.random <- chart.Weights.RP
 
-#' classic risk return scatter of random portfolios
-#' 
-#' @param RP set of portfolios created by \code{\link{optimize.portfolio}}
-#' @param neighbors set of 'neighbor' portfolios to overplot, see Details
-#' @param return.col string matching the objective of a 'return' objective, on vertical axis
-#' @param risk.col string matching the objective of a 'risk' objective, on horizontal axis
-#' @param ... any other passthru parameters 
-#' @param cex.axis The magnification to be used for axis annotation relative to the current setting of \code{cex}
-#' @param element.color color for the default plot scatter points
-#' @seealso \code{\link{optimize.portfolio}}
+#' @rdname chart.RiskReward
 #' @export
-chart.Scatter.RP <- function(RP, neighbors = NULL, return.col='mean', risk.col='ES', ..., element.color = "darkgray", cex.axis=0.8){
+chart.Scatter.RP <- function(object, neighbors = NULL, ..., return.col='mean', risk.col='ES', element.color = "darkgray", cex.axis=0.8){
   # more or less specific to the output of the random portfolio code with constraints
   # will work to a point with other functions, such as optimize.porfolio.parallel
   # there's still a lot to do to improve this.
-  if(!inherits(RP, "optimize.portfolio.random")){
-    stop("RP must be of class 'optimize.portfolio.random'")
+  if(!inherits(object, "optimize.portfolio.random")){
+    stop("object must be of class 'optimize.portfolio.random'")
   }
-  R <- RP$R  
-  xtract = extractStats(RP)
+  R <- object$R  
+  xtract = extractStats(object)
   columnnames = colnames(xtract)
   #return.column = grep(paste("objective_measures",return.col,sep='.'),columnnames)
   return.column = pmatch(return.col,columnnames)
@@ -179,20 +170,20 @@
   }
   
   points(xtract[1,risk.column],xtract[1,return.column], col="orange", pch=16) # overplot the equal weighted (or seed)
-  #check to see if portfolio 1 is EW  RP$random_portoflios[1,] all weights should be the same
-  if(!isTRUE(all.equal(RP$random_portfolios[1,][1],1/length(RP$random_portfolios[1,]),check.attributes=FALSE))){
+  #check to see if portfolio 1 is EW  object$random_portoflios[1,] all weights should be the same
+  if(!isTRUE(all.equal(object$random_portfolios[1,][1],1/length(object$random_portfolios[1,]),check.attributes=FALSE))){
     #show both the seed and EW if they are different 
     #NOTE the all.equal comparison could fail above if the first element of the first portfolio is the same as the EW weight, 
     #but the rest is not, shouldn't happen often with real portfolios, only toy examples
     points(xtract[2,risk.column],xtract[2,return.column], col="green", pch=16) # overplot the equal weighted (or seed)
   }
   ## @TODO: Generalize this to find column containing the "risk" metric
-  if(length(names(RP)[which(names(RP)=='constrained_objective')])) {
+  if(length(names(object)[which(names(object)=='constrained_objective')])) {
     result.slot<-'constrained_objective'
   } else {
     result.slot<-'objective_measures'
   }
-  objcols<-unlist(RP[[result.slot]])
+  objcols<-unlist(object[[result.slot]])
   names(objcols)<-PortfolioAnalytics:::name.replace(names(objcols))
   return.column = pmatch(return.col,names(objcols))
   if(is.na(return.column)) {
@@ -210,7 +201,7 @@
     return.col <- gsub("\\..*", "", return.col)
     risk.col <- gsub("\\..*", "", risk.col)
     # warning(return.col,' or ', risk.col, ' do  not match extractStats output of $objective_measures slot')
-    opt_weights <- RP$weights
+    opt_weights <- object$weights
     ret <- as.numeric(applyFUN(R=R, weights=opt_weights, FUN=return.col))
     risk <- as.numeric(applyFUN(R=R, weights=opt_weights, FUN=risk.col))
     points(risk, ret, col="blue", pch=16) #optimal
@@ -222,6 +213,10 @@
   box(col = element.color)
 }
 
+#' @rdname chart.RiskReward
+#' @export
+chart.RiskReward.optimize.portfolio.random <- chart.Scatter.RP
+
 #' scatter and weights chart  for random portfolios
 #' 
 #' \code{neighbors} may be specified in three ways.  
@@ -243,16 +238,15 @@
 #' \code{\link{optimize.portfolio}}
 #' \code{\link{extractStats}}
 #' @export
-charts.RP <- function(RP, R=NULL, risk.col, return.col, 
-                      neighbors=NULL, main="Random.Portfolios", ...){
+charts.RP <- function(RP, risk.col, return.col, neighbors=NULL, main="Random.Portfolios", ...){
   # Specific to the output of the random portfolio code with constraints
   # @TODO: check that RP is of the correct class
   op <- par(no.readonly=TRUE)
   layout(matrix(c(1,2)),height=c(2,1.5),width=1)
   par(mar=c(4,4,4,2))
-  chart.Scatter.RP(RP, risk.col=risk.col, return.col=return.col, neighbors=neighbors, main=main, ...)
+  chart.Scatter.RP(object=RP, risk.col=risk.col, return.col=return.col, neighbors=neighbors, main=main, ...)
   par(mar=c(2,4,0,2))
-  chart.Weights.RP(RP, main="", neighbors=neighbors, ...)
+  chart.Weights.RP(object=RP, main="", neighbors=neighbors, ...)
   par(op)
 }
 

Added: pkg/PortfolioAnalytics/man/chart.RiskReward.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/chart.RiskReward.Rd	                        (rev 0)
+++ pkg/PortfolioAnalytics/man/chart.RiskReward.Rd	2013-08-20 17:05:15 UTC (rev 2837)
@@ -0,0 +1,95 @@
+\name{chart.Scatter.DE}
+\alias{chart.RiskReward}
+\alias{chart.RiskReward.optimize.portfolio.DEoptim}
+\alias{chart.RiskReward.optimize.portfolio.GenSA}
+\alias{chart.RiskReward.optimize.portfolio.pso}
+\alias{chart.RiskReward.optimize.portfolio.random}
+\alias{chart.RiskReward.optimize.portfolio.ROI}
+\alias{chart.Scatter.DE}
+\alias{chart.Scatter.GenSA}
+\alias{chart.Scatter.pso}
+\alias{chart.Scatter.ROI}
+\alias{chart.Scatter.RP}
+\title{classic risk reward scatter}
+\usage{
+  chart.Scatter.DE(object, neighbors = NULL, ...,
+    return.col = "mean", risk.col = "ES",
+    element.color = "darkgray", cex.axis = 0.8)
+
+  chart.RiskReward.optimize.portfolio.DEoptim(object,
+    neighbors = NULL, ..., return.col = "mean",
+    risk.col = "ES", element.color = "darkgray",
+    cex.axis = 0.8)
+
+  chart.Scatter.RP(object, neighbors = NULL, ...,
+    return.col = "mean", risk.col = "ES",
+    element.color = "darkgray", cex.axis = 0.8)
+
+  chart.RiskReward.optimize.portfolio.random(object,
+    neighbors = NULL, ..., return.col = "mean",
+    risk.col = "ES", element.color = "darkgray",
+    cex.axis = 0.8)
+
+  chart.Scatter.ROI(object, neighbors = NULL, ...,
+    rp = FALSE, return.col = "mean", risk.col = "ES",
+    element.color = "darkgray", cex.axis = 0.8)
+
+  chart.RiskReward.optimize.portfolio.ROI(object,
+    neighbors = NULL, ..., rp = FALSE, return.col = "mean",
+    risk.col = "ES", element.color = "darkgray",
+    cex.axis = 0.8)
+
+  chart.Scatter.pso(object, neighbors = NULL, ...,
+    return.col = "mean", risk.col = "ES",
+    element.color = "darkgray", cex.axis = 0.8)
+
+  chart.RiskReward.optimize.portfolio.pso(object,
+    neighbors = NULL, ..., return.col = "mean",
+    risk.col = "ES", element.color = "darkgray",
+    cex.axis = 0.8)
+
+  chart.Scatter.GenSA(object, neighbors = NULL, ...,
+    rp = FALSE, return.col = "mean", risk.col = "ES",
+    element.color = "darkgray", cex.axis = 0.8)
+
+  chart.RiskReward.optimize.portfolio.GenSA(object,
+    neighbors = NULL, ..., rp = FALSE, return.col = "mean",
+    risk.col = "ES", element.color = "darkgray",
+    cex.axis = 0.8)
+
+  chart.RiskReward(object, neighbors, ..., rp = FALSE,
+    return.col = "mean", risk.col = "ES",
+    element.color = "darkgray", cex.axis = 0.8)
+}
+\arguments{
+  \item{object}{optimal portfolio created by
+  \code{\link{optimize.portfolio}}}
+
+  \item{neighbors}{set of 'neighbor' portfolios to
+  overplot, see Details in \code{\link{charts.DE}}}
+
+  \item{...}{any other passthru parameters}
+
+  \item{rp}{TRUE/FALSE. If TRUE, random portfolios are
+  generated by \code{\link{random_portfolios}} to view the
+  feasible space}
+
+  \item{return.col}{string matching the objective of a
+  'return' objective, on vertical axis}
+
+  \item{risk.col}{string matching the objective of a 'risk'
+  objective, on horizontal axis}
+
+  \item{cex.axis}{The magnification to be used for axis
+  annotation relative to the current setting of \code{cex}}
+
+  \item{element.color}{color for the default plot scatter
+  points}
+}
+\description{
+  classic risk reward scatter
+}
+\seealso{
+  \code{\link{optimize.portfolio}}
+}
+

Modified: pkg/PortfolioAnalytics/man/chart.Scatter.DE.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/chart.Scatter.DE.Rd	2013-08-20 15:36:33 UTC (rev 2836)
+++ pkg/PortfolioAnalytics/man/chart.Scatter.DE.Rd	2013-08-20 17:05:15 UTC (rev 2837)
@@ -2,8 +2,8 @@
 \alias{chart.Scatter.DE}
 \title{classic risk return scatter of DEoptim results}
 \usage{
-  chart.Scatter.DE(DE, neighbors = NULL,
-    return.col = "mean", risk.col = "ES", ...,
+  chart.Scatter.DE(DE, neighbors = NULL, ...,
+    return.col = "mean", risk.col = "ES",
     element.color = "darkgray", cex.axis = 0.8)
 }
 \arguments{

Modified: pkg/PortfolioAnalytics/man/chart.Scatter.ROI.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/chart.Scatter.ROI.Rd	2013-08-20 15:36:33 UTC (rev 2836)
+++ pkg/PortfolioAnalytics/man/chart.Scatter.ROI.Rd	2013-08-20 17:05:15 UTC (rev 2837)
@@ -2,9 +2,9 @@
 \alias{chart.Scatter.ROI}
 \title{classic risk return scatter of random portfolios}
 \usage{
-  chart.Scatter.ROI(ROI, rp = NULL, return.col = "mean",
-    risk.col = "StdDev", ..., element.color = "darkgray",
-    cex.axis = 0.8, main = "")
+  chart.Scatter.ROI(ROI, neighbors = NULL, ..., rp = FALSE,
+    return.col = "mean", risk.col = "ES",
+    element.color = "darkgray", cex.axis = 0.8)
 }
 \arguments{
   \item{ROI}{object created by

Modified: pkg/PortfolioAnalytics/man/chart.Scatter.RP.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/chart.Scatter.RP.Rd	2013-08-20 15:36:33 UTC (rev 2836)
+++ pkg/PortfolioAnalytics/man/chart.Scatter.RP.Rd	2013-08-20 17:05:15 UTC (rev 2837)
@@ -2,8 +2,8 @@
 \alias{chart.Scatter.RP}
 \title{classic risk return scatter of random portfolios}
 \usage{
-  chart.Scatter.RP(RP, neighbors = NULL,
-    return.col = "mean", risk.col = "ES", ...,
+  chart.Scatter.RP(RP, neighbors = NULL, ...,
+    return.col = "mean", risk.col = "ES",
     element.color = "darkgray", cex.axis = 0.8)
 }
 \arguments{

Modified: pkg/PortfolioAnalytics/man/chart.Scatter.pso.Rd
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/returnanalytics -r 2837


More information about the Returnanalytics-commits mailing list