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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jun 29 01:54:10 CEST 2013


Author: rossbennett34
Date: 2013-06-29 01:54:09 +0200 (Sat, 29 Jun 2013)
New Revision: 2470

Modified:
   pkg/PortfolioAnalytics/NAMESPACE
   pkg/PortfolioAnalytics/R/constraints.R
   pkg/PortfolioAnalytics/man/add.constraint.Rd
   pkg/PortfolioAnalytics/man/turnover_constraint.Rd
   pkg/PortfolioAnalytics/man/volatility_constraint.Rd
Log:
adding position_limit constraint type and updating documentation for constraints

Modified: pkg/PortfolioAnalytics/NAMESPACE
===================================================================
--- pkg/PortfolioAnalytics/NAMESPACE	2013-06-28 21:31:08 UTC (rev 2469)
+++ pkg/PortfolioAnalytics/NAMESPACE	2013-06-28 23:54:09 UTC (rev 2470)
@@ -29,6 +29,7 @@
 export(is.constraint)
 export(is.objective)
 export(is.portfolio)
+export(minmax_objective)
 export(objective)
 export(optimize.portfolio.parallel)
 export(optimize.portfolio.rebalancing)
@@ -38,6 +39,7 @@
 export(plot.optimize.portfolio)
 export(portfolio_risk_objective)
 export(portfolio.spec)
+export(position_limit_constraint)
 export(random_portfolios)
 export(random_walk_portfolios)
 export(randomize_portfolio)

Modified: pkg/PortfolioAnalytics/R/constraints.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraints.R	2013-06-28 21:31:08 UTC (rev 2469)
+++ pkg/PortfolioAnalytics/R/constraints.R	2013-06-28 23:54:09 UTC (rev 2470)
@@ -173,11 +173,11 @@
   )
 }
 
-#' General interface for adding and/or updating optimization constraints, currently supports weight, box and group constraints.
+#' General interface for adding and/or updating optimization constraints.
 #' 
 #' This is the main function for adding and/or updating constraints in an object of type \code{\link{portfolio}}.
 #' 
-#' In general, you will define your constraints as: 'weight_sum', 'box', 'group', 'turnover', 'diversification', or 'volatility'.  
+#' In general, you will define your constraints as: 'weight_sum', 'box', 'group', 'turnover', 'diversification', 'volatility', or 'position_limit'.  
 #' 
 #' @param portfolio an object of class 'portfolio' to add the constraint to, specifying the constraints for the optimization, see \code{\link{portfolio.spec}}
 #' @param type character type of the constraint to add or update, currently 'weight_sum', 'box', 'group', 'turnover', 'diversification', or 'volatility'
@@ -185,7 +185,7 @@
 #' @param \dots any other passthru parameters to specify box and/or group constraints
 #' @param indexnum if you are updating a specific constraint, the index number in the $objectives list to update
 #' @author Ross Bennett
-#' @seealso \code{\link{constraint_v2}}, \code{\link{weight_sum_constraint}}, \code{\link{box_constraint}}, \code{\link{group_constraint}}, \code{\link{turnover_constraint}}, \code{\link{diversification_constraint}}, \code{\link{volatility_constraint}}
+#' @seealso \code{\link{constraint_v2}}, \code{\link{weight_sum_constraint}}, \code{\link{box_constraint}}, \code{\link{group_constraint}}, \code{\link{turnover_constraint}}, \code{\link{diversification_constraint}}, \code{\link{volatility_constraint}}, \code{\link{position_limit_constraint}}
 #' @export
 add.constraint <- function(portfolio, type, enabled=FALSE, ..., indexnum=NULL){
   # Check to make sure that the portfolio passed in is a portfolio object
@@ -231,6 +231,11 @@
                                                                enabled=enabled,
                                                                ...=...)
          },
+         # Position limit constraint
+         position_limit = {tmp_constraint <- position_limit_constraint(type=type,
+                                                                       enabled=enabled,
+                                                                       ...=...)
+         },
          # Do nothing and return the portfolio object if type is NULL
          null = {return(portfolio)}
   )
@@ -534,6 +539,23 @@
   return(Constraint)
 }
 
