Learn R Programming

rportfolios (version 1.0-1)

portfolio.composite: Merge portfolios into a composite

Description

This function merges a list of portfolios using a specified set of weights. The components in the list can be single portfolio vectors a matrix of portfolios.

Usage

portfolio.composite(portfolios, weights = NULL)

Arguments

portfolios
A list of vectors or matrices corresponding to portfolios of investments
weights
A numeric vector of weights for the components

Value

A vector or matrix.

Details

The private function vector.composite is used to create a single portfolio from a list of portfolio weight vectors. The private function matrix.composite generates the weighted composite matrix from a list of portfolio weight matrices.

Examples

Run this code
segments <- list()
segments[[1]] <- c( 1, 2, 3 )
segments[[2]] <- c( 4, 5 )
segments[[3]] <- c( 6, 7 )
segments[[4]] <- c( 8, 9, 10 )
weights <- c( .3, .2, .2, .3 )
vectors <- list()
matrices <- list()
for ( i in 1:4 ) {
vectors[[i]] <- random.longonly( 10, segments=segments[[i]] )
matrices[[i]] <- rlongonly( 200, 10, segments=segments[[i]] )
}
combined.vectors <- portfolio.composite( vectors, weights )
combined.matrices <- portfolio.composite( matrices, weights )

Run the code above in your browser using DataLab