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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jun 30 18:56:53 CEST 2013


Author: rossbennett34
Date: 2013-06-30 18:56:53 +0200 (Sun, 30 Jun 2013)
New Revision: 2473

Added:
   pkg/PortfolioAnalytics/man/constraint_fnMap.Rd
   pkg/PortfolioAnalytics/man/minmax_objective.Rd
   pkg/PortfolioAnalytics/man/position_limit_constraint.Rd
Modified:
   pkg/PortfolioAnalytics/DESCRIPTION
   pkg/PortfolioAnalytics/NAMESPACE
   pkg/PortfolioAnalytics/R/constraints.R
   pkg/PortfolioAnalytics/man/group_constraint.Rd
   pkg/PortfolioAnalytics/sandbox/constraints_vignette.Rnw
Log:
adding support for group labels and updating documentation

Modified: pkg/PortfolioAnalytics/DESCRIPTION
===================================================================
--- pkg/PortfolioAnalytics/DESCRIPTION	2013-06-29 23:06:16 UTC (rev 2472)
+++ pkg/PortfolioAnalytics/DESCRIPTION	2013-06-30 16:56:53 UTC (rev 2473)
@@ -44,3 +44,4 @@
     'objectiveFUN.R'
     'portfolio.R'
     'constraintsFUN.R'
+    'constraint_fnMap.R'

Modified: pkg/PortfolioAnalytics/NAMESPACE
===================================================================
--- pkg/PortfolioAnalytics/NAMESPACE	2013-06-29 23:06:16 UTC (rev 2472)
+++ pkg/PortfolioAnalytics/NAMESPACE	2013-06-30 16:56:53 UTC (rev 2473)
@@ -11,6 +11,7 @@
 export(charts.RP)
 export(constrained_group_tmp)
 export(constrained_objective)
+export(constraint_fnMap)
 export(constraint_ROI)
 export(constraint_v2)
 export(constraint)

Modified: pkg/PortfolioAnalytics/R/constraints.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraints.R	2013-06-29 23:06:16 UTC (rev 2472)
+++ pkg/PortfolioAnalytics/R/constraints.R	2013-06-30 16:56:53 UTC (rev 2473)
@@ -354,6 +354,7 @@
 #' @param type character type of the constraint
 #' @param assets number of assets, or optionally a named vector of assets specifying seed weights
 #' @param groups vector specifying the groups of the assets
+#' @param group_labels character vector to label the groups (e.g. size, asset class, style, etc.)
 #' @param group_min numeric or vector specifying minimum weight group constraints
 #' @param group_max numeric or vector specifying minimum weight group constraints
 #' @param enabled TRUE/FALSE
@@ -361,7 +362,7 @@
 #' @author Ross Bennett
 #' @seealso \code{\link{add.constraint}}
 #' @export
