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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Apr 15 18:49:32 CEST 2014


Author: rossbennett34
Date: 2014-04-15 18:49:32 +0200 (Tue, 15 Apr 2014)
New Revision: 3369

Modified:
   pkg/PortfolioAnalytics/R/constraints.R
   pkg/PortfolioAnalytics/R/objective.R
   pkg/PortfolioAnalytics/man/add.constraint.Rd
   pkg/PortfolioAnalytics/man/add.objective.Rd
   pkg/PortfolioAnalytics/man/print.summary.optimize.portfolio.rebalancing.Rd
Log:
adding examples to add.constraint and add.objective

Modified: pkg/PortfolioAnalytics/R/constraints.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraints.R	2014-04-15 01:49:25 UTC (rev 3368)
+++ pkg/PortfolioAnalytics/R/constraints.R	2014-04-15 16:49:32 UTC (rev 3369)
@@ -255,6 +255,29 @@
 #' 
 #' # Add target mean return constraint
 #' pspec <- add.constraint(portfolio=pspec, type="return", return_target=0.007)
+#' 
+#' # Example using the indexnum argument
+#' portf <- portfolio.spec(assets=fund.names)
+#' portf <- add.constraint(portf, type="full_investment")
+#' portf <- add.constraint(portf, type="long_only")
+#' 
+#' # indexnum corresponds to the index number of the constraint
+#' # The full_investment constraint was the first constraint added and has 
+#' # indexnum=1
+#' portf$constraints[[1]]
+#' 
+#' # View the constraint with indexnum=2
+#' portf$constraints[[2]]
+#' 
+#' # Update the constraint to relax the sum of weights constraint
+#' portf <- add.constraint(portf, type="weight_sum", 
+#' min_sum=0.99, max_sum=1.01, 
+#' indexnum=1)
+#' 
+#' # Update the constraint to modify the box constraint
+#' portf <- add.constraint(portf, type="box", 
+#' min=0.1, max=0.8, 
+#' indexnum=2)
 #' @export
 add.constraint <- function(portfolio, type, enabled=TRUE, message=FALSE, ..., indexnum=NULL){
   # Check to make sure that the portfolio passed in is a portfolio object

Modified: pkg/PortfolioAnalytics/R/objective.R
===================================================================
--- pkg/PortfolioAnalytics/R/objective.R	2014-04-15 01:49:25 UTC (rev 3368)
+++ pkg/PortfolioAnalytics/R/objective.R	2014-04-15 16:49:32 UTC (rev 3369)
@@ -223,12 +223,60 @@
 #' @param arguments default arguments to be passed to an objective function when executed
 #' @param enabled TRUE/FALSE
 #' @param \dots any other passthru parameters 
-#' @param indexnum if you are updating a specific constraint, the index number in the $objectives list to update
+#' @param indexnum if you are updating a specific objective, the index number in the $objectives list to update
 #' @author Brian G. Peterson and Ross Bennett
 #' @aliases add.objective_v2 add.objective_v1
 #' @seealso \code{\link{objective}}, \code{\link{portfolio.spec}}
 #' @rdname add.objective
 #' @name add.objective
+#' @examples
+#' data(edhec)
+#' returns <- edhec[,1:4]
+#' fund.names <- colnames(returns)
+#' portf <- portfolio.spec(assets=fund.names)
+#' # Add some basic constraints
+#' portf <- add.constraint(portf, type="full_investment")
+#' portf <- add.constraint(portf, type="long_only")
+#' 
+#' # Creates a new portfolio object using portf and adds a quadratic utility
+#' # objective. This will add two objectives to the portfolio object; 1) mean and
+#' # 2) var. The risk aversion parameter is commonly referred to as lambda in the
+#' # quadratic utility formulation that controls how much the portfolio variance 
+#' # is penalized.
+#' portf.maxQU <- add.objective(portf, type="quadratic_utility", 
+#'                              risk_aversion=0.25)
+#' 
+#' # Creates a new portfolio object using portf and adds mean as an objective
+#' portf.maxMean <- add.objective(portf, type="return", name="mean")
+#' 
+#' # Creates a new portfolio object using portf and adds StdDev as an objective
+#' portf.minStdDev <- add.objective(portf, type="risk", name="StdDev")
+#' 
+#' # Creates a new portfolio object using portf and adds ES as an objective. 
+#' # Note that arguments to ES are passed in as a named list.
+#' portf.minES <- add.objective(portf, type="risk", name="ES", 
+#'                              arguments=list(p=0.925, clean="boudt"))
+#' 
+#' # Creates a new portfolio object using portf.minES and adds a risk budget 
+#' # objective with limits on component risk contribution. 
+#' # Note that arguments to ES are passed in as a named list.
+#' portf.RiskBudgetES <- add.objective(portf.minES, type="risk_budget", name="ES", 
+#'                              arguments=list(p=0.925, clean="boudt"),
+#'                              min_prisk=0, max_prisk=0.6)
+#' 
+#' # Creates a new portfolio object using portf.minES and adds a risk budget 
+#' # objective with equal component risk contribution. 
+#' # Note that arguments to ES are passed in as a named list.
+#' portf.EqRiskES <- add.objective(portf.minES, type="risk_budget", name="ES", 
+#'                                     arguments=list(p=0.925, clean="boudt"),
+#'                                     min_concentration=TRUE)
+#' 
+#' # Creates a new portfolio object using portf and adds a weight_concentration 
+#' # objective. The conc_aversion parameter controls how much concentration is
+#' # penalized. The portfolio concentration is defined as the Herfindahl Hirschman
+#' # Index of the weights.
+#' portf.conc <- add.objective(portf, type="weight_concentration", 
+#'                             name="HHI", conc_aversion=0.01)
 #' @export
 add.objective <- add.objective_v2
 

Modified: pkg/PortfolioAnalytics/man/add.constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/add.constraint.Rd	2014-04-15 01:49:25 UTC (rev 3368)
+++ pkg/PortfolioAnalytics/man/add.constraint.Rd	2014-04-15 16:49:32 UTC (rev 3369)
@@ -102,6 +102,29 @@
 
 # Add target mean return constraint
 pspec <- add.constraint(portfolio=pspec, type="return", return_target=0.007)
+
+# Example using the indexnum argument
+portf <- portfolio.spec(assets=fund.names)
+portf <- add.constraint(portf, type="full_investment")
+portf <- add.constraint(portf, type="long_only")
+
+# indexnum corresponds to the index number of the constraint
+# The full_investment constraint was the first constraint added and has
+# indexnum=1
+portf$constraints[[1]]
+
+# View the constraint with indexnum=2
+portf$constraints[[2]]
+
+# Update the constraint to relax the sum of weights constraint
+portf <- add.constraint(portf, type="weight_sum",
+min_sum=0.99, max_sum=1.01,
+indexnum=1)
+
+# Update the constraint to modify the box constraint
+portf <- add.constraint(portf, type="box",
+min=0.1, max=0.8,
+indexnum=2)
 }
 \author{
   Ross Bennett

Modified: pkg/PortfolioAnalytics/man/add.objective.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/add.objective.Rd	2014-04-15 01:49:25 UTC (rev 3368)
+++ pkg/PortfolioAnalytics/man/add.objective.Rd	2014-04-15 16:49:32 UTC (rev 3369)
@@ -36,9 +36,8 @@
 
   \item{\dots}{any other passthru parameters}
 
-  \item{indexnum}{if you are updating a specific
-  constraint, the index number in the $objectives list to
-  update}
+  \item{indexnum}{if you are updating a specific objective,
+  the index number in the $objectives list to update}
 }
 \description{
   This function is the main function for adding and
@@ -56,6 +55,55 @@
   Objectives of type 'turnover' and 'minmax' are also
   supported.
 }
+\examples{
+data(edhec)
+returns <- edhec[,1:4]
+fund.names <- colnames(returns)
+portf <- portfolio.spec(assets=fund.names)
+# Add some basic constraints
+portf <- add.constraint(portf, type="full_investment")
+portf <- add.constraint(portf, type="long_only")
+
+# Creates a new portfolio object using portf and adds a quadratic utility
+# objective. This will add two objectives to the portfolio object; 1) mean and
+# 2) var. The risk aversion parameter is commonly referred to as lambda in the
+# quadratic utility formulation that controls how much the portfolio variance
+# is penalized.
+portf.maxQU <- add.objective(portf, type="quadratic_utility",
+                             risk_aversion=0.25)
+
+# Creates a new portfolio object using portf and adds mean as an objective
+portf.maxMean <- add.objective(portf, type="return", name="mean")
+
+# Creates a new portfolio object using portf and adds StdDev as an objective
+portf.minStdDev <- add.objective(portf, type="risk", name="StdDev")
+
+# Creates a new portfolio object using portf and adds ES as an objective.
+# Note that arguments to ES are passed in as a named list.
+portf.minES <- add.objective(portf, type="risk", name="ES",
+                             arguments=list(p=0.925, clean="boudt"))
+
+# Creates a new portfolio object using portf.minES and adds a risk budget
+# objective with limits on component risk contribution.
+# Note that arguments to ES are passed in as a named list.
+portf.RiskBudgetES <- add.objective(portf.minES, type="risk_budget", name="ES",
+                             arguments=list(p=0.925, clean="boudt"),
+                             min_prisk=0, max_prisk=0.6)
+
+# Creates a new portfolio object using portf.minES and adds a risk budget
+# objective with equal component risk contribution.
+# Note that arguments to ES are passed in as a named list.
+portf.EqRiskES <- add.objective(portf.minES, type="risk_budget", name="ES",
+                                    arguments=list(p=0.925, clean="boudt"),
+                                    min_concentration=TRUE)
+
+# Creates a new portfolio object using portf and adds a weight_concentration
+# objective. The conc_aversion parameter controls how much concentration is
+# penalized. The portfolio concentration is defined as the Herfindahl Hirschman
+# Index of the weights.
+portf.conc <- add.objective(portf, type="weight_concentration",
+                            name="HHI", conc_aversion=0.01)
+}
 \author{
   Brian G. Peterson and Ross Bennett
 }

Modified: pkg/PortfolioAnalytics/man/print.summary.optimize.portfolio.rebalancing.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/print.summary.optimize.portfolio.rebalancing.Rd	2014-04-15 01:49:25 UTC (rev 3368)
+++ pkg/PortfolioAnalytics/man/print.summary.optimize.portfolio.rebalancing.Rd	2014-04-15 16:49:32 UTC (rev 3369)
@@ -2,8 +2,7 @@
 \alias{print.summary.optimize.portfolio.rebalancing}
 \title{Printing summary output of optimize.portfolio.rebalancing}
 \usage{
-  \method{print}{summary.optimize.portfolio.rebalancing}
-    (x, ..., digits = 4)
+  \method{print}{summary.optimize.portfolio.rebalancing}(x, ..., digits = 4)
 }
 \arguments{
   \item{x}{an object of class



More information about the Returnanalytics-commits mailing list