Assessing Risks and Return with Probabilities of Events with Python

Image Credit: Byju’s

So far in the series about risk and return, we have looked at assessments using actual historical data. There are various situations where quants look at different scenarios of an event when making investment decisions. Running simulated scenarios is an invaluable tool for all finance/investment managers as it allows them to measure likely performance for various states.

These scenarios quants invent are normally based on probabilities of event/state occurring. It is quite normal to see three (3) states and their associated likely performance. For example: “What will be the likely performance an investment if the economy ‘booms’, ‘normalizes’ or ‘recesses’? I found an old paper Microsoft Excel exam paper and decided to use it to explain the calculation of expected returns and risk with the inclusion of probabilities.

As shown in the case pictured above, the question demands the calculation of the expected returns for each investment given the likelihood (probability) of a scenario panning out. This calculation can be done in Python by simply translating the formula for expected returns with the inclusion of probabilities.

Expected Return of a single asset with Probabilities
Expected Return of each investment

With the expected return of each asset calculated, let’s turn our attention to the returns of a portfolio consisting of the two investments. The question supplied equal weights for the portfolio. The portfolio’s expected return is calculated using this formula:

Expected Return of a Portfolio
Expected Individual Returns and Portfolio Returns

The next step is to look at the calculation of the covariance matrix for this equally weighted portfolio. From the covariance matrix, we can easily calculate the variance and standard deviation for each investment as well as their covariance and correlation. Luckily, numpy’s cov (covariance) method accomodates the inclusion of probabilities:

If ddof=0 the array of weights (aweights can be used to assign probabilities to observation vectors

We are almost there now. Let’s switch our attention to the portfolio’s variance and volatility. As covered in this post, the variance and standard deviation of a portfolio can easily be ascertained by means of a matrix multiplication sequence:

Weights transposed * (Covariance matrix * Weights)
Variance of a Portfolio expressed as matrix calculation

Great! All the heavy lifting is now complete so let’s look at the output of the analysis:

Output of exercise

The output from the above code:

Expected Return of Investment 1 = 7.5%
Expected Return of Investment 2 = 15.0%
Expected Return of Portfolio = 11.25%
Standard Deviation of Investment 1 = 1.77%
Standard Deviation of Investment 1 = 3.54%
Correlation between Returns of 1 & 2 = -1.0
Risk of Portfilio = 0.88%

The results from this analysis are interesting. Notice how the risk of each investment drops considerably when the two investments are consolidated into a single portfolio? That is one of the benefits of diversification through portfolio constructions. Don’t fret, for now! the next posts will cover these effects in detail.

With the fundamentals of Risk and Returns of assets covered, we are one step closer to one of the fundamental theories in Finance — Markowitz Portfolio Theory. The next post will look at this analysis. Until then, happy coding!


Here’s the full source code of the suggested solution which is hosted on this blog’s github page: