Modern Portfolio Theory-Searching For the Optimal Portfolio-Portfolio Management in Python

Subscribe to newsletter

In the previous installment, we presented a description of the Model Portfolio Theory and provided a concrete example in Python. We also explained the concept of an Efficient Frontier and provided a visual presentation of it. Recall that,

… the efficient frontier (or portfolio frontier) is an investment portfolio which occupies the “efficient” parts of the risk–return spectrum. Formally, it is the set of portfolios which satisfy the condition that no other portfolio exists with a higher expected return but with the same standard deviation of return (i.e., the risk). The efficient frontier was first formulated by Harry Markowitz in 1952.

A combination of assets, i.e. a portfolio, is referred to as “efficient” if it has the best possible expected level of return for its level of risk (which is represented by the standard deviation of the portfolio’s return). Here, every possible combination of risky assets can be plotted in risk–expected return space, and the collection of all such possible portfolios defines a region in this space. In the absence of the opportunity to hold a risk-free asset, this region is the opportunity set (the feasible set). The positively sloped (upward-sloped) top boundary of this region is a portion of a hyperbola and is called the “efficient frontier”. Read more

Subscribe to newsletter https://harbourfrontquant.beehiiv.com/subscribe Newsletter Covering Trading Strategies, Risk Management, Financial Derivatives, Career Perspectives, and More

In this follow-up post, we are going to search for the optimal portfolio, i.e. one that has the highest risk-adjusted return. To do so, we will maximize the portfolio’s Sharpe ratio. The Sharpe Ratio is a financial metric that helps investors determine the return of an investment compared to its risk. It presents the average return that investors earn above the risk-free rate per unit of volatility or risk. The higher the Sharpe Ratio of a portfolio, the better it is in terms of risk-adjusted return.

Our hypothetical portfolio consists of 3 Exchange Traded Funds: SPY, TLT, and GLD which track the S&P500, long-term Treasury bond, and gold respectively.  We downloaded 10 years of data from Yahoo Finance and utilized a Python program to search for the optimal portfolio. The figure below shows the Efficient Frontier along with the optimal portfolio (depicted by the red dot).

Portfolio Management in Python

The figure below shows the optimal portfolio’s composition, return, volatility, and the Sharpe ratio.

Modern Portfolio Theory in Python


To download the accompanying Excel workbook or Python program for this post:
1. Subscribe to the newsletter. If you're already a subscriber, go to the next step
2. Once subscribed, refer a friend
After completing these steps, you’ll gain access to the file for this post, along with files for a dozen other posts.

Subscribe to newsletter https://harbourfrontquant.beehiiv.com/subscribe Newsletter Covering Trading Strategies, Risk Management, Financial Derivatives, Career Perspectives, and More

Further questions

What's your question? Ask it in the discussion forum

Have an answer to the questions below? Post it here or in the forum

LATEST NEWSWall Street Turns Icy on US Stocks as Tariffs Hit Markets Hard
Wall Street Turns Icy on US Stocks as Tariffs Hit Markets Hard

Wall Street forecasters are turning ice cold on US equities, telling investors to refrain from buying the selloff as President Donald Trump’s historic trade war raises the specter of recession.

Stay up-to-date with the latest news - click here
LATEST NEWS40-hour flightmare for passengers stuck 2,300 miles from their destination after a midair emergency
40-hour flightmare for passengers stuck 2,300 miles from their destination after a midair emergency

Virgin Atlantic passengers had to spend a night in an airport lounge in Turkey when their flight to India was diverted due to a medical emergency.

Stay up-to-date with the latest news - click here
LATEST NEWSenGene Reports Inducement Grants Under NASDAQ Listing Rule 5635(c)(4)
enGene Reports Inducement Grants Under NASDAQ Listing Rule 5635(c)(4)

BOSTON & MONTREAL — enGene Holdings Inc. (Nasdaq: ENGN, “enGene” or the “Company”), a clinical-stage, non-viral genetic medicines company, today reported the grant of inducement equity awards to seven newly-hired employees, with a grant date of April 2, 2025. The inducement awards consist of a…

Stay up-to-date with the latest news - click here
LATEST NEWSInside MrBeast's business, which generated $473 million in revenue in a single year and comprises much of his net worth
Inside MrBeast's business, which generated $473 million in revenue in a single year and comprises much of his net worth

MrBeast's business made $473 million in revenue in 2024. Of his net worth, he said he's a billionaire on paper but has under $1 million in the bank.

Stay up-to-date with the latest news - click here
LATEST NEWSEU says a trade deal with Mercosur is a "massive opportunity" given U.S. tariffs
EU says a trade deal with Mercosur is a "massive opportunity" given U.S. tariffs
Stay up-to-date with the latest news - click here

2 Comments

Leave a Reply