This document discusses using simulated annealing (SA) as an algorithm to optimize portfolios by finding optimal combinations of risk and return. SA is presented as an alternative to gradient search methods which tend to get stuck in local optima. The SA algorithm begins with a random portfolio and iteratively explores neighboring portfolios to search for better risk-return metrics. It allows for some probability of accepting worse portfolios to avoid local optima. Step-by-step instructions are provided for implementing an SA algorithm along with an example application to optimizing a credit default swap portfolio. The SA approach is shown to outperform a greedy search algorithm in finding superior risk-return portfolios.
1. G L O B A L A S S O C I AT I O N O F R I S K P R O F E S S I O N A L S
P O R T F O L I O O P T I M I Z AT I O N
Optimization by
Simulated Annealing
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.
he introduction of the Markowitz Efficient tify mathematically the portfolio (i.e., the combination of
T 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
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
2200 potential portfolios. Enumerating and considering each
potential portfolio is impractical because of computing
time constraints. Also, the complexity of the risk-return
risk-return relationship of a portfolio; the second is to iden- function could exclude the possibility of effectively using
GLOBAL ASSOCIATION OF RISK PROFESSIONALS 45
2. G L O B A L A S S O C I AT I O N O F R I S K P R O F E S S I O N A L S
P O R T F O L I O O P T I M I Z AT I O N
the gradient search method (the most popular non-linear ing to a worse portfolio is controlled by the “cooling sched-
optimization technique). ule,” and as the cooling schedule reaches completion, the
The gradient search method tends to converge on local SA algorithm evolves into a simple greedy algorithm. The
optimums and requires matrix inversions that can be time following example illustrates how the SA algorithm can be
consuming or impossible if the objective function is not deployed.
smooth or differentiable. Therefore, search algorithms can
be used to scan the vast space of potential portfolios effi- A Simple Illustration
ciently for optimal combinations of instruments. First, we must set up the problem. For the purpose of illus-
Simulated annealing is one such algorithm. This article tration, we will consider the problem of selecting an opti-
illustrates how simulated annealing (SA) can be used to mal overlay portfolio of credit default swaps (CDS) to
identify portfolios with optimal combinations of risk and hedge and improve returns on a bank’s loan portfolio while
return. managing the overlay portfolio’s mark-to-market (MTM)
volatility. Based on fundamental analysis, internal con-
straints and personal judgment, we will assume that the
portfolio manager has developed a list of 200 potential
CDS transactions from which to construct a portfolio (“the
“When applied to portfolio con- CDS universe”). Presumably, he has restricted this universe
struction, the SA algorithm begins to CDS positions that he would feel comfortable transact-
ing based on his view of idiosyncratic risks. One measure
with a randomly selected portfolio. of return to be used in this context is economic value added
(EVA). The portfolio manager will only want to take CDS
It then iteratively jumps to other positions with positive EVA.
portfolios in the neighborhood of After screening for idiosyncratic risks, the portfolio man-
ager may also focus on minimizing the expected MTM
its current position in search of bet- volatility of the overlay portfolio. The MTM volatility of
the CDS portfolio is directly related to the volatility of the
ter risk-return metrics.’ credit spreads associated with each position in the portfo-
lio. Therefore a crude measure of this risk is the historical
standard deviation of credit spreads weighted by portfolio
notional (STD), as calculated below. The portfolio manag-
SA is an optimization heuristic inspired by the cooling of er will want to minimize the expected volatility of the over-
solids. As a substance cools, its molecules arrange them- lay portfolio.
selves into a low energy state (as measured by an “energy The risk-return relationship of potential portfolios can
function”). The energy function could have several local now be measured by the following ratio: EVA/STD. This is
minima. The cooling process is akin to minimizing the the objective function to be maximized. Clearly, EVA may
energy function. It is an empirical fact that the rate of cool- not be a desired measure of return, and the historical stan-
ing determines the final structure of the solid, and the solid dard deviation of credit spreads may not fully measure the
formed by rapid cooling is usually not as stable as the solid expected MTM volatility of a CDS portfolio.
formed by a slower cooling schedule. This is because rapid Nevertheless, these simple measures will be used to illus-
cooling forces the molecules into the first locally minimal trate the simulated annealing technique. The choice of
energy state that they happen to chance upon. A slower appropriate risk and return measures will depend on the
cooling schedule increases the probability that the mole- goals and context of portfolio optimization, which is not
cules converge on the globally minimal energy state. the subject of this article.
When applied to portfolio construction, the SA algo- The EVA for a particular CDS can be calculated using
rithm begins with a randomly selected portfolio. It then the following formula:
iteratively jumps to other portfolios in the neighborhood of
its 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 heuristic In the above formula, the “Expected Revenue” is sim-
allows a non-zero probability of moving to portfolios with ply the annual spread multiplied by the notional. The
worse risk-return metrics. This prevents the heuristic from “Capital” term can refer to either the regulatory or eco-
getting stuck at a local minimum. The probability of jump- nomic capital to be held by the institution for a particular
46 GLOBAL ASSOCIATION OF RISK PROFESSIONALS J U N E / J U LY 0 8 I S S U E 4 2
3. G L O B A L A S S O C I AT I O N O F R I S K P R O F E S S I O N A L S
P O R T F O L I O O P T I M I Z AT I O N
transaction. If $10 million notional in protection is sold
(long position) for 50 basis points (bps), then the annual
expected revenue is simply $50,000. If protection is
bought (short position) on the same terms, the annual
expected revenue (i.e., cost) is $50,000. Of course, long
positions incur a positive capital charge, while short posi- The above random portfolio consists of all swaps with
tions incur a negative capital charge (i.e., capital release). an indicator value of 1. The EVA/MTM value associated
The portfolio EVA is simply the sum the EVA of compo- with this portfolio can be easily calculated using the
nent swaps. appropriate formulas. On iteration i, a uniform random
The historical standard deviation (in dollars) of a portfo- number between 0 and 1 is generated and assigned to
lio of CDS can be calculated using the following formula: each swap in the universe. That number is then compared
with 0.5*schedule(i). If the random number assigned to a
particular swap is less than 0.5*schedule(i), then the indi-
cator for that deal is switched from its current state. For
In the above formula, “w” is a vector containing the each iteration, this function initially generates vastly dif-
notional amounts of CDS in the portfolio, and “™” is the ferent portfolios. However, the variation in portfolio
covariance matrix of historical spreads for the swaps. STD composition between iterations decreases as the heuristic
is in dollar terms. winds down.
Finally, in each step, an accep-
Implementation Steps tance probability is calculated to
Now that the problem is set up, we can implement the SA determine whether to keep the cur-
algorithm. The first step is to define the following three rent configuration of swaps (i.e.,
functions: the annealing schedule, the neighbor generator the current portfolio) or to switch
and acceptance probability. These functions must be tested to the configuration proposed by
and refined empirically for each problem. the neighbor generator. This proba-
The annealing schedule is used to control the path the bility depends on the value of the
heuristic takes as it searches for the global optimum. Its objective function corresponding to
value depends on how far along the SA algorithm has pro- the current and proposed configu-
gressed. Initially, it allows the heuristic to search the space Vallabh rations, as well as on schedule(i).
of portfolios randomly. As the routine progresses, however, Muralikrishnan In our implementation, we set
the annealing schedule forces the heuristic to move toward the acceptance probability to 1 if
the maximum. For our illustration here, we use a simple the proposed configuration yields a higher objective.
linear annealing schedule represented by the following Otherwise, we set the acceptance probability to a random
function: number between 0 and 1 multiplied by schedule(i). Clearly,
the heuristic will always choose the proposed configuration
if it yields a better objective. However, there is initially a
non-zero probability of choosing a proposed configuration,
In the above formula, “N” is the total number of itera- even if it yields a worse objective. Still, since schedule(i)
tions over which we wish to run the SA heuristic, and “i” goes to 0 as the heuristic winds down, the probability of
represents the current iteration. Clearly, the annealing accepting a configuration with a worse objective also
schedule has the property that it produces values close to 1 decreases to zero.
initially and then converges to 0 as the heuristic runs its It is also important to note that in the implementation
course. The choice of annealing schedule is subjective and we’ve outlined, the algorithm initially makes bigger
must be chosen based on the design of neighbor generator moves (as evident from the neighbor function) and has a
and acceptance probability functions. greater probability of selecting worse outcomes (as evi-
The neighbor generator is used in each step to generate dent from the acceptance function).
sample portfolios to consider on the next iteration. Each The initial large moves are not necessary, but they do
transaction in the swap universe is assigned an indicator allow for the algorithm to experiment with vastly differ-
variable (1 or 0) that indicates whether or not the swap is ent combinations from the initial starting point.
included in a portfolio. This can be accomplished by using However, the probability of selecting worse outcomes
a random number generator to assign a vector of indicators decreases over time.
to potential transactions: Given the three functions we’ve discussed (the annealing
GLOBAL ASSOCIATION OF RISK PROFESSIONALS 47
4. G L O B A L A S S O C I AT I O N O F R I S K P R O F E S S I O N A L S
P O R T 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 implemented
using the following steps:
1. Decide on the number of iterations over which to
run the algorithm. This is subjective and can be set
based 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. case. This conclusion can be easily duplicated. However,
even more interesting is the variability in the results of the
4. Generate a neighbor portfolio and calculate the simulated annealing algorithm. To illustrate the variability
objective function value for this new portfolio. of results, the two algorithms were run 10 times, and ele-
mentary statistics were computed:
5. Based on the acceptance probability, accept or
reject the new portfolio. If accepted, set the new
portfolio as the “best portfolio” and update and
store the corresponding objective function value.
6. Repeat steps 4 and 5 until the maximum number
of iterations is reached.
For a given number of iterations, there seems to be sig-
Simulated Annealing vs. Greedy Algorithm nificant variability in the final objective value found by the
The benefits of using SA over a greedy search algorithm implementation of the SA algorithm.
can be demonstrated empirically. Unlike SA, a greedy algo-
rithm will only select portfolios that have higher values of Further Study: The Challenge of Convergence
the objective function. We can modify the SA algorithm SA is a search algorithm and therefore is subject to the
outlined earlier in this article to create a greedy algorithm same criticism as all search algorithms. In our experi-
and then compare the results of optimization by the two ment, we used SA to search a space of 2200 (over 1060)
algorithms. A greedy algorithm can be created by simply potential portfolios, with a maximum of 50,000 itera-
setting the acceptance probability to zero, if the objective tions. Due to the vast space of potential portfolios, con-
of the proposed portfolio is less than the objective of the vergence is understandably difficult. Several options are
“current” portfolio on all iterations. available to address the problem of convergence; none,
To test the effectiveness of the two search algorithms, however, is perfect.
we start with identical swap universes and identical start- One option is to increase the number of iterations, but
ing points. This ensures that the value of the objective this will be restricted by available computing time. Another
function will be the same for identical portfolios regardless option is to start from several different starting points and
of which algorithm is used. It also enables fair compar- compare the results. A third option is to use SA to identify
isons because both algorithms start from the same point. one solution and then use that solution as the starting point
The following table summarizes the results from the afore- for a gradient search.
mentioned experiment. Much experimentation is required to customize the SA
The result of the above experiment clearly shows that the algorithm for a particular problem. Nevertheless, SA
SA search algorithm beats the greedy algorithm in every remains 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 in
mathematical finance from the University of Toronto. He can be reached at vallabh.muralikrishnan@bmo.com
48 GLOBAL ASSOCIATION OF RISK PROFESSIONALS J U N E / J U LY 0 8 I S S U E 4 2