12#' Combine objects created by optimize.portfolio3#'4#' This function takes a list of objects created by \code{\link{optimize.portfolio}}5#' and sets the class name attribute to 'opt.list' for use in generic functions6#'7#' @param x a list of objects created by \code{\link{optimize.portfolio}}8#' @return an \code{opt.list} object9#' @export10combine.optimizations <- function(x){11if(!is.list(x)) stop("x must be passed in as a list")12for(i in 1:length(x)){13if(!(inherits(x[[i]], "optimize.portfolio") | inherits(x[[i]], "optimize.portfolio.rebalancing"))){14stop("All objects in x must be of class 'optimize.portfolio' or 'optimize.portfolio.rebalancing'")15}16}17class(x) <- "opt.list"18return(x)19}2021#' Combine a list of portfolio objects22#'23#' This function takes a list of objects created by \code{\link{portfolio.spec}}24#' and sets the class name attribute to 'portfolio.list' for use in generic functions25#'26#' @param x a list of objects created by \code{\link{portfolio.spec}}27#' @return a \code{portfolio.list} object28#' @export29combine.portfolios <- function(x){30if(!is.list(x)) stop("x must be passed in as a list")31for(i in 1:length(x)){32if(!inherits(x[[i]], "portfolio")) stop("All objects in x must be of class 'portfolio'")33}34class(x) <- c("portfolio.list", "portfolio")35return(x)36}373839###############################################################################40# R (https://r-project.org/) Numeric Methods for Optimization of Portfolios41#42# Copyright (c) 2004-2021 Brian G. Peterson, Peter Carl, Ross Bennett, Kris Boudt43#44# This library is distributed under the terms of the GNU Public License (GPL)45# for full details see the file COPYING46#47# $Id$48#49###############################################################################505152