Learn R Programming

rportfolios (version 1.0-1)

extract.segments: Extract Investment Segment Exposures

Description

This function extracts the investment exposures from one or more portfolios for the specified investment segments.

Usage

extract.segments(portfolios, segments, collapse = FALSE)

Arguments

portfolios
A vector or matrix that defines the portfolios
segments
A vector or list of vectors that defines the investment segments
collapse
A logical value. If TRUE, only the investment segment exposures are returned

Value

A vector for one portfolio or a matrix for multiple portfolios.

Details

If the collapse argument is FALSE, the segment complement exposures are zero and the investment segment exposures are taken from the portfolios. If the collapse argument is TRUE, then only the investment segment exposures are returned. The private function vector.extract.segments is used to perform the extraction. For matrices of investment weights, the apply function is used with vector.extract.segments to obtain a matrix of extracted segment weights. The transpose of this matrix is returned.

Examples

Run this code
onePortfolio <- random.longonly( 10 )
I <- list()
I[[1]] <- c( 1, 2, 3 )
I[[2]] <- c( 4, 5 )
I[[3]] <- c( 6, 7 )
I[[4]] <- c( 8, 9, 10 )
extract.segments( onePortfolio, I[[1]], FALSE )
extract.segments( onePortfolio, I[[1]], TRUE )

Run the code above in your browser using DataLab