## Task

Perform a scenario optimization that maximizes the portfolio value (in the future).

## Preparation

You need:

- a matrix or three-dimensional array containing scenarios
- Portfolio Probe
- the
`pprobeSup`

package

The `pprobeSup`

package needs to be loaded into your R session:

require(pprobeSup)

If `pprobeSup`

is not installed on your machine, then you can get it with:

install.packages("pprobeSup", repos="http://www.portfolioprobe.com/R")

or alternatively with:

install.packages("pprobeSup", repos="http://www.portfolioprobe.com/R", type="source")

You also need to have the Portfolio Probe package loaded into your R session:

require(PortfolioProbe)

If you don’t have Portfolio Probe, see “Demo or Buy”.

### Doing the example

You need to have the `pprobeData`

package loaded into your R session:

require(pprobeData)

This package may be installed from the same repository as `pprobeSup`

.

## Doing it

### Preparation

We use a scenario object created in “generate historical scenarios”.

### Optimization

We need to specify the constraints for the portfolio in addition to the utility to use and the scenarios:

mvalOpt <- scenario.optimizer(monScen[2,,], utility=pputil.value, prices=monScen[1,,1], gross.value=1e6, long.only=TRUE, max.weight=.08, port.size=c(20,30))

The constraints for this problem are that the gross value of the portfolio is (close to) $1 million, the portfolio is long-only, no asset may have a weight greater than 8% and there are between 20 and 30 names in the portfolio.

Unlike examples with other utility functions, here we need to specify a value for `prices`

(the vector of current prices) because the scenarios for this utility are expected only to hold future price values.

The result is an object that holds the best portfolio found, the trade to get there, and some other information.

## Explanation

This might be a reasonable problem if the constraints included some form of risk control. But this particular specification is probably unreasonable.

What is being maximized is the average portfolio value — the average across scenarios. This is very much in the spirit of traditional optimization that maximizes expected (that is, mean) utility. See below for an alternative with this utility function.

## Further details

#### the number of iterations

You can specify the maximum number of iterations that can be used — the number of bites is the function’s analogy:

mvalOpt2 <- scenario.optimizer(monScen[2,,], utility=pputil.value, prices=monScen[1,,1], gross.value=1e6, long.only=TRUE, max.weight=.08, port.size=c(20,30), regulate=c(nbites=100))

#### maximizing a value quantile

One way to bring an element of risk control into maximizing value is to maximize a quantile of the value rather than the mean value. In this problem we maximize the 20% quantile. So the portfolios that are thought to be good need to perform at least moderately well for most of the scenarios.

q20valOpt <- scenario.optimizer(monScen[2,,], utility=pputil.value, prices=monScen[1,,1], extraArgs=list(level=.2), gross.value=1e6, long.only=TRUE, max.weight=.08, port.size=c(20,30), regulate=c(nbites=100))

#### scenario weighting

Not all scenarios need to have the same importance. Some scenarios may be thought more or less likely to occur. Alternatively, some scenarios may be thought to be more important if they do occur.

Here we have an example where the first few scenarios are considered more important than the rest.

q20wtvalOpt <- scenario.optimizer(monScen[2,,], utility=pputil.valueWt, prices=monScen[1,,1], extraArgs=list(level=.2, sweights=c(10,5,3,2, rep(1, 96))), gross.value=1e6, long.only=TRUE, max.weight=.08, port.size=c(20,30), regulate=c(nbites=100))

This is maximizing the weighted quantile — the scenarios with the larger weights count more in the quantile.

#### variance matrix

You can provide a variance matrix in order to impose variance constraints, tracking error constraints or risk fraction constraints.

## See also

- Maximize the omega ratio
- First four moments utility
- Write your own utility function
- the Portfolio Probe User’s Manual

## Navigation

- Back to “Scenario optimization”
- Back to “Optimize trades”
- Back to the top level of “Portfolio Probe Cookbook”