random.portfolio.utility {PortfolioProbe} | R Documentation

## Generate Random Portfolios with a Utility Constraint

### Description

Returns a list of portfolios that satisfy the constraints imposed, and includes a constraint on the utility.

### Usage

    random.portfolio.utility(number.rand = 1, objective.limit, prices,
            variance = NULL, expected.return = NULL, gen.fail = 4,
            objfail.max = 1, ..., out.trade = FALSE, verbose = FALSE)

### Arguments

`number.rand` | the number of random portfolios desired. This can be zero (in which case `NULL` is returned), but can not be negative.
`objective.limit` | a number that gives the upper bound for the objective. The objective is the negative of the utility (except for minimum variance but you should use `random.portfolio` for this utility).
`prices` | the vector of prices. See the `trade.optimizer` help file for the description.
`variance` | the variance. See the `trade.optimizer` help file for the description.
`expected.return` | the expected returns. See the `trade.optimizer` help file for the description.
`gen.fail` | a single number. The maximum number of failures that are allowed is `gen.fail` times `number.rand`.
`objfail.max` | a single number – the maximum number of times that a try can fail to achieve the objective limit.
`...` | arguments of `trade.optimizer` need to be given that specify the constraints and the utility.
`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 of this argument needs to be given.
`verbose` | a logical value. If `TRUE`, then messages about the progress are printed. The full name of this argument needs to be given.

### Value

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 for the first try.
`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 value `NA`. This attribute is suppressed when the object is printed.
`class` | `"randportBurSt"`. There are several methods for this class.

### Side Effects

the S language random seed is created or changed.

### Details

It is possible that fewer portfolios are generated than requested. There is a warning for this.

There are two types of failure:

1) The try can fail to decrease the objective enough. If this happens on the first try and `objfail.max=1` (the default), then an error occurs. Otherwise, computation stops if the number of such failures is `objfail.max` – the result contains the portfolios or trades that have been successful (which theoretically could be none).

2) The try could achieve the necessary objective but fail on other constraints. This is likely to be a rare event.

Although `random.portfolio.utility` and `random.portfolio` return objects that are essentially the same, their internal operation is quite different. `random.portfolio` calls the underlying C code once and uses a search that is optimized to find portfolios that satisfy constraints. In contrast `random.portfolio.utility` makes a call to `trade.optimizer` on each try. (The starting point is made totally random and it is told to stop once it achieves the objective limit, but is otherwise the same as ordinary calls to `trade.optimizer`.)

The `seed` argument is ignored. If you want to have reproducible results, then you need to set the S language seed.

There are `randportBurSt` methods for several generic functions.

### Bugs

For safety, the `start.sol` argument is ruled out. Unfortunately, an error is thrown even if `start.sol` is given but `NULL`.

### Revision

This help was last revised 2009 December 30.

### See Also

`trade.optimizer`, `random.portfolio`, `randport.eval`, `deport.randportBurSt`, `summary.randportBurSt`, `valuation.randportBurSt`, `head.randportBurSt`, `update.randportBurSt`.

### Examples

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

    randtrade1 <- random.portfolio.utility(100, objective.limit=-.2, prices,
            varian, expected.return=alphas, 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.02 Index]