-group_constraint <- function(type, assets, groups, group_min, group_max, enabled=FALSE, ...) {
+group_constraint <- function(type, assets, groups, group_labels=NULL, group_min, group_max, enabled=FALSE, ...) {
   nassets <- length(assets)
   ngroups <- length(groups)
   
@@ -383,8 +384,16 @@
   }
   if (length(group_max) != ngroups) stop(paste("length of group_max must be equal to 1 or the length of groups:", ngroups))
   
+  # Construct the group_label vector if it is not passed in
+  if(is.null(group_labels)){
+    group_labels <- paste(rep("group", ngroups), 1:ngroups, sep="")
+  }
+  
+  if(length(group_labels) != length(groups)) stop("length of group_labels must be equal to the length of groups")
+  
   Constraint <- constraint_v2(type, enabled=enabled, constrclass="group_constraint", ...)
   Constraint$groups <- groups
+  Constraint$group_labels <- group_labels
   Constraint$cLO <- group_min
   Constraint$cUP <- group_max
   return(Constraint)

Added: pkg/PortfolioAnalytics/man/constraint_fnMap.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/constraint_fnMap.Rd	                        (rev 0)
+++ pkg/PortfolioAnalytics/man/constraint_fnMap.Rd	2013-06-30 16:56:53 UTC (rev 2473)
@@ -0,0 +1,27 @@
+\name{constraint_fnMap}
+\alias{constraint_fnMap}
+\title{Constraint mapping function}
+\usage{
+  constraint_fnMap(weights, portfolio)
+}
+\arguments{
+  \item{weights}{vector of weights}
+
+  \item{portfolio}{object of class portfolio}
+}
+\description{
+  The purpose of the mapping function is to transform a
+  weights vector that does not meet all the constraints
+  into a weights vector that does meet the constraints, if
+  one exists, hopefully with a minimum of transformation. I
+  think our first step should be to test each constraint
+  type, in some sort of hierarchy, starting with box
+  constraints (almost all solvers support box constraints,
+  of course), since some of the other transformations will
+  violate the box constraints, and we'll need to transform
+  back again.
+}
+\author{
+  Ross Bennett
+}
+

Modified: pkg/PortfolioAnalytics/man/group_constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/group_constraint.Rd	2013-06-29 23:06:16 UTC (rev 2472)
+++ pkg/PortfolioAnalytics/man/group_constraint.Rd	2013-06-30 16:56:53 UTC (rev 2473)
@@ -2,8 +2,9 @@
 \alias{group_constraint}
 \title{constructor for group_constraint}
 \usage{
-  group_constraint(type, assets, groups, group_min,
-    group_max, enabled = FALSE, ...)
+  group_constraint(type, assets, groups,
+    group_labels = NULL, group_min, group_max,
+    enabled = FALSE, ...)
 }
 \arguments{
   \item{type}{character type of the constraint}
@@ -13,6 +14,9 @@
 
   \item{groups}{vector specifying the groups of the assets}
 
+  \item{group_labels}{character vector to label the groups
+  (i.e. size, asset class, style, etc.)}
+
   \item{group_min}{numeric or vector specifying minimum
   weight group constraints}
 

Added: pkg/PortfolioAnalytics/man/minmax_objective.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/minmax_objective.Rd	                        (rev 0)
+++ pkg/PortfolioAnalytics/man/minmax_objective.Rd	2013-06-30 16:56:53 UTC (rev 2473)
@@ -0,0 +1,48 @@
+\name{minmax_objective}
+\alias{minmax_objective}
+\title{constructor for class tmp_minmax_objective}
+\usage{
+  minmax_objective(name, target = NULL, arguments = NULL,
+    multiplier = 1, enabled = FALSE, ..., min, max)
+}
+\arguments{
+  \item{name}{name of the objective, should correspond to a
+  function, though we will try to make allowances}
+
+  \item{target}{univariate target for the objective}
+
+  \item{min}{minimum value}
+
+  \item{max}{maximum value}
+
+  \item{arguments}{default arguments to be passed to an
+  objective function when executed}
+
+  \item{multiplier}{multiplier to apply to the objective,
+  usually 1 or -1}
+
+  \item{enabled}{TRUE/FALSE}
+
+  \item{\dots}{any other passthru parameters}
+}
+\description{
+  I am add this as a temporary objective allowing for a min
+  and max to be specified. Testing to understand how the
+  objective function responds to a range of allowable
+  values. I will likely add this to the turnover,
+  diversification, and volatility constraints allowing the
+  user to specify a range of values.
+}
+\details{
+  if target is null, we'll try to minimize the metric
+
+  if target is set, we'll try to meet the metric
+
+  If max is violated to the upside, penalize the metric If
+  min is violated to the downside, penalize the metric Try
+  to meet the range between min and max
+}
+\author{
+  Ross Bennett
+}
+

Added: pkg/PortfolioAnalytics/man/position_limit_constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/position_limit_constraint.Rd	                        (rev 0)
+++ pkg/PortfolioAnalytics/man/position_limit_constraint.Rd	2013-06-30 16:56:53 UTC (rev 2473)
@@ -0,0 +1,28 @@
+\name{position_limit_constraint}
+\alias{position_limit_constraint}
+\title{constructor for position_limit_constraint}
+\usage{
+  position_limit_constraint(type, max.pos, enabled = FALSE,
+    ...)
+}
+\arguments{
+  \item{type}{character type of the constraint}
+
+  \item{max.pos}{maximum number of positions}
+
+  \item{enabled}{TRUE/FALSE}
+
+  \item{\dots}{any other passthru parameters to specify box
+  and/or group constraints}
+}
+\description{
+  This function is called by add.constraint when
+  type="position_limit" is specified,
+  \code{\link{add.constraint}} Allows the user to specify
+  the maximum number of positions (i.e. number of assets
+  with non-zero weights)
+}
+\author{
+  Ross Bennett
+}
+

Modified: pkg/PortfolioAnalytics/sandbox/constraints_vignette.Rnw
===================================================================
--- pkg/PortfolioAnalytics/sandbox/constraints_vignette.Rnw	2013-06-29 23:06:16 UTC (rev 2472)
+++ pkg/PortfolioAnalytics/sandbox/constraints_vignette.Rnw	2013-06-30 16:56:53 UTC (rev 2473)
@@ -80,10 +80,12 @@
 The assets are grouped in 2 groups of 2 assets.
 The sum of asset weights of the first group must be greater than or equal to 0.15 and less than or equal to 0.65.
 The sum asset weights of the second group must be greater than or equal to 0.25 and less than or equal to 0.55.
+Labels for the groups can be specified (e.g. size, asset class, style, etc.). By default, the group labels will be group1, group2, ..., groupN for N groups. 
 <<>>=
 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),
                         enabled=TRUE)



More information about the Returnanalytics-commits mailing list