Learn R Programming

rportfolios (version 1.0-1)

rgeneral: Generate random general portfolios

Description

This function generates m random general portfolios with n investments each. There are k positions that can be positive or negative. The probability that a given investment weight is positive is p. The maximum absolute exposure is x.u which has $1$ as the default

Usage

rgeneral(m, n = 2, k = n, segments = NULL, p = 0.5, x.u = 1)

Arguments

m
A positive integer value for the number of portfolios
n
A positive integer value for the number of investments in the portfolio
k
A positive integer value for the number of non-zero investment positions
segments
A vector or list of vectors that defines the portfolio segments
p
A positive numeric value for the probability that a non-zero position is positive
x.u
A positive numeric value for the maximum absolute exposure to an investment

Value

An $m \times n$ numeric matrix. The rows are the portfolios and the columns are the investment weights for each portfolio

Details

The function executes the function random.general using the R function sapply. The result returned is the transpose of the matrix generated in the previous step.

See Also

random.general

Examples

Run this code
###
### 100 long only portfolios of 30 investments with 30 non-zero positions
###
x.long <- rgeneral( 100, 30, p=1.0 )
###
### 100 long only portfolios of 30 investments with 10 non-zero positions
###
y.long <- rgeneral( 100, 30, 10, p=1.0 )
###
### 100 short only portfolios of 30 investments with 30 non-zero positions
###
x.short <- rgeneral( 100, 30, p=0.0 )
###
### 100 short only portfolios of 30 investments with 10 non-zero positions
###
y.short <- rgeneral( 100, 30, 10, p=0.0 )
###
### 100 long short portfolios of 30 investments with 30 non-zero positions
###
x.long.short <- rgeneral( 100, 30, p=0.5 )
###
### 100 long short portfolios of 30 investments with 10 non-zero positions
###
y.long.short <- rgeneral( 100, 30, 10, p=0.5 )
###
### 100 long bias portfolios of 30 investments with 30 non-zero positions
###
x.long.bias <- rgeneral( 100, 30, p=0.7 )
###
### 100 long bias portfolios of 30 investments with 10 non-zero positions
###
y.long.bias <- rgeneral( 100, 30, 10, p=0.7 )
###
### 100 short bias portfolios of 30 investments with 30 non-zero positions
###
x.short.bias <- rgeneral( 100, 30, p=0.3 )
###
### 100 short bias portfolios of 30 investments with 10 non-zero positions
###
y.short.bias <- rgeneral( 100, 30, 10, p=0.3 )

Run the code above in your browser using DataLab