Description Usage Arguments Details Value Author(s) Examples
This function generates a general random portfolio of n investments with k long or short positiobs, The probability that a a non-zero investment weight is positive is p. The maximum absolute exposure for any investment is x.u. The default value is 1.
1  | random.general(n = 2, k=n, segments=NULL, p = 0.5, x.u = 1)
 | 
n | 
 A positive integer value for the number of investments in the portfolio  | 
k | 
 A positive integer value for the number of non-zero positions  | 
segments | 
 A vector or list of vectors that defines the portfolio segments  | 
p | 
 A positive numeric value for the probability that an investment weight is positive  | 
x.u | 
 A positive numeric value for the maximum absolute exposure to an investment  | 
If  k < n the function random.general is recursively called with n set equal to k
to obtain a k \times 1 vector of non-zero long and short weights.
The R function sample is used to generate a simple random sample without replacement
of k values from the integers 1,2, … ,n.  These are the subscripts into 
an n \times 1 zero vector to assign the k non-zero weights.  This vector is returned.
If  k = n , the R function rbinom is used to generate a vector of plus and minus ones corresponding
to the long and short positions.  The R function runif is used to generate uniformly
distributed values between 0 and 1.  These are scaled by x.u and then multiplied by the signs.
The sum of the investment weights is not restricted.
An n \times 1 numeric vector of investment weights for the equal weighted portfolio.
Frederick Novomestky fn334@nyu.edu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40  | ###
### long only portfolio of 30 investments with 30 non zero positions
###
x.long <- random.general( 30, p=1.0 )
###
### long only portfolio of 30 investments with 10 non zero positions
###
y.long <- random.general( 30, 10, p=1.0 )
###
### short only portfolio of 30 investments with 30 non zero positions
###
x.short <- random.general( 30, p=0.0 )
###
### short only portfolio of 30 investments with 10 non zero positions
###
y.short <- random.general( 30, 10, p=1.0 )
###
### long short portfolio of 30 investments with 30 non zero positions
###
x.long.short <- random.general( 30, p=0.5 )
###
### long short portfolio of 30 investments with 10 non zero positions
###
y.long.short <- random.general( 30, 10, p=0.5 )
###
### long bias portfolio of 30 investments with 30 non zero positions
###
x.long.bias <- random.general( 30, p=0.7 )
###
### long bias portfolio of 30 investments with 10 non zero positions
###
y.long.bias <- random.general( 30, 10, p=0.7 )
###
### short bias portfolio of 30 investments with 30 non zero positions
###
x.short.bias <- random.general( 30, p=0.3 )
###
### short bias portfolio of 30 investments with 10 non zero positions
###
y.short.bias <- random.general( 30, 10, p=0.3 )
 | 
Loading required package: truncdist
Loading required package: stats4
Loading required package: evd
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.