Optimization By Simulated Annealing

4
GLOBAL ASSOCIATION OF RISK PROFESSIONALS 45 T he introduction of the Markowitz Efficient Frontier more than 50 years ago popularized the use of mathematical optimization techniques in finance. The central idea of portfolio optimiza- tion is that if the risk and return of available financial instruments could be quantified accu- rately, then portfolios that minimize risk for target levels of return could be identified. Thus, portfolio optimization comprises two distinct problems: the first problem is to decide on measures of risk and return and to quantify the risk-return relationship of a portfolio; the second is to iden- tify mathematically the portfolio (i.e., the combination of available instruments) that has optimal risk-return charac- teristics. One challenge in addressing the second problem is that the number of potential portfolios grows exponentially with the number of available instruments. For example, a portfolio manager with only 200 instruments can construct 2 200 potential portfolios. Enumerating and considering each potential portfolio is impractical because of computing time constraints. Also, the complexity of the risk-return function could exclude the possibility of effectively using If you are searching for portfolios that offer optimal combinations of risk and return, simulated annealing (SA) can prove a useful tool. Vallabh Muralikrishnan defines SA, explains the challenges posed by portfolio optimization and provides step-by-step instructions for implementing an SA algorithm. Optimization by Simulated Annealing GLOBAL ASSOCIATION OF RISK PROFESSIONALS PORTFOLIO OPTIMIZATION

description

My first paper, published in GARP\'s flagship magazine.

Transcript of Optimization By Simulated Annealing

Page 1: Optimization By Simulated Annealing

GLOBAL ASSOCIATION OF RISK PROFESSIONALS 45

The introduction of the Markowitz EfficientFrontier more than 50 years ago popularized theuse of mathematical optimization techniques infinance. The central idea of portfolio optimiza-tion is that if the risk and return of availablefinancial instruments could be quantified accu-

rately, then portfolios that minimize risk for target levels ofreturn could be identified. Thus, portfolio optimizationcomprises two distinct problems: the first problem is todecide on measures of risk and return and to quantify therisk-return relationship of a portfolio; the second is to iden-

tify mathematically the portfolio (i.e., the combination ofavailable instruments) that has optimal risk-return charac-teristics.

One challenge in addressing the second problem is thatthe number of potential portfolios grows exponentiallywith the number of available instruments. For example, aportfolio manager with only 200 instruments can construct2200 potential portfolios. Enumerating and considering eachpotential portfolio is impractical because of computingtime constraints. Also, the complexity of the risk-returnfunction could exclude the possibility of effectively using

If you are searching for portfolios that offer optimal combinations of risk and return, simulated annealing(SA) can prove a useful tool. Vallabh Muralikrishnan defines SA, explains the challenges posed byportfolio optimization and provides step-by-step instructions for implementing an SA algorithm.

Optimization bySimulated Annealing

GLOB AL ASSOCIAT ION OF R I SK PROFESS IONALS

P O RT F O L I O O P T I M I Z AT I O N

Page 2: Optimization By Simulated Annealing

GLOB AL ASSOCIAT ION OF R I SK PROFESS IONALS

GLOBAL ASSOCIATION OF RISK PROFESSIONALS46 JUNE / JULY 08 I SSUE 4422

P O RT F O L I O O P T I M I Z AT I O N

the gradient search method (the most popular non-linearoptimization technique).

The gradient search method tends to converge on localoptimums and requires matrix inversions that can be timeconsuming or impossible if the objective function is notsmooth or differentiable. Therefore, search algorithms canbe used to scan the vast space of potential portfolios effi-ciently for optimal combinations of instruments.

Simulated annealing is one such algorithm. This articleillustrates how simulated annealing (SA) can be used toidentify portfolios with optimal combinations of risk andreturn.

SA is an optimization heuristic inspired by the cooling ofsolids. As a substance cools, its molecules arrange them-selves into a low energy state (as measured by an “energyfunction”). The energy function could have several localminima. The cooling process is akin to minimizing theenergy function. It is an empirical fact that the rate of cool-ing determines the final structure of the solid, and the solidformed by rapid cooling is usually not as stable as the solidformed by a slower cooling schedule. This is because rapidcooling forces the molecules into the first locally minimalenergy state that they happen to chance upon. A slowercooling schedule increases the probability that the mole-cules converge on the globally minimal energy state.

When applied to portfolio construction, the SA algo-rithm begins with a randomly selected portfolio. It theniteratively jumps to other portfolios in the neighborhood ofits current position in search of better risk-return metrics.However, in order to avoid converging to a local minimum,which is the bane of greedy algorithms, the SA heuristicallows a non-zero probability of moving to portfolios withworse risk-return metrics. This prevents the heuristic fromgetting stuck at a local minimum. The probability of jump-

