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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jun 30 20:38:16 CEST 2013


Author: rossbennett34
Date: 2013-06-30 20:38:16 +0200 (Sun, 30 Jun 2013)
New Revision: 2477

Modified:
   pkg/PortfolioAnalytics/R/constraints.R
   pkg/PortfolioAnalytics/man/box_constraint.Rd
   pkg/PortfolioAnalytics/man/diversification_constraint.Rd
   pkg/PortfolioAnalytics/man/group_constraint.Rd
   pkg/PortfolioAnalytics/man/position_limit_constraint.Rd
   pkg/PortfolioAnalytics/man/turnover_constraint.Rd
   pkg/PortfolioAnalytics/man/weight_sum_constraint.Rd
Log:
adding examples in documentation files for all supported constraint types

Modified: pkg/PortfolioAnalytics/R/constraints.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraints.R	2013-06-30 18:04:31 UTC (rev 2476)
+++ pkg/PortfolioAnalytics/R/constraints.R	2013-06-30 18:38:16 UTC (rev 2477)
@@ -277,6 +277,20 @@
 #' @param \dots any other passthru parameters to specify box constraints
 #' @author Ross Bennett
 #' @seealso \code{\link{add.constraint}}
+#' @examples
+#' data(edhec)
+#' ret <- edhec[, 1:4]
+#' 
+#' pspec <- portfolio.spec(assets=colnames(ret))
+#' 
+#' # defaults to min=0 and max=1
+#' pspec <- add.constraint(pspec, type="box")
+#' 
+#' # specify box constraints as a scalar
+#' pspec <- add.constraint(pspec, type="box", min=0.05, max=0.45)
+#' 
+#' # specify box constraints per asset
+#' pspec <- add.constraint(pspec, type="box", min=c(0.05, 0.10, 0.08, 0.06), max=c(0.45, 0.55, 0.35, 0.65))
 #' @export
 box_constraint <- function(type, assets, min, max, min_mult, max_mult, enabled=FALSE, ...){
   # Based on the constraint function for object of class constraint_v1 that
@@ -377,6 +391,18 @@
 #' @param \dots any other passthru parameters to specify group constraints
 #' @author Ross Bennett
 #' @seealso \code{\link{add.constraint}}
+#' @examples
+#' data(edhec)
+#' ret <- edhec[, 1:4]
+#' 
+#' pspec <- portfolio.spec(assets=colnames(ret))
+#' 
+#' pspec <- add.constraint(portfolio=pspec, 
+#'                         type="group", 
+#'                         groups=c(2, 2),
+#'                         group_labels=c("Style A", "Style B"),
+#'                         group_min=c(0.15, 0.25),
+#'                         group_max=c(0.65, 0.55))
 #' @export
 group_constraint <- function(type, assets, groups, group_labels=NULL, group_min, group_max, enabled=FALSE, ...) {
   nassets <- length(assets)
@@ -432,6 +458,21 @@
 #' @param enabled TRUE/FALSE
 #' @param \dots any other passthru parameters to specify weight_sum constraints
 #' @author Ross Bennett
+#' @examples
+#' data(edhec)
+#' ret <- edhec[, 1:4]
+#' 
+#' pspec <- portfolio.spec(assets=colnames(ret))
+#' 
+#' # min_sum and max_sum can be specified with type="weight_sum" or type="leverage"
+#' pspec <- add.constraint(pspec, type="weight_sum", min_sum=1, max_sum=1)
+#' 
+#' # Specify type="full_investment" to set min_sum=1 and max_sum=1
+#' pspec <- add.constraint(pspec, type="full_investment")
+#' 
+#' # Specify type="dollar_neutral" or type="active" to set min_sum=0 and max_sum=0
+#' pspec <- add.constraint(pspec, type="dollar_neutral")
+#' pspec <- add.constraint(pspec, type="active")
 #' @export
 weight_sum_constraint <- function(type, min_sum=0.99, max_sum=1.01, enabled=FALSE, ...){
   Constraint <- constraint_v2(type, enabled=enabled, constrclass="weight_sum_constraint", ...)
@@ -528,6 +569,13 @@
 #' @param enabled TRUE/FALSE
 #' @param \dots any other passthru parameters to specify box and/or group constraints
 #' @author Ross Bennett
+#' @examples
+#' data(edhec)
+#' ret <- edhec[, 1:4]
+#' 
+#' pspec <- portfolio.spec(assets=colnames(ret))
+#' 
+#' pspec <- add.constraint(portfolio=pspec, type="turnover", turnover.target=0.6)
 #' @export
 turnover_constraint <- function(type, turnover.target, enabled=FALSE, ...){
   Constraint <- constraint_v2(type, enabled=enabled, constrclass="turnover_constraint", ...)
@@ -544,6 +592,13 @@
 #' @param enabled TRUE/FALSE
 #' @param \dots any other passthru parameters to specify box and/or group constraints
 #' @author Ross Bennett
+#' @examples
+#' data(edhec)
+#' ret <- edhec[, 1:4]
+#' 
+#' pspec <- portfolio.spec(assets=colnames(ret))
+#' 
+#' pspec <- add.constraint(portfolio=pspec, type="diversification", div.target=0.7)
 #' @export
 diversification_constraint <- function(type, div.target, enabled=FALSE, ...){
   Constraint <- constraint_v2(type, enabled=enabled, constrclass="diversification_constraint", ...)
@@ -580,6 +635,13 @@
 #' @param enabled TRUE/FALSE
 #' @param \dots any other passthru parameters to specify box and/or group constraints
 #' @author Ross Bennett
+#' #' @examples
+#' data(edhec)
+#' ret <- edhec[, 1:4]
+#' 
+#' pspec <- portfolio.spec(assets=colnames(ret))
+#' 
+#' pspec <- add.constraint(portfolio=pspec, type="position_limit", max.pos=3)
 #' @export
 position_limit_constraint <- function(type, max.pos, enabled=FALSE, ...){
   Constraint <- constraint_v2(type, enabled=enabled, constrclass="position_limit_constraint", ...)

Modified: pkg/PortfolioAnalytics/man/box_constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/box_constraint.Rd	2013-06-30 18:04:31 UTC (rev 2476)
+++ pkg/PortfolioAnalytics/man/box_constraint.Rd	2013-06-30 18:38:16 UTC (rev 2477)
@@ -34,6 +34,21 @@
   This function is called by add.constraint when type="box"
   is specified. see \code{\link{add.constraint}}
 }
+\examples{
+data(edhec)
+ret <- edhec[, 1:4]
+
+pspec <- portfolio.spec(assets=colnames(ret))
+
+# defaults to min=0 and max=1
+pspec <- add.constraint(pspec, type="box")
+
+# specify box constraints as a scalar
+pspec <- add.constraint(pspec, type="box", min=0.05, max=0.45)
+
+# specify box constraints per asset
+pspec <- add.constraint(pspec, type="box", min=c(0.05, 0.10, 0.08, 0.06), max=c(0.45, 0.55, 0.35, 0.65))
+}
 \author{
   Ross Bennett
 }

Modified: pkg/PortfolioAnalytics/man/diversification_constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/diversification_constraint.Rd	2013-06-30 18:04:31 UTC (rev 2476)
+++ pkg/PortfolioAnalytics/man/diversification_constraint.Rd	2013-06-30 18:38:16 UTC (rev 2477)
@@ -20,6 +20,14 @@
   type="diversification" is specified,
   \code{\link{add.constraint}}
 }
+\examples{
+data(edhec)
+ret <- edhec[, 1:4]
+
+pspec <- portfolio.spec(assets=colnames(ret))
+
+pspec <- add.constraint(portfolio=pspec, type="diversification", div.target=0.7)
+}
 \author{
   Ross Bennett
 }

Modified: pkg/PortfolioAnalytics/man/group_constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/group_constraint.Rd	2013-06-30 18:04:31 UTC (rev 2476)
+++ pkg/PortfolioAnalytics/man/group_constraint.Rd	2013-06-30 18:38:16 UTC (rev 2477)
@@ -33,6 +33,19 @@
   type="group" is specified. see
   \code{\link{add.constraint}}
 }
+\examples{
+data(edhec)
+ret <- edhec[, 1:4]
+
+pspec <- portfolio.spec(assets=colnames(ret))
+
+pspec <- add.constraint(portfolio=pspec,
+                        type="group",
+                        groups=c(2, 2),
+                        group_labels=c("Style A", "Style B"),
+                        group_min=c(0.15, 0.25),
+                        group_max=c(0.65, 0.55))
+}
 \author{
   Ross Bennett
 }

Modified: pkg/PortfolioAnalytics/man/position_limit_constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/position_limit_constraint.Rd	2013-06-30 18:04:31 UTC (rev 2476)
+++ pkg/PortfolioAnalytics/man/position_limit_constraint.Rd	2013-06-30 18:38:16 UTC (rev 2477)
@@ -22,7 +22,15 @@
   the maximum number of positions (i.e. number of assets
   with non-zero weights)
 }
+\examples{
+data(edhec)
+ret <- edhec[, 1:4]
+
+pspec <- portfolio.spec(assets=colnames(ret))
+
+pspec <- add.constraint(portfolio=pspec, type="position_limit", max.pos=3)
+}
 \author{
-  Ross Bennett
+  Ross Bennett #'
 }
 

Modified: pkg/PortfolioAnalytics/man/turnover_constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/turnover_constraint.Rd	2013-06-30 18:04:31 UTC (rev 2476)
+++ pkg/PortfolioAnalytics/man/turnover_constraint.Rd	2013-06-30 18:38:16 UTC (rev 2477)
@@ -26,6 +26,14 @@
   for global minimum variance problem with ROI quadprog
   plugin
 }
+\examples{
+data(edhec)
+ret <- edhec[, 1:4]
+
+pspec <- portfolio.spec(assets=colnames(ret))
+
+pspec <- add.constraint(portfolio=pspec, type="turnover", turnover.target=0.6)
+}
 \author{
   Ross Bennett
 }

Modified: pkg/PortfolioAnalytics/man/weight_sum_constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/weight_sum_constraint.Rd	2013-06-30 18:04:31 UTC (rev 2476)
+++ pkg/PortfolioAnalytics/man/weight_sum_constraint.Rd	2013-06-30 18:38:16 UTC (rev 2477)
@@ -36,6 +36,22 @@
   If type="dollar_neutral" or type="active", min_sum=0, and
   max_sum=0
 }
+\examples{
+data(edhec)
+ret <- edhec[, 1:4]
+
+pspec <- portfolio.spec(assets=colnames(ret))
+
+# min_sum and max_sum can be specified with type="weight_sum" or type="leverage"
+pspec <- add.constraint(pspec, type="weight_sum", min_sum=1, max_sum=1)
+
+# Specify type="full_investment" to set min_sum=1 and max_sum=1
+pspec <- add.constraint(pspec, type="full_investment")
+
+# Specify type="dollar_neutral" or type="active" to set min_sum=0 and max_sum=0
+pspec <- add.constraint(pspec, type="dollar_neutral")
+pspec <- add.constraint(pspec, type="active")
+}
 \author{
   Ross Bennett
 }



More information about the Returnanalytics-commits mailing list