Creating Optimal Portfolio and The Efficient Frontier
Creating Optimal Portfolio and The Efficient Frontier
Creating Optimal Portfolio and The Efficient Frontier
ISSN(P):2522-2252
Indexing/Abstracting
Teaching Module
Creating Optimal Portfolio and the
Efficient Frontier Using Microsoft
Excel®
Author(s)
Saurav Roychoudhury1
Affiliations
1
Department of Business, Capital University, Columbus, OH,
USA 43209. Email: sroychou@capital.edu
Manuscript Information
Published by Citation in APA Style
Department of Quantitative Methods Roychoudhury, S. (2018). Creating Optimal Portfolio and the
Efficient Frontier Using Microsoft Excel®. Journal of
Quantitative Methods 2(2), 104-136.
University of Management and This manuscript contains references to 10 other manuscripts.
Technology, Lahore, Pakistan
The online version of this manuscript can be found at
https://journals.umt.edu.pk/sbe/jqm/volume2issue2.aspx#
Teaching Module
1
Department of Business, Capital University, Columbus, OH, USA 43209.
Email: sroychou@capital.edu
Author’s Note: The author gratefully acknowledges an NSF grant # 0618252 on
Development and Dissemination of Computational Science Educational Materials
and Curricula at the Undergraduate Level in the United States. I hereby declare that
this paper is partially extracted from an unpublished teaching module titled “The
Optimal Portfolio and the Efficient Frontier” which I developed as part of this NSF
grant #0618252.
1. Introduction
Finance theory has become increasingly mathematical, but there is a
dearth of computational finance materials at the undergraduate level
which is likely because undergraduate finance and economics tend to
be taught in business schools or under social sciences and more
mathematically oriented courses are in mathematics and natural
science departments. In recent years we have seen an increase in
academic programs that support computational finance but mostly at
the graduate level (Roychoudhury, 2007). One of the first papers
which laid the groundwork for mathematical theorization in finance
was Portfolio Selection by Markowitz (1952). The paper introduced
the Modern Portfolio Theory (MPT) and formulated the concept of
optimal portfolios and the efficient frontier. This paper provides a
teaching tool to create mean-variance portfolios and traces out the
efficient frontier using real-world data and Microsoft Excel®. In the
process, the students learn to determine optimal investment
allocations in a portfolio, select the optimum investment portfolio
given investor’s objectives and preferences and learn about factors
that influence different asset allocations.
The finance industry uses proprietary software that runs into
thousands of dollars in annual license fees that estimate the efficient
frontier and the optimal portfolio. However, Microsoft Excel® has
developed into a powerful tool that can be used to model and do
sophisticated calculations in finance. For example, see Wann (2015),
Boudreaux et al. (2016), and Wann & Lamb (2016). Hess (2005)
finds that "hands-on" use of spreadsheet modeling in class, improves
understanding and retention of the concepts. Incorporating powerful
Excel tools into finance teaching can help students understand the
concepts of finance intuitively, and bridge the gap between financial
theories and real-world applications (Zhang, 2014). Finance faculty at
most leading business schools advocate the use of Excel to prepare
students for the workforce.
Investors and portfolio managers concentrate their efforts on
achieving the best possible trade-off between risk and return. For
portfolios constructed from a fixed set of assets, the risk/return profile
varies with the portfolio composition. Portfolios that maximize the
return, given the risk, or, conversely, minimize the risk for the given
return, are called optimal portfolios. The set of optimal portfolios in
on a stock is the mean return of its historical returns. For example, the
expected mean monthly return of Microsoft would be simply
1 N
E (rmsft ) ri,msft
N i 1
where ri ,msft is the historical monthly return for i th month and
N is the number of months over which the returns are averaged.
The expected return of a portfolio, p , is the weighted
average of the expected returns on the individual assets in the
portfolio, with the weights being the percentage of the total portfolio
invested in each asset.
E (rp ) s A E (rA ) s B E (rB ) sn E(rn )
n
p si i
i 1
N
for N observations and the standard deviation is expressed
as the square root of the variance
r
2
N
When we say something like “this investment is risky” we
generally refer to the downside risk only. That is, to an investor,
the relevant risk of investing in a portfolio is the chance that he
would end up with returns which are less than the expected returns.
There is a subtle difference between this and how we measure risk
statistically (by variance or standard deviation). When we measure
risk statistically, we measure the variability or dispersion around
the mean. We put equal weights to the variability of returns both
above and below the mean. Though the portfolio expected return is
simply the weighted average of the expected returns of the
individual assets in the portfolio, the risky-ness (measured by the
standard deviation, p ) is not the weighted average of the
individual assets’ standard deviations. The portfolio risk is
typically smaller than the average of the standard deviations of the
individual assets.
2.3. Diversification
Diversification is equivalent to not putting all eggs in one basket. It
is akin to not putting all your money in one risky asset but
allocating your money across a number of risky assets.2 A well-
diversified portfolio will significantly lower the downside risk
without lowering your expected return (Roychoudhury, 2007).
Take the coin-toss example. Suppose the return on $10,000 you
have put in a risky stock depends on the flip of a coin. Heads, it
quadruples in value (becomes $40,000); tails, you lose $10,000.
The expected return is very good at 100%3. Unfortunately, the
downside risk is terrible – there is a 50% chance that you would
lose your $10,000.
As a rule, portfolio risk declines as the number of stocks in
the portfolio increases4. Thus, careful diversification can create a
portfolio that is less risky and earns more on average for the same
degree of risk than any single company stock.
2
In this paper we are looking at stocks as the risky asset. In the real world, the
investor will have other choices like investing in bonds, Bank CDs, real estate,
commodities and derivatives.
3
It is 50% $40,000 50% $0 $20,000 or 100% return on the initial
$10,000 investment.
4
In practice, investment managers and finance practitioners find that if you hold
anywhere between 25 and 30 stocks you can capture most of the diversification
benefits. Adding assets beyond a certain number (like 30) does not generate
much incremental benefit as far as reducing portfolio risk is concerned.
3. The Model
We know that it is essential to diversify, but it still does not tell
you how much of each security you should purchase. How do you
determine investment allocations in a portfolio? Where is the best
investment portfolio given the investor’s objectives and
preferences? What would influence different allocations? To
answer these questions, we start with a modified version of the
Markowitz’s (1952) portfolio theory model.
We begin with the simplest example – one period, two
assets, and, normally distributed returns. The model assumes that
investors are risk-averse, meaning that if there are two assets that
offer a same expected return, the investor will prefer the less risky
asset. An investor will undertake increased risk only if
compensated by higher expected returns. The model also assumes
that the investor’s risk-reward preference can be explained entirely
by expected return and volatility (measured by standard deviation
of historical returns). A risk-free asset exists (in the form of US
Treasury Bills), and it is possible to borrow and lend money at the
risk-free rate. All stocks are perfectly divisible (e.g., it is possible
to buy 1 / 1000 th of a share) and there are no transaction costs or
taxes.
We use the following notations
ri the return (sometimes called rate of return) on asset i
n number of available assets
r f the return on the risk-free asset
i mean of the return on asset i
i the standard deviation of the return on asset i
i2 the variance of the return on asset i
ij covariance between the returns on assets i and j
ij correlation between the returns on assets i and j
si the share of asset i in the portfolio
r rp the (rate of) return of a portfolio
p the mean of the portfolio return
P s A2 A2 (1 s A ) 2 B2 2 s A (1 s A ) A, B A B (6)
p
1
( B A ) 2
12 ( B ) 2 2 AB A B ( A ) ( B ) B2 ( B ) 2
(7)
The equation represents a hyperbola in mean-standard deviation
space.
3.2. Three Risky Assets
5
The model used in this paper is a simpler version to suit the level of advanced
undergraduate students.
ij , represents the n x n variance-covariance matrix of the n
asset returns, where
is a 1 x n column vector of the expected returns, i .
s represents a 1 x n column vector of the portfolio shares or weights,
si .
1 represents a 1 x n column vector of 1's
1 represents the inverse of a matrix
The portfolio frontier is found by minimizing portfolio variance
subject to a given portfolio mean:
Minimize with respect to s:
1 T
s s (10)
2
Subject to the constraints
T s p (11)
1T s 1 (12)
Thus the portfolio variance is minimized subject to a given
expected portfolio return p and given that all portfolio shares add up
to 1.
Using the Lagrangian6 method with multipliers and for
constraints (11) and (12), respectively, produces the following first-
order condition:
s T T 1T 0 (13)
Solving for the portfolio weights gives us:
s T * T 1 1T 1 (14)
6
For students new to Lagrangian multipliers it might be a good idea to look at an
undergraduate Finance and Economics book like Alpha C. Chiang’s
“Fundamental Methods of Mathematical Economics.” A brief overview on
Lagrangian multipliers is written by Steuard Jensen and is available at
http://www.slimy.com/~steuard/teaching/tutorials/Lagrange.html
1 T 1 1 1T 1 1 (17)
Define:
A T 1 , B 1T 1 1 , C 1 T 1 , and D AB C 2
(18)
Note that A, B, C, and D are scalars that depend only on the
constant parameters of the set of available assets. It is now
straightforward to solve for and from equations (16) and (17):
B C
p
(19)
D
A C
p
(20)
D
Plugging (19) and (20) into equation (19) yields an explicit expression
of the portfolio frontier:
2
B 2
p 2 C p A
(21)
p
D
The portfolio frontier is a hyperbola in mean-standard
deviation space as in the case of 2 risky assets. The reason is intuitive:
7
For the variance-covariance matrix to have an inverse, it requires that no two
assets are perfect substitutes; so that the matrix is not singular.
Any two points on the frontier can be thought of as mutual funds that
are individual assets. Taking different combinations of these two
assets must trace out a hyperbola based on case with 2 risky assets,
but there is no way that this hyperbola can be different from the n-
asset frontier as it can, at no point, lie to the left of the n-asset frontier
(or the frontier wouldn’t be a true frontier). Thus, once we understand
the 2 risky assets case, we can deduce logically that the n-asset
frontier must be a hyperbola, as well (Roychoudhury, 2007). Based
on the above formula it is now easy to find the minimum variance
portfolio of risky assets. Differentiating equation (21) with respect
to P and setting it equal to zero yields P C / B so that we
obtain p2 1 / B (after using the definition of D in (22)).
very well do it after the pain we went through deriving all the
formulas). We start with the non-linear programming method using
solver and then move to the calculus approach.
4.1.1. Minimum Variance Portfolio using Solver
Excel solver is a powerful tool for optimization10 and produces
targeted results for your models (the technical jargon is “calibrate
your model”). 11 Microsoft solver can be added by selecting “Tools-
Add-ins” and choosing the “Solver Add-in.”
By using the solver, we can calculate the minimum variance
portfolio. The screen-shot in figure 4 shows the solver dialog box. In
this box, we have asked the solver to minimize the variance in cell
B12, by changing the weight of JPM (cell B17) in the portfolio. In
order to ensure that the weights of JPM and ORCL are positive we
put a non-negative constraint by ensuring the weight of JPM and
ORCL’s weight are greater than equal to zero. The relation formula 1-
B7 in cell C17 corresponding to ORCL’s weight ensures that the sum
of the two weights does not exceed 1.
Clicking on “Solve” in the solver dialog box gives (see
screen-shot below), the minimum variance portfolio with 64.9%
invested in JPM and 35.1% in Microsoft. The minimum Variance
portfolio corresponding to 7.01% risk (standard deviation) and 0.81%
returns matches our result obtained previously in “Tracing a Portfolio
Frontier.”
4.1.2. Minimum Variance Portfolio using Calculus Method
Recall the section where we derived the minimum variance portfolio
for 2 risky assets (all those derivations coming to some use now).
Equation (8) gave us the optimal portfolio weight as
B2 A, B A B B2 CovrA , rB
sA
A2 B2 2 A, B A B A2 B2 2 CovrA , rB
10
Solver tool uses the Generalized Reduced Gradient (GRG2) nonlinear
optimization code developed by Leon Lasdon, University of Texas at Austin,
and Allan Waren, Cleveland State University.
11
A nice book on using excel tools like Solver and Goal-seek and its application
in Finance is by Simon Benninga, “Principles of Finance with Excel”.
We plug the values of variance and covariances in cell B26 to get the
optimal weight of JPM. Implementing the formula in Excel gives the
same answer as that given by solver (see figure 5).
4.2. Effect of Change in the Correlation Co-efficient in a Portfolio
Stock A and stock B are two risky assets which have the following
characteristics. Stock A has an expected return of 3% but a standard
deviation of 25%, while for stock B, the respective numbers are 2%
and 15%. The correlation coefficient between the two assets is 0.54.
Let us see what happens if the correlation coefficient changes to two
extremes; perfectly negatively correlated and perfectly positively
correlated.
We trace the portfolio frontier using the same methodology as
in “Tracing a Portfolio Frontier” section. We do it for three different
values of the correlation coefficient AB . For AB = 0.54; AB 1
and for AB =+1 as shown in figure 6.
There is a trick to superimpose all the three graphs in the same
diagram. Select any graph, copy it and paste it over the other graph, it
should clearly superimpose if the size of the graph and the axis are
identical. Do the same for the third graph, and we have a graph very
similar to figure 3 in the Model section. The screen-shot below (figure
6) of our example is shown below. We can observe that the best
diversification can be obtained for AB 1 .
For a detailed derivation and explanation of the effect of a
change in correlations, refer to Appendix A2.
4.3. Minimum Variance Portfolio for Three Risky Assets
Let us pick a third asset, Haliburton (HAL), which would give us a
three asset portfolio with ORCL and JPM. The primary objective is to
find the minimum variance portfolio and the weights of the three
assets which correspond to the minimum variance portfolio
4.4. Solving the QPP: Minimizing Portfolio Risk Subjected to the
Constraints
The weight of funds invested in different assets must add to unity;
There is no short sale provision.
as{=MMULT(MMULT(TRANSPOSE(mu),MINVERSE(Sigma)),m
u)
B 1T 1 1
as {=MMULT(MMULT(TRANSPOSE(I),MINVERSE(Sigma)),i)}
12
C 1 T 1
as {=MMULT(MMULT(TRANSPOSE(I),MINVERSE(Sigma)),mu,
and, D AB C 2
as =A*B-(C.^2)
For the return on the minimum risk portfolio we
take P C / B as =C./B in Excel notation, and for minimum
standard deviation, we take the square-root of
p2 1 / B in Excel notation as =SQRT(1/B). Figure 10
shows the solution using the calculus method, and it matches the
solution by the solver method.
For the equation of the portfolio frontier in the mean-standard
deviation space, we take the square-root of equation (21)
p2
B 2
p 2 C p A
(21)
D
As, =(((B*(E39)^2-(2*C.*(E39))+A)/D)^(1/2)) in Excel notation,
where the cell E39 corresponds to a value of the portfolio expected
return.
We can trace the portfolio frontier by selecting different
values of expected return and calculating the corresponding
standard deviation using the above formula. Note: In solving using
the calculus method we do not consider the assumption anymore
that there are no short sale constraints. Figure 10 also shows the
graph of the frontier. Refer to the worksheet
“Portfolio_optimization_Matrix.xls” for more description on how
to select different values portfolio expected returns.
The line tracing the points from the minimum variance
portfolio A to B is the efficient frontier. A risk-averse investor will
never hold a portfolio which is to the southeast of point A. Any point
to the southeast of A such as C would have a corresponding point like
12
Excel does not allow using “C” to name arrays. We use “C.” in place of “C”.
D which has a higher expected return than C with the same portfolio
risk. Clearly, point D will dominate point C. The optimal portfolio is
the portfolio allocation (or points on the efficient frontier)
corresponding to the investor’s risk preference. More risk-averse
investors would choose points on the efficient frontier that is closer to
point A. Similarly, an investor who is less risk-averse or can handle
more risk would choose a portfolio closer to point B.
5. Conclusion
Creating optimal portfolios and tracing the efficient frontier is a skill
required for a student in finance. Microsoft Excel® has developed into
a powerful tool that can be used to model and do sophisticated
calculations in finance. This paper is a teaching module that uses
Microsoft Excel® to create mean-variance portfolios and traces out the
efficient frontier using real-world data. This paper could be used as an
integrated part of a computational finance course or a stand-alone
component within the typical investments or security analysis and
portfolio management course in finance. If the paper suggestions are
followed, the students will be able to build a real-world investment
portfolio of risky assets using modern portfolio theory techniques. The
students should also be equipped to make modifications to the portfolio
if some real-world variable changes or if some assumptions of the
model are relaxed. The investors could also use this modeling
framework to come up with optimal portfolios from a fixed set of risky
assets.
References
Benninga, S. (2014). Financial Modeling(4th Ed.). Cambridge, MA:
The MIT Press.
Black , F. (1972). Capital market equilibrium with restricted
borrowing. Journal of Business, 45(3), 444-455.
Boudreaux, D., Das, P. & Rao S. (2016). Bootstrap simulation with
spreadsheet application. Journal of Economics and Finance
Education, 15(1), 1-8.
Hess, K. (2005). Spreadsheet-Based Modelling for Teaching Finance
and Accounting Courses Retrieved from
http://ssrn.com/abstract=378680.http://dx.doi.org/10.2139/ssr
n.378680
FIGURES
1.20%
B
1.00%
Expected Return (monthly)
0.80%
0.60% A
0.40%
0.20%
0.00%
4.70% 4.80% 4.90% 5.00% 5.10% 5.20%
Standard Deviation (Risk)
Figure 10: Efficient Frontier for 5 risky Assets using the Calculus
Method. Data is on monthly returns from 2001-2007 in
JQM_EF_Excel.xls and is available for download at
http://bit.ly/EFrontier
APPENDIX A
A1. Derivation of portfolio Expected return and variance for a
portfolio consisting of three risky assets A, B and C
The return for the portfolio is simply
r s A rA s B rB sC rC
Taking expectations on both sides of the above equation we get
Er s A ErA s B ErB sC ErC
This can be re-written as
s A A s B B sC C
The notations have their usual significance.
The variance of the portfolio can be written as,
Var (r ) Var (s A rA s B rB sC rC )
Let X = s ArA sB rB ; then we can re-write the above equation as13
Var (r )
Var ( X , sC rC ) = Var ( X ) 2 Cov ( X , sC rC ) Var (sC rC ) (A1.1)
Take the first term on the left-hand side, and we get
Var ( X ) Var (s A rA s B rB ) Var (s A rA ) 2 Cov (s A rA , s B rB ) Var (s B rB )
= s A2 Var (rA ) 2s A s B Cov (rA , rB ) s B2 Var (rB ) (A1.2)
13
For any X and Y, Var ( X Y ) Var ( X ) 2 Cov( X , Y ) Var (Y )
14
Cov(aX 1 bX 2 , Y ) a Cov( X 1 , Y ) b Cov( X 2 , Y )
p s A A s B B (A2.2)
0 (iii)
The assets are uncorrelated. One may think that this implies
that diversification is not possible; in fact, the benefits of
diversification are quite clear in this case. It is one of the basic
insights necessary to understand portfolio choice. Even though the
middle term in equation (5) drops out due to this assumption, the
analysis, in this case, is substantially more complex than in the
previous two cases. Equation (5) becomes:
p s
2
A
2
A s B2 B2 (A2.3)
2, it is also true that the portfolio frontier has the same hyperbolic
shape as in case (iii).