+#' constructor for position_limit_constraint
+#' 
+#' 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)
+#' 
+#' @param type character type of the constraint
+#' @param max.pos maximum number of positions
+#' @param enabled TRUE/FALSE
+#' @param \dots any other passthru parameters to specify box and/or group constraints
+#' @author Ross Bennett
+#' @export
+position_limit_constraint <- function(type, max.pos, enabled=FALSE, ...){
+  Constraint <- constraint_v2(type, enabled=enabled, constrclass="position_limit_constraint", ...)
+  Constraint$max.pos <- max.pos
+  return(Constraint)
+}
+
 #' function for updating constrints, not well tested, may be broken
 #' 
 #' can we use the generic update.default function?

Modified: pkg/PortfolioAnalytics/man/add.constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/add.constraint.Rd	2013-06-28 21:31:08 UTC (rev 2469)
+++ pkg/PortfolioAnalytics/man/add.constraint.Rd	2013-06-28 23:54:09 UTC (rev 2470)
@@ -1,6 +1,6 @@
 \name{add.constraint}
 \alias{add.constraint}
-\title{General interface for adding and/or updating optimization constraints, currently supports weight, box and group constraints.}
+\title{General interface for adding and/or updating optimization constraints.}
 \usage{
   add.constraint(portfolio, type, enabled = FALSE, ...,
     indexnum = NULL)
@@ -30,7 +30,7 @@
 \details{
   In general, you will define your constraints as:
   'weight_sum', 'box', 'group', 'turnover',
-  'diversification', or 'volatility'.
+  'diversification', 'volatility', or 'position_limit'.
 }
 \author{
   Ross Bennett
@@ -42,6 +42,7 @@
   \code{\link{group_constraint}},
   \code{\link{turnover_constraint}},
   \code{\link{diversification_constraint}},
-  \code{\link{volatility_constraint}}
+  \code{\link{volatility_constraint}},
+  \code{\link{position_limit_constraint}}
 }
 

Modified: pkg/PortfolioAnalytics/man/turnover_constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/turnover_constraint.Rd	2013-06-28 21:31:08 UTC (rev 2469)
+++ pkg/PortfolioAnalytics/man/turnover_constraint.Rd	2013-06-28 23:54:09 UTC (rev 2470)
@@ -2,13 +2,13 @@
 \alias{turnover_constraint}
 \title{constructor for turnover_constraint}
 \usage{
-  turnover_constraint(type, max.turnover, enabled = FALSE,
-    ...)
+  turnover_constraint(type, turnover.target,
+    enabled = FALSE, ...)
 }
 \arguments{
   \item{type}{character type of the constraint}
 
-  \item{max.turnover}{maximum turnover value}
+  \item{turnover.target}{target turnover value}
 
   \item{enabled}{TRUE/FALSE}
 
@@ -19,11 +19,12 @@
   This function is called by add.constraint when
   type="turnover" is specified. see
   \code{\link{add.constraint}} This function allows the
-  user to specify a maximum turnover constraint
+  user to specify a target turnover value
 }
 \details{
   Note that turnover constraint is currently only supported
-  for global minimum variance problem with solve.QP plugin
+  for global minimum variance problem with ROI quadprog
+  plugin
 }
 \author{
   Ross Bennett

Modified: pkg/PortfolioAnalytics/man/volatility_constraint.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/volatility_constraint.Rd	2013-06-28 21:31:08 UTC (rev 2469)
+++ pkg/PortfolioAnalytics/man/volatility_constraint.Rd	2013-06-28 23:54:09 UTC (rev 2470)
@@ -2,16 +2,14 @@
 \alias{volatility_constraint}
 \title{constructor for volatility_constraint}
 \usage{
-  volatility_constraint(type, min.vol, max.vol,
-    enabled = FALSE, ...)
+  volatility_constraint(type, vol.target, enabled = FALSE,
+    ...)
 }
 \arguments{
   \item{type}{character type of the constraint}
 
-  \item{min.vol}{minimum volatility constraint}
+  \item{vol.target}{target volatilty constraint}
 
-  \item{max.vol}{maximum volatilty constraint}
-
   \item{enabled}{TRUE/FALSE}
 
   \item{\dots}{any other passthru parameters to specify box
@@ -20,10 +18,8 @@
 \description{
   This function is called by add.constraint when
   type="volatility" is specified,
-  \code{\link{add.constraint}} If portfolio standard
-  deviation is less than min.vol, add penalty to maximize
-  If portfolio standard deviation is greater than max.vol,
-  add penalty to minimize
+  \code{\link{add.constraint}} Penalize if portfolio
+  standard deviation deviates from volatility target
 }
 \author{
   Ross Bennett



More information about the Returnanalytics-commits mailing list