Differential Evolution with Deoptim
Total Page:16
File Type:pdf, Size:1020Kb
CONTRIBUTED RESEARCH ARTICLES 27 Differential Evolution with DEoptim An Application to Non-Convex Portfolio Optimiza- tween upper and lower bounds (defined by the user) tion or using values given by the user. Each generation involves creation of a new population from the cur- by David Ardia, Kris Boudt, Peter Carl, Katharine M. rent population members fxi ji = 1,. .,NPg, where Mullen and Brian G. Peterson i indexes the vectors that make up the population. This is accomplished using differential mutation of Abstract The R package DEoptim implements the population members. An initial mutant parame- the Differential Evolution algorithm. This al- ter vector vi is created by choosing three members of gorithm is an evolutionary technique similar to the population, xi1 , xi2 and xi3 , at random. Then vi is classic genetic algorithms that is useful for the generated as solution of global optimization problems. In this note we provide an introduction to the package . vi = xi + F · (xi − xi ), and demonstrate its utility for financial appli- 1 2 3 cations by solving a non-convex portfolio opti- where F is a positive scale factor, effective values for mization problem. which are typically less than one. After the first mu- tation operation, mutation is continued until d mu- tations have been made, with a crossover probability Introduction CR 2 [0,1]. The crossover probability CR controls the fraction of the parameter values that are copied from Differential Evolution (DE) is a search heuristic intro- the mutant. Mutation is applied in this way to each duced by Storn and Price(1997). Its remarkable per- member of the population. If an element of the trial formance as a global optimization algorithm on con- parameter vector is found to violate the bounds after tinuous numerical minimization problems has been mutation and crossover, it is reset in such a way that extensively explored (Price et al., 2006). DE has the bounds are respected (with the specific protocol also become a powerful tool for solving optimiza- depending on the implementation). Then, the ob- tion problems that arise in financial applications: for jective function values associated with the children fitting sophisticated models (Gilli and Schumann, are determined. If a trial vector has equal or lower 2009), for performing model selection (Maringer and objective function value than the previous vector it Meyer, 2008), and for optimizing portfolios under replaces the previous vector in the population; oth- non-convex settings (Krink and Paterlini, 2011). DE erwise the previous vector remains. Variations of is available in R with the package DEoptim. this scheme have also been proposed; see Price et al. In what follows, we briefly sketch the DE algo- (2006). rithm and discuss the content of the package DEop- Intuitively, the effect of the scheme is that the tim. The utility of the package for financial applica- shape of the distribution of the population in the tions is then explored by solving a non-convex port- search space is converging with respect to size and folio optimization problem. direction towards areas with high fitness. The closer the population gets to the global optimum, the more the distribution will shrink and therefore reinforce Differential Evolution the generation of smaller difference vectors. For more details on the DE strategy, we refer DE belongs to the class of genetic algorithms (GAs) the reader to Price et al.(2006) and Storn and Price which use biology-inspired operations of crossover, (1997). mutation, and selection on a population in order to minimize an objective function over the course The package DEoptim of successive generations (Holland, 1975). As with other evolutionary algorithms, DE solves optimiza- DEoptim (Ardia et al., 2011) was first published on tion problems by evolving a population of candi- CRAN in 2005. Since becoming publicly available, it date solutions using alteration and selection opera- has been used by several authors to solve optimiza- tors. DE uses floating-point instead of bit-string en- tion problems arising in diverse domains. We refer coding of population members, and arithmetic op- the reader to Mullen et al.(2011) for a detailed de- erations instead of logical operations in mutation, in scription of the package. DEoptim contrast to classic GAs. DEoptim consists of the core function Let NP denote the number of parameter vectors whose arguments are: 2 Rd (members) x in the population, where d de- • fn: the function to be optimized (minimized). notes dimension. In order to create the initial genera- tion, NP guesses for the optimal value of the param- • lower, upper: two vectors specifying scalar real eter vector are made, either using random values be- lower and upper bounds on each parameter to The R Journal Vol. 3/1, June 2011 ISSN 2073-4859 28 CONTRIBUTED RESEARCH ARTICLES be optimized. The implementation searches be- > set.seed(1234) tween lower and upper for the global optimum > DEoptim(fn = Rastrigin, of fn. + lower = c(-5, -5), + upper = c(5, 5), • control: a list of tuning parameters, among + control = list(storepopfrom = 1)) which: NP (default: 10 · d), the number of pop- ulation members and itermax (default: 200), The above call specifies the objective function to the maximum number of iterations (i.e., pop- minimize, Rastrigin, the lower and upper bounds ulation generations) allowed. For details on on the parameters, and, via the control argument, the other control parameters, the reader is re- that we want to store intermediate populations from ferred to the documentation manual (by typ- the first generation onwards (storepopfrom = 1). ing ?DEoptim). For convenience, the function Storing intermediate populations allows us to exam- DEoptim.control() returns a list with default ine the progress of the optimization in detail. Upon elements of control. initialization, the population is comprised of 50 ran- dom values drawn uniformly within the lower and • ...: allows the user to pass additional argu- upper bounds. The members of the population gen- ments to the function fn. erated by the above call are plotted at the end of The output of the function DEoptim is a member different generations in Figure2. DEoptim consis- of the S3 class DEoptim. Members of this class have a tently finds the minimum of the function (market plot and a summary method that allow to analyze the with an open white circle) within 200 generations us- optimizer’s output. ing the default settings. We have observed that DE- Let us quickly illustrate the package’s usage with optim solves the Rastrigin problem more efficiently the minimization of the Rastrigin function in R2, than the simulated annealing method available in the which is a common test for global optimization: R function optim (for all annealing schedules tried). Note that users interested in exact reproduction of > Rastrigin <- function(x) { results should set the seed of their random number + sum(x^2 - 10 * cos(2 * pi * x)) + 20 generator before calling DEoptim (using set.seed). } DE is a randomized algorithm, and the results may The global minimum is zero at point x = (0,0)0.A vary between runs. perspective plot of the function is shown in Figure1. Finally, note that DEoptim relies on repeated evaluation of the objective function in order to move the population toward a global minimum. Therefore, users interested in making DEoptim run as fast as possible should ensure that evaluation of the objec- tive function is as efficient as possible. Using pure R code, this may often be accomplished using vector- ization. Writing parts of the objective function in a lower-level language like C or Fortran may also in- crease speed. f(x_1,x_2) Risk allocation portfolios Mean-risk models were developed in early fifties for the portfolio selection problem. Initially, variance was used as a risk measure. Since then, many al- x_2 ternative risk measures have been proposed. The x_1 question of which risk measure is most appropriate is still the subject of much debate. Value-at-Risk (VaR) and Conditional Value-at-Risk (CVaR) are the most popular measures of downside risk. VaR is the neg- ative value of the portfolio return such that lower returns will only occur with at most a preset prob- ability level, which typically is between one and five percent. CVaR is the negative value of the mean of Figure 1: Perspective plot of the Rastrigin function. all return realizations that are below the VaR. There is a voluminous literature on portfolio optimization The function DEoptim searches for a minimum problems with VaR and CVaR risk measures, see, of the objective function between lower and upper e.g., Fábián and Veszprémi(2008) and the references bounds. A call to DEoptim can be made as follows: therein. The R Journal Vol. 3/1, June 2011 ISSN 2073-4859 CONTRIBUTED RESEARCH ARTICLES 29 Generation 1 Generation 20 4 4 2 2 2 0 2 0 x x −2 −2 −4 −4 −4 −2 0 2 4 −4 −2 0 2 4 x1 x1 Generation 40 Generation 80 4 4 2 2 2 0 2 0 x x −2 −2 −4 −4 −4 −2 0 2 4 −4 −2 0 2 4 x1 x1 Figure 2: The population (market with black dots) associated with various generations of a call to DEoptim as it searches for the minimum of the Rastrigin function at point x = (0,0)0 (market with an open white circle). The minimum is consistently determined within 200 generations using the default settings of DEoptim. The R Journal Vol. 3/1, June 2011 ISSN 2073-4859 30 CONTRIBUTED RESEARCH ARTICLES Modern portfolio selection considers additional age estimators, and their implementation in portfolio criteria such as to maximize upper-tail skewness and allocation, we refer the reader to Würtz et al.(2009, liquidity or minimize the number of securities in the Chapter 4).