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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Oct 18 03:11:41 CEST 2013


Author: rossbennett34
Date: 2013-10-18 03:11:40 +0200 (Fri, 18 Oct 2013)
New Revision: 3229

Modified:
   pkg/PortfolioAnalytics/NAMESPACE
   pkg/PortfolioAnalytics/R/charts.risk.R
   pkg/PortfolioAnalytics/man/chart.RiskBudget.Rd
Log:
Adding chart.RiskBudget method for optimize.portfolio.rebalancing objects.

Modified: pkg/PortfolioAnalytics/NAMESPACE
===================================================================
--- pkg/PortfolioAnalytics/NAMESPACE	2013-10-18 01:04:30 UTC (rev 3228)
+++ pkg/PortfolioAnalytics/NAMESPACE	2013-10-18 01:11:40 UTC (rev 3229)
@@ -79,6 +79,7 @@
 S3method(chart.EfficientFrontier,optimize.portfolio.ROI)
 S3method(chart.EfficientFrontier,optimize.portfolio)
 S3method(chart.RiskBudget,opt.list)
+S3method(chart.RiskBudget,optimize.portfolio.rebalancing)
 S3method(chart.RiskBudget,optimize.portfolio)
 S3method(chart.RiskReward,opt.list)
 S3method(chart.RiskReward,optimize.portfolio.DEoptim)

Modified: pkg/PortfolioAnalytics/R/charts.risk.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.risk.R	2013-10-18 01:04:30 UTC (rev 3228)
+++ pkg/PortfolioAnalytics/R/charts.risk.R	2013-10-18 01:11:40 UTC (rev 3229)
@@ -2,9 +2,11 @@
 #' Generic method to chart risk contribution
 #' 
 #' This function is the generic method to chart risk budget objectives for 
-#' \code{optimize.portfolio} and \code{opt.list} objects. This function charts 
-#' the contribution or percent contribution of the resulting objective measures 
-#' of a \code{risk_budget_objective}.
+#' \code{optimize.portfolio}, \code{optimize.portfolio.rebalancing}, and 
+#' \code{opt.list} objects. This function charts the contribution or percent 
+#' contribution of the resulting objective measures of a 
+#' \code{risk_budget_objective}. The risk contributions for \code{optimize.portfolio.rebalancing}
+#' objects are plotted through time with \code{\link[PerformanceAnalytics]{chart.StackedBar}}.
 #' 
 #' @details
 #' \code{neighbors} may be specified in three ways.  
@@ -43,6 +45,7 @@
 #' @param colorset color palette or vector of colors to use
 #' @param legend.loc legend.loc NULL, "topright", "right", or "bottomright". If legend.loc is NULL, the legend will not be plotted
 #' @param cex.legend The magnification to be used for the legend relative to the current setting of \code{cex}
+#' @seealso \code{\link{optimize.portfolio}} \code{\link{optimize.portfolio.rebalancing}} \code{\link[PerformanceAnalytics]{chart.StackedBar}}
 #' @export
 chart.RiskBudget <- function(object, ...){
   UseMethod("chart.RiskBudget")
@@ -206,7 +209,30 @@
   } # end plot for pct_contrib risk.type
 }
 
+#' @rdname chart.RiskBudget
+#' @method chart.RiskBudget optimize.portfolio.rebalancing
+#' @S3method chart.RiskBudget optimize.portfolio.rebalancing
+chart.RiskBudget.optimize.portfolio.rebalancing <- function(object, ..., match.col="ES", risk.type="absolute", main="Risk Contribution"){
+  
+  # Get the objective measures at each rebalance period
+  rebal.obj <- extractObjectiveMeasures(object)
+  
+  if(risk.type == "absolute"){
+    rbcols <- grep(paste(match.col, "pct_contrib", sep="."), colnames(rebal.obj))
+    if(length(rbcols) < 1) stop(paste("No ", match.col, ".contribution columns.", sep=""))
+    rbdata <- rebal.obj[, rbcols]
+    chart.StackedBar(w=rbdata, ylab=paste(match.col, "Contribution", sep=" "), main=main, ...)
+  }
+  
+  if(risk.type %in% c("percent", "percentage", "pct_contrib")){
+    rbcols <- grep(paste(match.col, "pct_contrib", sep="."), colnames(rebal.obj))
+    if(length(rbcols) < 1) stop(paste("No ", match.col, ".pct_contrib columns.", sep=""))
+    rbdata <- rebal.obj[, rbcols]
+    chart.StackedBar(w=rbdata, ylab=paste(match.col, "% Contribution", sep=" "), main=main, ...)
+  }
+}
 
+
 #' @rdname chart.RiskBudget
 #' @method chart.RiskBudget opt.list
 #' @S3method chart.RiskBudget opt.list

Modified: pkg/PortfolioAnalytics/man/chart.RiskBudget.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/chart.RiskBudget.Rd	2013-10-18 01:04:30 UTC (rev 3228)
+++ pkg/PortfolioAnalytics/man/chart.RiskBudget.Rd	2013-10-18 01:11:40 UTC (rev 3229)
@@ -2,6 +2,7 @@
 \alias{chart.RiskBudget}
 \alias{chart.RiskBudget.opt.list}
 \alias{chart.RiskBudget.optimize.portfolio}
+\alias{chart.RiskBudget.optimize.portfolio.rebalancing}
 \title{Generic method to chart risk contribution}
 \usage{
   chart.RiskBudget(object, ...)
@@ -12,6 +13,10 @@
     cex.axis = 0.8, cex.lab = 0.8,
     element.color = "darkgray", las = 3, ylim = NULL)
 
+  \method{chart.RiskBudget}{optimize.portfolio.rebalancing}
+    (object, ..., match.col = "ES", risk.type = "absolute",
+    main = "Risk Contribution")
+
   \method{chart.RiskBudget}{opt.list} (object, ...,
     match.col = "ES", risk.type = "absolute",
     main = "Risk Budget", plot.type = "line",
@@ -78,10 +83,15 @@
 }
 \description{
   This function is the generic method to chart risk budget
-  objectives for \code{optimize.portfolio} and
+  objectives for \code{optimize.portfolio},
+  \code{optimize.portfolio.rebalancing}, and
   \code{opt.list} objects. This function charts the
   contribution or percent contribution of the resulting
-  objective measures of a \code{risk_budget_objective}.
+  objective measures of a \code{risk_budget_objective}. The
+  risk contributions for
+  \code{optimize.portfolio.rebalancing} objects are plotted
+  through time with
+  \code{\link[PerformanceAnalytics]{chart.StackedBar}}.
 }
 \details{
   \code{neighbors} may be specified in three ways. The
@@ -96,4 +106,9 @@
   \code{\link{extractStats}}, and should contain properly
   named contribution and pct_contrib columns.
 }
+\seealso{
+  \code{\link{optimize.portfolio}}
+  \code{\link{optimize.portfolio.rebalancing}}
+  \code{\link[PerformanceAnalytics]{chart.StackedBar}}
+}
 



More information about the Returnanalytics-commits mailing list