Learn R Programming

rportfolios (version 1.0-1)

set.segments: Set segment weights from portfolios

Description

This function assigns the given investment weights to larget portfolios using the investment indices in the segments

Usage

set.segments(portfolios, n, segments)

Arguments

portfolios
A vector or matrix of investment weights for the segments
n
A positive integer value for the number of investments in the larger portfolio
segments
A vector or list of vectors that defines the segment investments

Value

A vector or matrix.

Details

A private function vector.set.segments is used to take weights in a given portfolio vector and assign them to a larger vector using the collapsed investment index vector. If the portfolios argument is a matrix, then the R function apply is used to perform this task for each row vector.

See Also

collapse.segments

Examples

Run this code
###
### simulate 300 long only portfolios with 30 investments
###
portfolios <- rlongonly( 300, 30 )
###
### define six segments with five investments in each
###
segment1 <- 1:5
segment2 <- 11:15
segment3 <- 21:25
segment4 <- 31:35
segment5 <- 41:45
segment6 <- 51:55
segments <- list( segment1, segment2, segment3, segment4, segment5, segment6 )
newPortfolios <- set.segments( portfolios, 60, segments )

Run the code above in your browser using DataLab