| scenario.optimizer {pprobeSup} | R Documentation |
Uses random portfolios, a utility function (written in R) and an array of scenarios to optimize a portfolio.
scenario.optimizer(scenarios, utility, prices = NULL, existing = NULL, regulate = NULL, extraArgs = NULL, maximize = TRUE, verbose = TRUE, start.sol = NULL, checkPositive = TRUE, ...)
scenarios |
either a matrix or a three-dimensional array – most likely filled with asset prices. If a matrix, then the rows correspond to assets and need to be named with the asset identifiers. The columns represent different scenarios. If a 3-D array, then the rows are times, the columns are assets and the third diminesion is scenarios. |
utility |
a function that takes a random portfolio object as its first argument, it must have an argument called 'scenarios', and it may have additional arguments as well. It needs to return a single number for each random portfolio. |
prices |
named numeric vector of prices to be used in the generation of the random portfolios. If not given, then the first scenario (at the first time if there are multiple times) is used. |
existing |
named numeric vector giving the existing portfolio. The numbers are the number of units (shares, contracts, etc.) for the assets. |
regulate |
named numeric vector giving controls for the optimization process. See the Details section for specifics. |
extraArgs |
a list with named components giving additional arguments
to the |
maximize |
logical value: do you want to maximize or minimize the
|
verbose |
logical value: if |
start.sol |
named numeric vector (or a portfolio object containing a
|
checkPositive |
logical value: should |
... |
the constraints to be given to |
a list with components:
new.portfolio |
named numeric vector giving the number of units for each asset in the optimized portfolio. |
trade |
named numeric vector giving the number of units for each
asset in the trade from the existing portfolio to
|
existing |
named numeric vector giving the number of units for each
asset in the existing portfolio – the same as the input
|
utility.value |
the value of the utility for the optimized portfolio. |
optim |
a vector giving some details of the optimization process. |
violated |
either This is only given when the |
timestamp |
two character strings giving the time and date of the start and finish of the optimization. |
call |
an image of the call that created the object. |
The S language random seed is changed or created.
This depends explicitly on the random.portfolio function
from Portfolio Probe.
Utilities are likely to depend on the valuation method for
random portfolio objects.
OVERVIEW OF OPTIMIZATION PROCESS
There is an initial set of random portfolios that satisfy the problem constraints. The utility is evaluated on each of the random portfolios, and the portfolio with the best utility is selected as the candidate for the optimized portfolio.
Then some number of iterations is done. At each iteration some number of random portfolios is generated that are within some radius of best solution as well as satisfying the other constraints of the problem. If a better solution is found among the new random portfolios, then that becomes the new candidate solution. If none of the random portfolios have a better utility, then the radius is reduced.
The optimization terminates if either the radius becomes too small, or the limit on iterations is exhausted.
REGULATE VALUES
There are a number of values that can be given in the regulate
argument:
initbitesize the number of random portfolios to generate initially.
nbites the maximum number of iterations to do.
bitesize the number of random portfolios to generate at each iteration.
radius the initial maximum trade distance from the best solution to any random portfolio in the iterations.
reduce
when an iteration fails to improve the solution, then
the new radius is the old radius times reduce.
minradius if the new radius is less than this number, then the optimization stops.
returnstart
if TRUE, then no optimization is done but the result
of start.sol being the trade is returned.
This is the exception that regulate must be numeric.
DISCLAIMER
The only sense in which the values in regulate are optimal
is that minimum effort was put into deciding their values.
RETURN STARTING SOLUTION
To get the utility and other information for a particular trade,
then the regulate value of returnstart must be TRUE
and start.sol must be given.
WRITING YOUR OWN UTILITY
The utility functions that are provided are intended merely as examples. You can easily write your own utility function to satisfy your needs.
The function must take a first argument that is expected to be a
random portfolio object.
It must also have an argument named scenarios.
It can have any additional arguments that you desire.
The other key requirement is that the function needs to return a numeric vector that is as long as the number of random portfolios given it.
Most likely a call to valuation (from Portfolio Probe) will be made
using the random portfolios and the scenarios.
Several of the utility functions show how to get either the mean utility
or a quantile of the utility.
pputil.valueWt shows how to give different weights to different
scenarios.
pputil.multomega shows how to get a single utility by doing a
weighted sum of utilities at different times.
It is perfectly feasible to have both weighting schemes in a single
utility function.
Distance constraints are not allowed to be imposed (for the real problem). It would be possible to lift this restriction by adding some ugly code.
In test suite, mildly tested.
This help file was last revised 2013 May 02.
pp.historyScenarios,
pp.normalScenarios, pp.priceScenarios
pputil.fourmoments, pputil.meanvar,
pputil.omega, pputil.value.
# get the utility of a particular portfolio omegaTest <- scenario.optimizer(scenWith2timepoints, utility=pputil.omega, extraArgs=list(target=0.04), max.weight=.07, gross=1e7, long.only=TRUE, existing=NULL, port.size=c(20,30), start.sol=myPortfolio, regulate=c(returnstart=TRUE)) # see also the examples in the pputil.* help files