Sunteți pe pagina 1din 9

Electronic copy available at: http://ssrn.

com/abstract=1767338
AN ALGORITHM FOR FINDING A PORTFOLIO
WITH THE HIGHEST SHARPE RATIO


Valentyn Khokhlov, MBA
Corporate Finance and Investments Consultant
Tel: +380-50-4779316
E-mail: val.khokhlov@gmail.com


Abstract:
An optimal portfolio with the highest possible Sharpe ratio plays an important role for capital allocation
and performance evaluation. This paper introduces a simple algorithm for finding the Sharpe-optimal
portfolio without solving a non-linear problem. The results are tested on S&P 100 components in year
2010. They also address the issue of using arithmetic means or actual returns as the optimization inputs.

Keywords:
Portfolio optimization; Sharpe ratio; mean-variance optimization; capital allocation line.



Asset allocation is one of the key tasks of any portfolio manager. The modern portfolio
theory starting with Markowitz [1952] provided theoretical basis for asset allocation using the
mean-variance optimization (MVO). MVO involves solving a quadratic programming problem,
and one of the most known algorithms was proposed by William Sharpe (see Sharpe [1987]).
The Sharpe algorithm allows finding assets weights for the optimal portfolio given the investors
risk tolerance. While it works perfectly well for individual investors, for whom the risk tolerance
can be specified, its usage is questionable in case of funds or generic portfolios.
Practitioners often adopt some indicators of investments performance, and one of the
most popular is the Sharpe ratio, which is the ratio of the return in excess of the risk-free rate to
the standard deviation of investment returns. Fund and portfolio managers are commonly
evaluated using this indicator. So, maximization of the Sharpe ratio can be an important criterion
for asset allocation. Although the original Sharpe algorithm cant directly solve the MVO
problem to maximize the Sharpe ratio of the optimal portfolio, with a minor modification
proposed in this paper it can altered to find the Sharpe-optimal portfolio.
Another usage of the Sharpe-optimal portfolio is to find an optimal capital allocation in
presence of a riskless asset. It can be shown that the optimal capital allocation line for the given
set of risky assets and a riskless asset is tangent to the efficient frontier of optimal portfolios at
the point that has the highest Sharpe ratio. Hence, finding the Sharpe-optimal portfolio allows
building the capital allocation line (CAL) for the given set of assets.

The Sharpe algorithm
The algorithm developed by William Sharpe is a quadratic programming problem solver,
which finds the assets weights that maximize the following objective function:

2
,
1 1
max
p p i i i j ij
t t i i j
U r w r w w
r r
= =

(1)
where
p
r denotes the expected portfolio return,
t
r is the investors risk tolerance,
p
is the
standard deviation of the portfolio returns,
i
w denotes the weight of i-th asset in the portfolio,
i
r
Electronic copy available at: http://ssrn.com/abstract=1767338
is the expected return of i-th asset,
ij
is the covariance between returns of i-th and j-th assets
(and
2
ii i
= stands for the variance of i-th asset), given the following boundary conditions:
1
i
i
w =

(2)

min max
, 1,
i i i
w w w i n = (3)
The Sharpe algorithm uses the gradient method to solve a quadratic problem and
converges rather quickly to a locally optimal solution. The gradient method used relies on the
marginal utilities, which are partial derivatives of the objective function on individual assets
weights:

( )
2
1 2
p
p
i i j ij
i i t i t j
r
U
MU r w
w w r w r

= = =


(4)

The Sharpe ratio maximization problem
To maximize the Sharpe ratio of a portfolio, we need to solve a maximization problem
for the following objective function:

( )
0.5
1
,
p f
S p f p i i f i j ij
p i i j
r r
R r r w r r w w

| |
| |
| = = =
|
|
|
\
\

(5)
where
f
r denotes the risk-free rate.
This is a non-liner optimization problem, which is not so trivial to solve. Non-liner
optimization algorithms are much more complicated than the Sharpe algorithm. However, any
solution to (5) must a root of all its partial derivatives. A partial derivate of (5) on i-th asset
weight is