ing to a worse portfolio is controlled by the “cooling sched-ule,” and as the cooling schedule reaches completion, theSA algorithm evolves into a simple greedy algorithm. Thefollowing example illustrates how the SA algorithm can bedeployed.

A Simple IllustrationFirst, we must set up the problem. For the purpose of illus-tration, we will consider the problem of selecting an opti-mal overlay portfolio of credit default swaps (CDS) tohedge and improve returns on a bank’s loan portfolio whilemanaging the overlay portfolio’s mark-to-market (MTM)volatility. Based on fundamental analysis, internal con-straints and personal judgment, we will assume that theportfolio manager has developed a list of 200 potentialCDS transactions from which to construct a portfolio (“theCDS universe”). Presumably, he has restricted this universeto CDS positions that he would feel comfortable transact-ing based on his view of idiosyncratic risks. One measureof return to be used in this context is economic value added(EVA). The portfolio manager will only want to take CDSpositions with positive EVA.

After screening for idiosyncratic risks, the portfolio man-ager may also focus on minimizing the expected MTMvolatility of the overlay portfolio. The MTM volatility ofthe CDS portfolio is directly related to the volatility of thecredit spreads associated with each position in the portfo-lio. Therefore a crude measure of this risk is the historicalstandard deviation of credit spreads weighted by portfolionotional (STD), as calculated below. The portfolio manag-er will want to minimize the expected volatility of the over-lay portfolio.

The risk-return relationship of potential portfolios cannow be measured by the following ratio: EVA/STD. This isthe objective function to be maximized. Clearly, EVA maynot be a desired measure of return, and the historical stan-dard deviation of credit spreads may not fully measure theexpected MTM volatility of a CDS portfolio.Nevertheless, these simple measures will be used to illus-trate the simulated annealing technique. The choice ofappropriate risk and return measures will depend on thegoals and context of portfolio optimization, which is notthe subject of this article.

The EVA for a particular CDS can be calculated usingthe following formula:

In the above formula, the “Expected Revenue” is sim-ply the annual spread multiplied by the notional. The“Capital” term can refer to either the regulatory or eco-nomic capital to be held by the institution for a particular

“When applied to portfolio con-struction, the SA algorithm begins

with a randomly selected portfolio.It then iteratively jumps to other

portfolios in the neighborhood ofits current position in search of bet-

ter risk-return metrics.’

Page 3: Optimization By Simulated Annealing

GLOB AL ASSOCIAT ION OF R I SK PROFESS IONALS

GLOBAL ASSOCIATION OF RISK PROFESSIONALS 47

transaction. If $10 million notional in protection is sold(long position) for 50 basis points (bps), then the annualexpected revenue is simply $50,000. If protection isbought (short position) on the same terms, the annualexpected revenue (i.e., cost) is $50,000. Of course, longpositions incur a positive capital charge, while short posi-tions incur a negative capital charge (i.e., capital release).The portfolio EVA is simply the sum the EVA of compo-nent swaps.

The historical standard deviation (in dollars) of a portfo-lio of CDS can be calculated using the following formula:

In the above formula, “w” is a vector containing thenotional amounts of CDS in the portfolio, and “™” is thecovariance matrix of historical spreads for the swaps. STDis in dollar terms.

Implementation StepsNow that the problem is set up, we can implement the SAalgorithm. The first step is to define the following threefunctions: the annealing schedule, the neighbor generatorand acceptance probability. These functions must be testedand refined empirically for each problem.

The annealing schedule is used to control the path theheuristic takes as it searches for the global optimum. Itsvalue depends on how far along the SA algorithm has pro-gressed. Initially, it allows the heuristic to search the spaceof portfolios randomly. As the routine progresses, however,the annealing schedule forces the heuristic to move towardthe maximum. For our illustration here, we use a simplelinear annealing schedule represented by the followingfunction:

In the above formula, “N” is the total number of itera-tions over which we wish to run the SA heuristic, and “i”represents the current iteration. Clearly, the annealingschedule has the property that it produces values close to 1initially and then converges to 0 as the heuristic runs itscourse. The choice of annealing schedule is subjective andmust be chosen based on the design of neighbor generatorand acceptance probability functions.

The neighbor generator is used in each step to generatesample portfolios to consider on the next iteration. Eachtransaction in the swap universe is assigned an indicatorvariable (1 or 0) that indicates whether or not the swap isincluded in a portfolio. This can be accomplished by usinga random number generator to assign a vector of indicatorsto potential transactions:

The above random portfolio consists of all swaps withan indicator value of 1. The EVA/MTM value associatedwith this portfolio can be easily calculated using theappropriate formulas. On iteration i, a uniform randomnumber between 0 and 1 is generated and assigned toeach swap in the universe. That number is then comparedwith 0.5*schedule(i). If the random number assigned to aparticular swap is less than 0.5*schedule(i), then the indi-cator for that deal is switched from its current state. Foreach iteration, this function initially generates vastly dif-ferent portfolios. However, the variation in portfoliocomposition between iterations decreases as the heuristicwinds down.

