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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 20 02:12:41 CEST 2013


Author: rossbennett34
Date: 2013-08-20 02:12:41 +0200 (Tue, 20 Aug 2013)
New Revision: 2830

Added:
   pkg/PortfolioAnalytics/man/quadratic_utility_objective.Rd
Modified:
   pkg/PortfolioAnalytics/NAMESPACE
   pkg/PortfolioAnalytics/R/objective.R
   pkg/PortfolioAnalytics/man/add.objective.Rd
Log:
adding quadratic_utility as an objective type

Modified: pkg/PortfolioAnalytics/NAMESPACE
===================================================================
--- pkg/PortfolioAnalytics/NAMESPACE	2013-08-19 19:22:08 UTC (rev 2829)
+++ pkg/PortfolioAnalytics/NAMESPACE	2013-08-20 00:12:41 UTC (rev 2830)
@@ -72,6 +72,7 @@
 export(print.optimize.portfolio.random)
 export(print.optimize.portfolio.ROI)
 export(print.portfolio)
+export(quadratic_utility_objective)
 export(random_portfolios_v1)
 export(random_portfolios_v2)
 export(random_portfolios)

Modified: pkg/PortfolioAnalytics/R/objective.R
===================================================================
--- pkg/PortfolioAnalytics/R/objective.R	2013-08-19 19:22:08 UTC (rev 2829)
+++ pkg/PortfolioAnalytics/R/objective.R	2013-08-20 00:12:41 UTC (rev 2830)
@@ -130,7 +130,7 @@
   # to add objectives to a portfolio object instead of a constraint object.
   if (!is.portfolio(portfolio)) {stop("portfolio passed in is not of class portfolio")}
   
-  if (!hasArg(name)) stop("you must supply a name for the objective")
+  if (type != "quadratic_utility" & !hasArg(name)) stop("you must supply a name for the objective")
   if (!hasArg(type)) stop("you must supply a type of objective to create")
   if (!hasArg(enabled)) enabled=TRUE
   if (!hasArg(arguments) | is.null(arguments)) arguments<-list()
@@ -176,7 +176,12 @@
                                                         arguments=arguments,
                                                         ...=...)
          },
-         
+         qu=, quadratic_utility = {tmp_objective = quadratic_utility_objective(enabled=enabled, ...=...)
+                              # quadratic_utility_objective returns a list of a return_objective and a portfolio_risk_objective
+                              # we just need to combine it to the portfolio$objectives slot and return the portfolio
+                              portfolio$objectives <- c(portfolio$objectives, tmp_objective)
+                              return(portfolio)
+         },
          null = 
            {return(portfolio)} # got nothing, default to simply returning
          ) # end objective type switch
@@ -201,7 +206,7 @@
 #' 
 #' @param portfolio an object of type 'portfolio' to add the objective to, specifying the portfolio for the optimization, see \code{\link{portfolio}}
 #' @param constraints a 'v1_constraint' object for backwards compatibility, see \code{\link{constraint}}
-#' @param type character type of the objective to add or update, currently 'return','risk', or 'risk_budget'
+#' @param type character type of the objective to add or update, currently 'return','risk', 'risk_budget', or 'quadratic_utility'
 #' @param name name of the objective, should correspond to a function, though we will try to make allowances
 #' @param arguments default arguments to be passed to an objective function when executed
 #' @param enabled TRUE/FALSE
@@ -383,6 +388,28 @@
   return(Objective)
 } # end minmax_objective constructor
 
+#' constructor for quadratic utility objective
+#' 
+#' This function calls \code{\link{return_objective}} and \code{\link{portfolio_risk_objective}}
+#' to create a list of the objectives to be added to the portfolio.
+#' 
+#' @param risk_aversion risk_aversion (i.e. lambda) parameter to penalize variance
+#' @param target target mean return value
+#' @param enabled TRUE/FALSE, default enabled=TRUE
+#' @return a list of two elements
+#' \itemize{
+#'   \item{\code{return_objective}}
+#'   \item{\code{portfolio_risk_objective}}
+#' }
+#' @author Ross Bennett
+#' @export
+quadratic_utility_objective <- function(risk_aversion=1, target=NULL, enabled=TRUE){
+  qu <- list()
+  qu[[1]] <- return_objective(name="mean", target=target, enabled=enabled)
+  qu[[2]] <- portfolio_risk_objective(name="var", risk_aversion=risk_aversion, enabled=enabled)
+  return(qu)
+} # end quadratic utility objective constructor
+
 #' Insert a list of objectives into the objectives slot of a portfolio object
 #' 
 #' @param portfolio object of class 'portfolio'

Modified: pkg/PortfolioAnalytics/man/add.objective.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/add.objective.Rd	2013-08-19 19:22:08 UTC (rev 2829)
+++ pkg/PortfolioAnalytics/man/add.objective.Rd	2013-08-20 00:12:41 UTC (rev 2830)
@@ -23,7 +23,8 @@
   compatibility, see \code{\link{constraint}}}
 
   \item{type}{character type of the objective to add or
-  update, currently 'return','risk', or 'risk_budget'}
+  update, currently 'return','risk', 'risk_budget', or
+  'quadratic_utility'}
 
   \item{name}{name of the objective, should correspond to a
   function, though we will try to make allowances}

Added: pkg/PortfolioAnalytics/man/quadratic_utility_objective.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/quadratic_utility_objective.Rd	                        (rev 0)
+++ pkg/PortfolioAnalytics/man/quadratic_utility_objective.Rd	2013-08-20 00:12:41 UTC (rev 2830)
@@ -0,0 +1,29 @@
+\name{quadratic_utility_objective}
+\alias{quadratic_utility_objective}
+\title{constructor for quadratic utility objective}
+\usage{
+  quadratic_utility_objective(risk_aversion = 1,
+    target = NULL, enabled = TRUE)
+}
+\arguments{
+  \item{risk_aversion}{risk_aversion (i.e. lambda)
+  parameter to penalize variance}
+
+  \item{target}{target mean return value}
+
+  \item{enabled}{TRUE/FALSE, default enabled=TRUE}
+}
+\value{
+  a list of two elements \itemize{
+  \item{\code{return_objective}}
+  \item{\code{portfolio_risk_objective}} }
+}
+\description{
+  This function calls \code{\link{return_objective}} and
+  \code{\link{portfolio_risk_objective}} to create a list
+  of the objectives to be added to the portfolio.
+}
+\author{
+  Ross Bennett
+}
+



More information about the Returnanalytics-commits mailing list