Learn R Programming

rportfolios (version 1.0-1)

random.longonly: Random long only portfolio

Description

This function generates a vector of investment weights for a portfolio where the weights are non-negative, do not exceed a given upper and and the sum of the weights is a given total. The number of non zero positions is k.

Usage

random.longonly(n = 2, k = n, segments = NULL, x.t = 1, x.l=0, x.u = x.t, max.iter = 1000)

Arguments

n
An integer value for the number of investments in the portfolio
k
An integer value for the number of non zero weights
segments
A vector or list of vectors that defines the portfolio segments
x.t
Numeric value for the sum of the investment weights
x.l
Numeric value for the lower bound on an investment weight
x.u
Numeric value for the upper bound on an investment weight
max.iter
An integer value for the maximum iteration in the acceptance rejection loop

Value

A numeric vector with investment weights.

Details

The simulation method combines the acceptance rejection method used for generating gamma and gaussian random variables with a continuous analog of the method used in Ross (2006) to generate a vector of multinomial random variables. $n - 1$ random variables are constructed where the first $U_1$ is uniformly distributed in the interval $\left[ X_l, X_t \right]$. Random variable $U_2$ is a uniform random variable in $\left[ {X_l,X_t - U_1 } \right]$ given $U_1$. Random variable $U_3$ is a uniform random variable in $\left[ {0,X_t - U_1 - U_2 } \right]$ given $U_1$ and $U_2$. This conditional generation of uniform random variables stops with $U_{n - 1}$ which is uniform on $\left[ {X_l,X_t - \sum\limits_{j = 1}^{n - 2} {U_j } } \right]$ given the first $n - 2$ random variables. if $X_t - \sum\limits_{j = 1}^{n - 1} {U_j }$ is less than or equal to $X_u$, then the final random variable is $U_n = X_t - \sum\limits_{j = 1}^{n - 1} {U_j }$. Otherwise, the above procedure of generating uniform random variables conditionally is repeated until this condition is satisfied. The vector ${\mathbf{W}}$ is a random sample of size $n$ of the values in vector ${\mathbf{X}}$ where the sampling is performed without replacement.

References

Cheng, R. C. H., 1977. The Generation of Gamma Variables with Non-integral Sape Parameter, Journal of the Royal Statistical Society, Series C (Applied Statistics), 26(1), 71.

Kinderman, A. J. and J. G. Ramage, 1976. Computer Generation of Normal Random Variables, Journal of the American Statistical Association, December 1976, 71(356), 893.

Marsaglia, G. and T. A. Bray, 1964. A Convenient method for generating normal variables, SIAM Review, 6(3), July 1964, 260-264.

Ross, S. M. (2006). Simulation, Fourth Edition, Academic Press, New York NY.

Tadikamalla, P. R., (1978). Computer generation of gamma random variables - II, Communications of the ACM, 21 (11), November 1978, 925-928.

Examples

Run this code
###
### long only portfolio of 30 investments with 30 non-zero positions
###
x <- random.longonly( 30 )
###
### long only portfolio of 30 investments with 10 non-zero positions
###
y <- random.longonly( 30, 10 )

Run the code above in your browser using DataLab