( ) ( )
( )
( )
( )
2
0.5
2
1.5
2
3 2
0.5
1 1
1
p
p f p p
S
p f p
i p i i p i i
p
p f p f
i
j ij i j ij
p p j j p p
r r r r
R
r r
w w w w w
r r r r
r
w r w




= + = =

| |

| = =
|
\

(6)
One can see that this derivative has the same roots as the marginal utility (4) when the
risk tolerance equals to

2
*
2
p
t
p f
r
r r

(7)
Therefore, an optimal portfolio that is a solution to the (1)-(3) will have the highest
possible Sharpe ratio when the condition (7) is satisfied. Thus we can derive the Sharpe-optimal
portfolio without having to solve a non-liner programming problem.

The modified Sharpe algorithm
In order to find the Sharpe-optimal portfolio, we need to find a solution to (1)-(3) which
satisfies (7). Although its impossible to know the Sharpe-optimal risk tolerance
*
t
r before
running the algorithm, since it depends on the assets weight in the optimal portfolio, we can
benefit from the iterative structure of the algorithm, which converges to the optimal solution.
Instead of using a constant risk tolerance, its possible to calculate it using (7) on each iteration,
thus ensuring that at the end of the algorithm the optimal solution will also satisfy (7).
Electronic copy available at: http://ssrn.com/abstract=1767338
The modified algorithm takes the following inputs:

{ }
(0) (0)
, 1,
i
w i n = = w the initial solution satisfying boundary conditions (2)-(3),
{ }
i
r = r the expected returns vector,

{ }
ij
= the covariance matrix,

f
r the risk-free rate,

{ } { }
min max
, , 1,
i i
w w i n = limits on individual assets weights for condition (3).
The algorithm consists of finite number of iteration 0,1, 2,... k = , each of them consist of
the following steps (please note that steps 2-5 and 7 dont differ from the original Sharpe
algorithm):
1. The variable risk tolerance is calculated to satisfy condition (7):

( ) ( )
2
,
( )
( )
2 2
k k
ij i j
p i j
k
t
k
p f
i f i
i
w w
r
r r
w r r

= =


2. The marginal utilities are calculated using (4) with
( ) k
t t
r r = .
3. Two assets to swap are selected such as the asset with the highest possible marginal
utility is added and the asset with the lowest possible marginal utility is subtracted. If
either of the assets cant be found the algorithm stops. The following formulas are used:

( )
{ }
{ }
add
sub
max
add
( ) min
sub
: max
: min
k
i i i i
i
k
i i i i
i
i MU MU w w
i MU MU w w
= <
= >

4. The effect of the swap is calculated as follows:

add sub
i i
MU MU MU =
5. If the effect is less than the optimization threshold, the algorithm stops.
6. The optimal feasible amount to swap is selected using the following formula:

( )
add sub
add sub
add sub
add sub add sub
( ) ( ) max min
( ) 2 2
min , ,
2
i i
k k
i i
i i
k
t i i i i
MU MU
w w w w w
r


