Efficient Frontier & Portfolio Optimization with Python [Part 2/2]

Bernard Brenyah
Nov 2, 2017 · 3 min read
Image for post
Image for post
William F. Sharpe. Image Credit: Sensible Investor

In the first part of this series, we looked at the underpinnings of Modern Portfolio Theory and generated an Efficient Frontier with the help of Monte Carlo Simulation. This post concludes the series by looking at the concept of portfolio optimization.

Image for post
Image for post

50,000 portfolios with different combinations of weights generated different expected returns and expected volatility. Each point lying on the line represents an optimal combination of stocks (CenterPoint Energy, Facebook, Walmart, General Electric, Tesla in this case) that maximises the expected return for the given level of risk. If all points on the Efficient Frontier curve are optimal combinations, what is the optimal portfolio among the various optimal combinations? What would even the criteria for choosing this “best of the best” combinations?

William F. Sharpe, another Nobel Prize laureate extended Markowitz’s work which resulted in the infamous Capital Asset Pricing Model (CAPM). This post will not delve into this model now. However, we will utilize one of his contributions (the Sharpe Ratio) as criteria for choosing this “best combination”.

Image for post
Image for post
Image Credit: Investopedia

Sharpe ratio is simply as a measure of the performance of an investment’s returns given its risk. This ratio adjusts the returns of an investment which makes it possible to compare different investments on a scale that incorporates risk. Without this scale of comparison, it would be virtually impossible to compare different investments with different combinations and their accompanying risks and returns.

We will take advantage of the code we used in generating the efficient frontier in the last post with some minor adjustments. We already have expected returns and returns of our simulated portfolios. We are simply going to calculate their risk-adjusted returns (with the help of the Sharpe Ratio), and make a colour bar of the plots using the Sharpe Ratio as the colour map:

Let’s see what we get. A nice efficient frontier coloured by the Sharpe Ratio of each portfolio’s risks and returns.

Image for post
Image for post

Next up, let’s try to locate the optimal portfolio and another portfolio with the minimum volatility for the most risk-averse investor out there:

There we have it. An Efficient Frontier with a highlight of the optimal (as per the risk-adjusted return metric) portfolio and a portfolio with the minimum volatility.

Image for post
Image for post

To get specific details of these two special portfolios, let’s print their values out:

The most risk-averse investor would construct the minimum variance portfolio which has an expected return of 4.58% with an accompanying expected volatility of 13.86%. Investors seeking the maximum risk-adjusted return would opt for portfolio that with the maximum Sharpe Ratio which has an expected return of 11.61% with expected volatility pegged at 17.50%

There are mathematical optimization techniques that would have resulted in the same result. However, I chose to use a Monte Carlo Simulation (sort of manual way) to explain the whole concept of Efficient Frontier and optimal portfolios. I will cover the mathematical technique in a future post (I promise!). Until the next post, happy coding!

As usual, you can grab the source code on the blog’s GitHub page.

DS Biz

A blog for data analytics using data science technologies

Bernard Brenyah

Written by

I have a love/hate relationship with numbers

DS Biz

DS Biz

A data analytic blog from a newbie for newbies. Check out the associated GitHub page for all the source codes: https://github.com/PyDataBlog/Python-for-Data-Science

Bernard Brenyah

Written by

I have a love/hate relationship with numbers

DS Biz

DS Biz

A data analytic blog from a newbie for newbies. Check out the associated GitHub page for all the source codes: https://github.com/PyDataBlog/Python-for-Data-Science

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store