R/objective.R

Defines functions objective

Documented in objective

#' @title Set new objective of a portfolio.model
#' 
#' @description
#' \code{objective} sets a new objective for VaR and Expected Shortfall
#'
#' @param model the portfolio.model to be changed
#' @param objective the new objective
#' 
#' @return the adapted portfolio.model
#' 
#' @author Ronald Hochreiter, \email{ronald@@algorithmic.finance}
#'
#' @export
#'
#' @examples
#' data(sp100w17av30s)
#' model <- portfolio.model(scenario.set)
#' mad <- optimal.portfolio(objective(model, "mad"))
#'
objective <- function(model, objective="markowitz") {
  
  # check if alias is used for objective
  objective <- aux_risk.alias(objective)
  
  # check if selected objective is supported
  supported_objectives <- list("1overN", "momentum", "reward",
                               "markowitz", "mad", "expected.shortfall")

  # if not, fall back to markowitz
  if (!(objective %in% supported_objectives)) {
    warning("Selected objective is not supported! Falling back to objective: markowitz")
    objective <- "markowitz"
  }

  # set objective and return model
  model$objective <- objective
  return(model)
}

Try the portfolio.optimization package in your browser

Any scripts or data that you put into this service are public.

portfolio.optimization documentation built on May 2, 2019, 8:16 a.m.