=
`
+
)

7. New assets weights are calculated for the next iteration:

( )
add
( 1) ( )
sub
( )
, ,
, ,
, otherwise.
k
i
k k
i i
k
i
w w i i
w w w i i
w
+

+ =

= =



The only difference from the original Sharpe algorithm is calculating the variable risk
tolerance on step 1 and using its absolute value in denominator of the formula on step 6.
To verify the modified algorithm, the sample 3-assets problem used by Dr. Sharpe in his
work is used. The assets are cash, bonds and stocks with parameters specified in the Table 1.

Table 1. Inputs for the sample 3-assets problem
Assets
Limits on
asset weights
Initial
solution
Expected
return
Standard
deviation
Correlations
i
min
i
w
max
i
w
(0)
i
w
i
r
i
1 2 3
1: cash 0 1 1 2.8 1.0 1 0.4 0.15
2: bonds 0 1 0 6.3 7.4 0.4 1 0.35
3: stocks 0 1 0 10.8 15.4 0.15 0.35 1

The risk-free rate is supposed to equal the expected return on cash, 2.8. The modified
algorithm found the Sharpe-optimal portfolio with the expected return 7.96, the standard
deviation 8.52 and the Sharpe-optimal risk tolerance 28.157. The original Sharpe algorithm was
then used to generate several optimal portfolios with various risk tolerance, including two values
close to the optimal. The resulting optimal portfolios are displayed in the Table 2.

Table 2. Optimal solutions for the sample 3-assets problem
Optimal portfolios with different risk tolerance levels
Assets
0 10 28.147 28.157 28.167 30 50 75 100
cash 100.00% 65.04% 0.0000% 0.0000% 0.0000% 0.00% 0.00% 0.00% 0.00%
bonds 0.00% 21.71% 63.1367% 63.1258% 63.1155% 61.17% 39.96% 13.45% 0.00%
stocks 0.00% 13.26% 36.8633% 36.8742% 36.8845% 38.83% 60.04% 86.55% 100.00%
Portfolio return 2.80 4.62 7.958848422 7.959341013 7.959802944 8.05 9.00 10.20 10.80
Standard deviation 1.00 3.27 8.521898631 8.522712232 8.523475392 8.67 10.65 13.71 15.40
Sharpe ratio 0.00 0.56 0.605363739 0.605363747 0.605363740 0.6051 0.58 0.54 0.52

The solution derived with the modified algorithm has the highest Sharpe ratio of all
optimal portfolios.

Sharpe-optimal portfolio on the U.S. stock market
To test the modified Sharpe algorithm on real market data, a sample of year 2010 daily
returns for 98 components of Standard & Poor 100 index was used. Two S&P 100 components,
BNI and USB, were dropped since they dont have full daily price coverage in 2010. The risk-
free rate was assumed to be 0.47% (as per 1-year Treasury bond on December 31, 2009). Short
positions were not allowed. Individual asset weights could be 0% to 100%.
When the theory presented above is used in practice, one of the key questions is how to
derive the estimated returns. Sample arithmetic mean is an unbiased estimator for daily expected
return. If we assume the daily assets returns are independent and normally distributed, then
expected periodic (e.g. annual) return over T days and its variance can be calculated using
arithmetic linkage of sample mean (
annual daily
r Tr = ) and variance (
2 2
annual daily
T = ). The
expected return on a constant-weight portfolio in this case is a weighted sum of assets return:

daily annual daily annual
p p i i i i
i i
r Tr wTr w r = = =


The important consequence is both periodic and daily portfolio returns are weighted sums
of the corresponding assets returns, and this equality is implied in (1) and (5):

p i i
i
r w r =

(8)
To test the modified Sharpe algorithm under the above-stated assumptions, arithmetic
sample means and covariances were used as inputs. The results are presented in Table 3, and
portfolio returns under Model returns are calculated using formula (8). In this case the Sharpe-
optimal portfolio has the highest Sharpe ratio of all the optimal portfolios.

Table 3. Optimal S&P 100 portfolios (using arithmetic means as inputs)
Optimal portfolios with different risk tolerance levels
Ticker
0 0.05 0.1 0.15 0.2 0.3 0.5 0.75 1 1.5 3
Sharpe-
optimal
AAPL 0.49% 7.48% 10.20% 11.76% 13.27% 3.83% 8.39%
ABT 12.24%
BMY 4.70% 0.93%
CAT 2.43% 8.41% 14.90% 27.71% 45.92% 61.22% 64.29% 59.18% 43.88% 4.59%
CL 9.68%
COST 0.02% 5.32% 1.72%
CPB 8.16%
DD 6.12% 7.14% 6.12% 2.30%
F 1.30% 3.69% 6.11% 11.07% 20.81% 30.74% 35.71% 40.82% 56.12% 2.10%
GS 0.40%
JNJ 13.27%
KFT 1.55% 3.24%
MCD 4.08% 22.54% 17.79% 1.73% 13.22%
MO 1.02% 29.67% 39.94% 36.81% 23.09% 40.51%
PG 8.16%
SLE 14.65% 25.90% 33.04% 37.00% 41.84% 29.44% 8.04% 28.89%
SO 16.33% 22.82% 3.44%
TGT 0.35%
WMT 20.39%
Model
Return 6.82% 27.51% 34.07% 39.96% 43.36% 48.86% 52.66% 56.58% 57.92% 58.02% 58.30% 36.48%
St.deviation 10.04% 11.75% 13.71% 16.14% 17.88% 21.30% 24.57% 29.11% 30.89% 31.08% 32.10% 14.63%
Sharpe ratio 0.632 2.301 2.451 2.447 2.399 2.272 2.124 1.928 1.860 1.852 1.802 2.461
Actual
Return 6.52% 30.75% 39.25% 47.16% 51.80% 59.30% 64.22% 68.72% 70.09% 70.15% 70.08% 42.46%
St.deviation 10.04% 11.75% 13.71% 16.14% 17.88% 21.30% 24.57% 29.11% 30.89% 31.08% 32.10% 14.63%
Sharpe ratio 0.603 2.577 2.829 2.893 2.871 2.762 2.595 2.345 2.254 2.242 2.169 2.870

The efficient frontier and CAL built with arithmetic means as inputs to the Sharpe
algorithm are shown on Figure 1. The CAL is tangent to the efficient frontier, as it should be
according to theory. Also, the S&P 100 index (denoted as OEX) doesnt lie on the efficient
frontier, so index portfolio is not optimal in this case.
Unfortunately, model returns have nothing to do with actual returns, because the latter are
based on geometric rather than arithmetic linkage of sample returns:
( )
annual daily
1 1
T
r r + = + . It
corresponds to the lognormal distribution of daily returns, and in this case equation (8) doesnt
necessary hold. In fact, the portfolio annual return equals to the weighted sum of its assets annual
returns only if the portfolio is never rebalanced. In order to calculate actual annual return on a
constant-weighted portfolio its required to calculate daily weighted returns and link them
geometrically. These results are presented in Table 3 under Actual returns, and one can note
that the Sharpe ratio of the Sharpe-optimal portfolio (2.870) is not the highest any more (for
example, a portfolio with risk tolerance of 0.15 has Sharpe ratio of 2.893).
The actual efficient frontier and CAL recalculated with actual returns are shown of Figure
2. This CAL isnt actually tangent to the actual efficient frontier, although quite close to it.
In attempt to derive a solution that is consistent with actual returns, the Sharpe algorithm
was tested using the actual annual returns as inputs. The results are presented in Table 4. One can
note that model portfolio returns, used in the algorithm and calculated with formula (8), are now
much closer to the actual returns derived from compounding of daily returns on generated
portfolios. Although its never possible to guarantee that the Sharpe-optimal portfolio calculated
with the modified algorithm has the highest possible Sharpe ratio unless equation (8) holds, the
solution is now much closer to the true Sharpe-optimal portfolio.
AAPL
DD
SLE
SO
MO
F
OEX
CAT
-20%
-10%
0%
10%
20%
30%
40%
50%
60%
70%
80%
0% 5% 10% 15% 20% 25% 30% 35% 40%
Standard deviation
M
o
d
e
l

r
e
t
u
r
n
ef f icient f rontier
individual stocks
capital allocation line

Figure 1. The model efficient frontier and capital allocation line (built with arithmetic means)


AAPL
DD
SLE
SO
MO
F
OEX
CAT
-20%
-10%
0%
10%
20%
30%
40%
50%
60%
70%
80%
0% 5% 10% 15% 20% 25% 30% 35% 40%
Standard deviation
A
c
t
u
a
l

r
e
t
u
r
n
efficient frontier
individual stocks
capital allocation line

Figure 2. The actual efficient frontier and capital allocation line (built with arithmetic means)

The actual efficient frontier and CAL built with actual stock returns as inputs to the
Sharpe algorithm are shown on Figure 3. Although the difference with Figure 2 is hardly
observable, the CAL is now closer to the true tangent line. The actual efficient frontier calculated
with the actual stock returns (solid line) is almost the same as the actual efficient frontier
previously calculated with arithmetic means (dotted line).
Table 4. Optimal S&P 100 portfolios (using actual returns as inputs)
Optimal portfolios with different risk tolerance levels
Ticker
0 0.05 0.1 0.15 0.2 0.3 0.5 0.75 1 1.5 3
Sharpe-
optimal
AAPL
2.51% 7.97% 10.03% 11.29% 7.77% 8.65%
ABT
12.60%
BMY
4.39%
CAT
7.46% 16.24% 25.47% 42.27% 62.40% 76.84% 77.71% 79.44% 84.64% 9.32%
CL 9.32%
COST 4.19%
CPB 8.37%
DD 3.45% 7.08% 7.69% 5.13%
F 0.98% 3.28% 5.57% 10.67% 18.03% 23.16% 22.29% 20.56% 15.36% 1.48%
GS 0.31%
JNJ 13.27%
KFT 1.55% 0.63%
MCD 4.42% 21.89% 9.75% 4.72%
MO 0.28% 33.44% 40.04% 26.75% 8.57% 38.51%
PG 8.56%
SLE 17.92% 30.35% 36.62% 41.40% 39.29% 19.57% 32.19%
SO 17.00% 19.42%
WMT 19.94%
Model
Return 6.37% 32.37% 42.76% 49.29% 54.32% 59.31% 64.46% 68.40% 68.40% 68.41% 68.45% 44.66%
St.deviation 10.04% 12.14% 15.02% 17.47% 19.82% 22.62% 26.74% 30.75% 30.76% 30.78% 30.90% 15.67%
Sharpe ratio 0.588 2.628 2.816 2.795 2.717 2.601 2.393 2.209 2.208 2.207 2.200 2.820
Actual
Return 6.47% 32.87% 43.70% 50.73% 56.17% 61.47% 66.44% 69.77% 69.74% 69.67% 69.45% 45.73%
St.deviation 10.04% 12.14% 15.02% 17.47% 19.82% 22.62% 26.74% 30.75% 30.76% 30.78% 30.90% 15.67%
Sharpe ratio 0.598 2.669 2.878 2.877 2.810 2.697 2.467 2.254 2.252 2.248 2.232 2.888


CAT
OEX
F
MO
SO
SLE
DD
AAPL
-20%
-10%
0%
10%
20%
30%
40%
50%
60%
70%
80%
0% 5% 10% 15% 20% 25% 30% 35% 40%
Standard deviation
A
c
t
u
a
l

r
e
t
u
r
n
efficient frontier
individual stocks
capital allocation line
efficient frontier (previous)

Figure 3. The actual efficient frontier and capital allocation line (built with actual returns)

So, the actual periodic returns work quite well for building the ex-post efficient frontier
and finding the ex-post Sharpe-optimal portfolio. Advanced research on ensuring that the model
periodic returns used in the algorithm are close to the true periodic returns is out of scope of this
article. More information on this topic can be found in Bernstein [1997].

Conservative capital allocation line
In presence of a risk-free asset, the efficient frontier built does not provide the best way
for capital allocation any more the investor can obtain a better risk-return portfolio combining
risky and riskless assets. All the optimal portfolios in this case will have the same Sharpe ratio,
which is the highest possible Sharpe ratio, i.e. the same ratio the Sharpe-optimal portfolio has.
The equation for the capital allocation line (CAL) therefore is

( )
*
*
p f
p p f p
p
r r
r r

= + , (9)
where
* *
,
p p
r denote the expected return and standard deviation of the Sharpe-optimal portfolio.
Market-weighted indexes are often used as proxies for market portfolios, which are
supposed to be Sharpe-optimal. Results presented in the previous section indicate that at least
S&P 100 index does not represent a Sharpe-optimal portfolio and isnt an optimal portfolio at all.
On the other hand, the solution derived with the modified Sharpe algorithm is very close to the
true Sharpe-optimal portfolio; therefore it suits better for building the CAL.
A typical CAL shown on Figure 4 has two segments. Segment FS contains portfolios
composed of long positions in the risk-free and risky assets (its 100% long position in the risk-
free asset at point F and 100% long position in the Sharpe-optimal portfolio at point S). Segment
SN, on the other hand, corresponds to a long position in the risk-free asset and a short position in
a risky portfolio. As any short position has speculative meaning, it may not be appropriate or
desirable for a conservative investor. Thats why a concept of the conservative CAL is proposed.
F
S
N
M
-20%
-10%
0%
10%
20%
30%
40%
50%
60%
70%
80%
0% 5% 10% 15% 20% 25% 30% 35% 40%
Standard deviation
M
o
d
e
l

r
e
t
u
r
n
conservative CAL
capital allocation line
ef f icient f rontier

Figure 4. The conservative capital allocation line

The conservative capital allocation line is a curve in risk-return space that contains all
the mean-variance optimal portfolios that can be composed with long positions in the risk-free
and risky assets. The conservative CAL has two segments (see Figure 4) liner segment FS,
corresponding to one of a conventional CAL, and a segment of efficient frontier SM that starts at
the Sharpe-optimal portfolio and ends at the 100% long position in the asset with the highest
expected return.
Portfolio managers who want to ensure the best possible capital allocation for their clients
engaging only in long positions in the selected risky and risk-free assets should use one of the
portfolios on the conservative CAL. To select one, they need to find the Sharpe-optimal portfolio
composed of the selected risky assets using the modified Sharpe algorithm lets suppose it has
parameters
* *
,
p p
r . The Sharpe-optimal risk tolerance could be found with (7). If the desirable
risk tolerance (or standard deviation) is smaller than that, a combination of the risk-free asset and
the Sharpe-optimal portfolio should be used to select one portfolio on segment FS of CAL. If the
desirable portfolio risk is higher than that of the Sharpe-optimal portfolio, an optimal portfolio
residing on the efficient frontier segment FM should be selected. It can be found using the
original Sharpe algorithm.
Finally, portfolio managers could also use the original Sharpe algorithm with the risk-free
asset. To accomplish it, they just need to add an asset with the expected return equal to the risk-
free rate, and standard deviation and all covariances with other assets equal to zero. In fact, the
conservative CAL on Figure 4 was built using the original Sharpe algorithm in such way.

Conclusions
The proposed algorithm for the Sharpe ratio maximization introduces a simple and
feasible way of portfolio optimization. While a theoretical Sharpe-optimal portfolio can be built
using the inverse covariance matrix, it often contains large long and short positions, so is
unfeasible on practice. The modified Sharpe algorithm allows setting upper and lower bounds on
individual assets weight, effectively limiting size of long positions and disabling short selling.
While the Sharpe ratio optimization is a non-linear problem, the paper shows how it can
be solved using a quadratic optimizer. It can be achieved by using a varying risk tolerance on
each iteration (in the original algorithm the risk tolerance is constant). The outcome is the same
as that of the non-linear solvers (for example, the Microsoft Excel solver).
The algorithm is sensitive to the expected returns estimated. Using arithmetic means as
inputs doesnt result in actual Sharpe ratio maximization, because arithmetic linking of daily
returns doesnt result in true total return. Using actual periodic returns as inputs results in much
better, although not a perfect, optimization of the true Sharpe ratio.
The Sharpe algorithms (both the original and the modified) may be used with the risk-
free asset as one of their inputs. This technique allows building the conservative CAL, an assets
allocation line which contains all the optimal portfolios that are achievable without short selling.



References:

1. Markowitz, Harry. Portfolio Selection. The Journal of Finance, Vol. 7, No. 1 (1952), pp. 77-91.

2. Sharpe, William. An Algorithm for Portfolio Improvement. In K.D.Lawrence, J.B. Guerard, Jr., and
Gary D. Reeves, eds., Advances in Mathematical Programming and Financial Planning, JAI Press,
Inc., 1987, pp. 155-170.

3. Bernstein, William J., and David J. Wilkinson. Diversification, Rebalancing, and the Geometric Mean
Frontier (1997). Available at SSRN: http://ssrn.com/abstract=53503 or doi:10.2139/ssrn.53503

S-ar putea să vă placă și