Learn R Programming

rportfolios (version 1.0-1)

random.equal: Random equal weighted portfolios

Description

This function generates a random portfolio of n investments in which there are only k positive equal weights. The weights sum to the given value $x_t$.

Usage

random.equal(n = 2, k = n, segments = NULL, x.t = 1)

Arguments

n
A positive integer for the number of investments in the portfolio
k
A positive integer for the number of investments with positive equal weights
segments
A vector or list of vectors that defines the portfolio segments
x.t
A positive numeric value for the sum of weights

Value

An $n \times 1$ numeric vector of investment weights for the equal weighted portfolio. The weights are proportions of invested capital.

Details

The R function sample is used to generate a simple random sample without replacement of k values from the integers $1,2, \ldots ,n$. These are the subscripts into an $n \times 1$ zero vector to assign the equal weight $x_t / k$.

Examples

Run this code
x <- random.equal( 30, 5 )

Run the code above in your browser using DataLab