Introduction to Financial Portfolios — Risk & Return with Python

This articles demonstrates how to measure the risk adjusted performance of financial portfolios.

Amir Nejad
QuantJam
Published in
6 min readMar 9, 2021

--

Photo by Ioannis Ritos from Pexels

Related Read

If you find this article helpful please consider following both author and publication site.

Source code of this article can be downloaded from Github: Link

A financial portfolio is a collection of different assets such as stocks, bonds, ETFs, mutual funds, etc. The performance of any portfolio directly correlates to it’s constituents. Each asset within the portfolio has different return. The total return of the portfolio is determined by weight of each asset w multiplied by return of each asset r:

Total portfolio return formula

Let’s consider a portfolio containing following stock: AAPL, AMZN, GOOGL, TSLA. Suppose we ask two different “stock pickers” to recommend how much money we should invest in each of the aforementioned stocks. Stock picker A is more bullish on AAPL and GOOGL while stock picker B is more bullish on TSLA as it can be seen from the following table:

Portfolio Position Weights

Now consider we have invested money in both portfolios for two years. Cumulative returns of both portfolios are plotted in the following figure. As it can be seen, portfolio A’s return is rather steady whereas portfolio B’s performance has more ups and downs. Furthermore, pay attention to the return of both portfolios at January 2018. Even though the final return of both portfolios are equal, one portfolio seems to be more volatile than the other. Evaluating the return of the portfolios alone and ignoring the volatility is analogous to jumping to the conclusion without looking at the context. Therefore, there need to be a common denominator in comparing the assets considering both return and risk.

Tale of two different portfolios

Sharpe Ratio

Dr. William Sharpe, Nobel Prize laureate. [Courtesy of Larry D. Moore]

Professor William F. Sharpe is the 1991 Nobel Prize winner in the field of economics. In 1966, he invented a so called “reward-to-variability” ratio (which later on began being called the Sharpe ratio by later academics) to create a baseline to compare multiple portfolios in view of risk and return. The ratio is defined as follows:

Sharpe Ratio Formula

The risk-free return is the interest rate an investor can expect to earn on an investment that carries zero risk. In practice, the risk-free rate is commonly considered to equal to the interest paid on a 3-month government Treasury bill, generally the safest investment an investor can make.

The numerator of the Sharpe Ratio deducts risk-free return from the mean portfolio return (this often called excess return). It simply states, if a portfolio’s return is not higher than the risk-free interest return it is not worth investing.

The denominator of the equation contains portfolio standard deviation. The standard deviation quantifies how risky any given portfolio is. Therefore, if two funds offer similar returns, the one with higher standard deviation will have a lower Sharpe ratio. In order to compensate for the higher standard deviation, the fund needs to generate a higher return to maintain a higher Sharpe ratio as it can be seen from the following figure:

Theoretical Sharpe Ratio vs Standard Deviation

Using Python, Sharpe Ratio can be easily calculated as follows:

  • Function Returns calculates annualized portfolio return given individual average return of each asset with portfolio (mean_return) and percentages of each asset within the portfolio (weights). Then the average return of the portfolio is multiplied by 252 trading days (1 year) to create the annualized return.
  • Function STD calculates the standard deviation of portfolio given percentages of each asset with the portfolio (weights)and covariance matrix of asset return (cov_matrix).
  • Finally, function Sharpe takes mean return and standard deviation of portfolio to calculate Sharpe Ratio.

Now let’s look at the example we showed in previous section. Using the Sharpe function that introduced above, one can easily calculate the Sharpe ratio of both Portfolio A and B. As expected, Portfolio B has half the Sharpe Ratio of Portfolio A as can be seen from the following figure. Therefore, we can see stock picker of Portfolio B has taken additional risk without offering extra return as compared to stock picker of portfolio B. With the magic of Sharpe Ratio, we are now able to compare multiple portfolios with risk-adjusted rate of return.

Portfolio A has twice higher Sharpe Ratio than portfolio B

Beyond Sharpe Ratio

Shape Ratio is useful metric for portfolio evaluation however its usability suffers in some cases. For example, it was Sharpe (1994) himself who acknowledged that the ratio may not give correct answers if one or more investments are correlated with existing positions in a portfolio. Also, when comparing investments with negative returns, the calculation can produce a ratio that is counterintuitive — that is, a fund with a higher standard deviation may have a higher Sharpe ratio than another fund with a lower standard deviation. Other advancements in measuring portfolio performance are made to address these shortcomings (subject of our future articles).

Key Takeaways

Analyzing the return of portfolio without addressing the risk of portfolio is like comparing apples and oranges. Risk of each portfolio provides common baseline for the comparison of portfolios. Sharpe Ratio normalizes excess return of portfolio by standard deviation of that portfolio. Higher risk assets should provide higher returns based on Sharpe Ratio. Sharpe ratio as introduced here provided guidelines for comparing different portfolios. However, like any statistical measure, it is only as good as its assumptions. This article only scratches the surface of portfolio evaluation subject and in the future episodes we will review other performance metrics to address shortcomings of Sharpe Ratio. Stay tuned and follow us to get notified on future episodes.

Thanks for reading! My name is Amir Nejad,PhD. I’m a data scientist and editor of QuantJam , and I love share my ideas and to collaborate with other fellow data scientists. You can connect with me on Github, Twitter, and LinkedIn.

You can see my other writings at:

About QuantJam

Quantjam is a medium publishing company aims at sharing reproducible research focused on finance and stock market data.

Follow us to stay up-to-date on all articles and activities: https://medium.com/quantjam

Disclaimer

QuantJam writings do not include any investment advice. Past performance is no guarantee of future results. Please consult with your financial advisor before making any investment decision. Investing involves risk and you may incur a profit or loss regardless of strategy selected, including diversification and asset allocation. Investments mentioned may not be suitable for all investors.

All images have been produced by the author, except where stated otherwise.

References

  • Markowitz, H. (1952). “Portfolio Selection”. The Journal of Finance, 7(1), 77–91. doi:10.2307/2975974
  • Sharpe, William F. “The sharpe ratio.” Journal of portfolio management 21.1 (1994): 49–58.
  • https://en.wikipedia.org/wiki/Sharpe_ratio

--

--

Amir Nejad
QuantJam

PhD. Engineer | Data Scientist | Problem Solver | Solution Oriented (twitter: @Dr_Nejad)