random.portfolio {PortfolioProbe} | R Documentation

## Generate Random Portfolios

### Description

Returns a list of portfolios that satisfy the constraints imposed, but the utility is ignored.

### Usage

    random.portfolio(number.rand=1, ..., out.trade=FALSE,
            seed=NULL, control=random.portfolio.control)

### Arguments

`number.rand` | the number of random portfolios desired. This can be zero (in which case `NULL` is returned), but can not be negative.
`...` | arguments of `trade.optimizer` need to be given that specify the constraints. Arguments concerning utility are ignored.
`out.trade` | logical value stating if it should be the random trades (`TRUE`), or the resulting random portfolios (`FALSE`) that are to be returned. The full name ("out.trade") needs to be given – no abbreviations are allowed.
`seed` | either `NULL` or a random seed to use for the computations. If `NULL`, then a random seed is created. The full name ("seed") needs to be given – no abbreviations are allowed.
`control` | a list like the output of `random.portfolio.control` or a function that produces such a list. The full name ("control") needs to be given – no abbreviations are allowed.

### Value

unless `intermediate` is given, a list of the random portfolios or trades. This has attributes:

`call` | an image of the call that created the object.
`timestamp` | a character string giving the time and date of creation.
`seed` | the random seed for the generator internal to the C code.
`version` | a vector stating the versions of C and S code used. This attribute is suppressed when the object is printed.
`checkinput` | a list with components `prices`, `variance`, `expected.return` and `existing` that contains a few values of each of these inputs. This is used in `randport.eval` and `update` to make sure that the data for these inputs are what you expect they are. This attribute is suppressed when the object is printed.
`funevals` | the number of portfolios that were examined during the search. This attribute is suppressed when the object is printed.
`iterhistory` | only present if the `save.iterhistory` control argument is `TRUE`, and is seldom of any interest. If present, it is a numeric vector giving the value of the objective at each iteration of the algorithm for the last random portfolio that is generated. The value of the objective is a measure of how much a given portfolio violates the constraints.
`class` | `"randportBurSt"`. There are several methods for this class.

### Side Effects

the S language random seed is created or changed (unless the `seed` argument is given explicitly and is not `NULL`).

An error occurs if no portfolios were found that satisfy the constraints, unless the `throw.error` control is set to `FALSE`. This generally only happens if the constraints are inconsistent, or at least very restrictive. In the latter case, you can adjust control arguments to search more thoroughly.

### Details

It is possible that fewer portfolios are generated than requested. This happens if too many attempts fail. There is a warning for this unless the `do.warn` item `randport.fail` is set to `FALSE`.

If you want a bound on the utility, then you can use `random.portfolio.utility`. However, this is substantially slower than using `random.portfolio`.

There are `randportBurSt` methods for several generic functions.

When tracing is done, a message gives: the number of optimizations, the number of satisfactory portfolios found, and the number of failures.

The `intermediate` argument allows some computations to be avoided in some circumstances. The amount of computation per call is in the millisecond range, so is unlikely to be important. The way it would be used is to make one call with `intermediate="Clist"` and then to pass a modification of that list as the `intermediate` argument multiple times. The list in question is a list of objects ready to be passed into the C code (plus a few other things).

### Bugs

Tracing generally does not work under Windows.

### Revision

This help was last revised 2011 March 24.

### See Also

`trade.optimizer`, `random.portfolio.control`, `random.portfolio.utility`, `randport.eval`, `deport.randportBurSt`, `summary.randportBurSt`, `valuation.randportBurSt`, `head.randportBurSt`, `update.randportBurSt`, `seed.BurSt`.

### Examples

    randport1 <- random.portfolio(100, prices, varian, long.only=TRUE,
            bench.constr=c(spx=.04^2/252), lin.constraints=cntrysect.conmat,
            lin.bounds=cntrysect.bounds, gross.value=1e6)

    randtrade1 <- random.portfolio(100, prices, varian, long.only=TRUE,
            bench.constr=c(spx=.04^2/252), lin.constraints=cntrysect.conmat,
            lin.bounds=cntrysect.bounds, gross.value=1e6, out.trade=TRUE)

    # now use it
    randalpha1 <- numeric(length(randtrade1))
    for(i in 1:length(randtrade1)) {
            randalpha1[i] <- trade.optimizer(prices, varian, long.only=TRUE,
              bench.constr=c(spx=.04^2/252), lin.constraints=cntrysect.conmat,
              lin.bounds=cntrysect.bounds, gross.value=1e6, funeval=0,
              start=randtrade1[[i]])$alpha.values
    }

    # same thing again
    randalpha1 <- unlist(randport.eval(randtrade1, keep="alpha.values"))
    # and again
    randalpha1 <- unlist(randport.eval(randport1, keep="alpha.values"))

[Package PortfolioProbe version 1.03 Index]