Finally, in each step, an accep-tance probability is calculated todetermine whether to keep the cur-rent configuration of swaps (i.e.,the current portfolio) or to switchto the configuration proposed bythe neighbor generator. This proba-bility depends on the value of theobjective function corresponding tothe current and proposed configu-rations, as well as on schedule(i).

In our implementation, we setthe acceptance probability to 1 if

the proposed configuration yields a higher objective.Otherwise, we set the acceptance probability to a randomnumber between 0 and 1 multiplied by schedule(i). Clearly,the heuristic will always choose the proposed configurationif it yields a better objective. However, there is initially anon-zero probability of choosing a proposed configuration,even if it yields a worse objective. Still, since schedule(i)goes to 0 as the heuristic winds down, the probability ofaccepting a configuration with a worse objective alsodecreases to zero.

It is also important to note that in the implementationwe’ve outlined, the algorithm initially makes biggermoves (as evident from the neighbor function) and has agreater probability of selecting worse outcomes (as evi-dent from the acceptance function).

The initial large moves are not necessary, but they doallow for the algorithm to experiment with vastly differ-ent combinations from the initial starting point.However, the probability of selecting worse outcomesdecreases over time.

Given the three functions we’ve discussed (the annealing

P O RT F O L I O O P T I M I Z AT I O N

VallabhMuralikrishnan

Page 4: Optimization By Simulated Annealing

GLOB AL ASSOCIAT ION OF R I SK PROFESS IONALS

GLOBAL ASSOCIATION OF RISK PROFESSIONALS48 JUNE / JULY 08 I SSUE 4422

P O RT F O L I O O P T I M I Z AT I O N

schedule, the neighbor generator and the acceptance proba-bility), it is clear that the SA algorithm can be implementedusing the following steps:

1. Decide on the number of iterations over which torun the algorithm. This is subjective and can be setbased on empirical tests.

2. Select a random starting portfolio and set it as the“best portfolio.”

3. Calculate the objective function value for this port-folio and store it.

4. Generate a neighbor portfolio and calculate theobjective function value for this new portfolio.

5. Based on the acceptance probability, accept orreject the new portfolio. If accepted, set the newportfolio as the “best portfolio” and update andstore the corresponding objective function value.

6. Repeat steps 4 and 5 until the maximum numberof iterations is reached.

Simulated Annealing vs. Greedy AlgorithmThe benefits of using SA over a greedy search algorithmcan be demonstrated empirically. Unlike SA, a greedy algo-rithm will only select portfolios that have higher values ofthe objective function. We can modify the SA algorithmoutlined earlier in this article to create a greedy algorithmand then compare the results of optimization by the twoalgorithms. A greedy algorithm can be created by simplysetting the acceptance probability to zero, if the objectiveof the proposed portfolio is less than the objective of the“current” portfolio on all iterations.

To test the effectiveness of the two search algorithms,we start with identical swap universes and identical start-ing points. This ensures that the value of the objectivefunction will be the same for identical portfolios regardlessof which algorithm is used. It also enables fair compar-isons because both algorithms start from the same point.The following table summarizes the results from the afore-mentioned experiment.

The result of the above experiment clearly shows that theSA search algorithm beats the greedy algorithm in every

case. This conclusion can be easily duplicated. However,even more interesting is the variability in the results of thesimulated annealing algorithm. To illustrate the variabilityof results, the two algorithms were run 10 times, and ele-mentary statistics were computed:

For a given number of iterations, there seems to be sig-nificant variability in the final objective value found by theimplementation of the SA algorithm.

Further Study: The Challenge of ConvergenceSA is a search algorithm and therefore is subject to thesame criticism as all search algorithms. In our experi-ment, we used SA to search a space of 2200 (over 1060)potential portfolios, with a maximum of 50,000 itera-tions. Due to the vast space of potential portfolios, con-vergence is understandably difficult. Several options areavailable to address the problem of convergence; none,however, is perfect.

One option is to increase the number of iterations, butthis will be restricted by available computing time. Anotheroption is to start from several different starting points andcompare the results. A third option is to use SA to identifyone solution and then use that solution as the starting pointfor a gradient search.

Much experimentation is required to customize the SAalgorithm for a particular problem. Nevertheless, SAremains a useful tool in the search of optimal portfolios. ■

FOOTNOTES:1.“Portfolio Selection,” Journal of Finance 7, no. 1 (March 1952): 77-91.

✎ VALLABH MURALIKRISHNAN is an associate in the asset portfolio management group at BMO Capital Markets. He has a masters inmathematical finance from the University of Toronto. He can be reached at [email protected]