Using modern portfolio theory to optimise a crypto portfolio.
If we were to ask you a simple question “Is a 40k Bitcoin bullish or bearish?” how would you respond? Well, we think it depends on when you ask the question. Back in the first quarter of 2021 as Bitcoin surged past its previous all-time highs a 40k Bitcoin seemed more bullish than ever. But right now, as Bitcoin trades below that level, the sentiment is completely different. The point is, the price goes up and the price goes down. When we are in a volatile place like crypto it’s sometimes hard to gauge what is a “cheap” price and what is “expensive”, since everything moves so quickly. From time to time, We think it’s useful to gauge your portfolio as a whole, not only through fundamental research but with mathematical models as well.
What is Modern Portfolio Theory?
“Diversification is the only free lunch” — Harry Markowitz
Modern portfolio theory is a practical way of maximising expected returns, at a given level of risk. Created by Nobel Prize laureate Harry Markowitz, he argues that risk and return should not be viewed independently. By balancing both risk and return, an investor can construct a multi-asset portfolio that will result in greater return, without increased risk.
For this article, we will be assuming that an average investor would be risk-averse. Given two portfolios with the same returns but higher risk, the investor will always opt for the lower risk one.
A mathematical way to measure returns
The expected return is the expected value of your gains or loss, given an asset. For our case, the expected return of our portfolio will be the weighted sum of the returns of the individual asset.
Since cryptocurrency is a volatile asset where the changes in price spans magnitudes, We will be using logarithmic returns. Calculated using the above formula.
Defining volatility as risk
There are many statistical methods to measure risk in statistics. For our case, we will be measuring risk as a function of the variance of each asset and the correlation of each pair of assets.
Constructing the model using Python
Now that we explained the theory, we will be using Python to construct this model. The link to the notebook can be found below.
Essentially, these are the main steps in Modern Portfolio Theory:
Calculate mean returns over a period for an asset
Calculate the standard deviation (risk) of an asset over a period
Get the weighted sum of expected returns and risk of all assets in a portfolio
Repeat multiple times for different weights
Find the efficient frontier that maximises reward and minimises the risk
Since we have previously explained how to calculate expected returns and risk, we will be importing the necessary libraries and data. For this model, we will be using these assets in the portfolio [BTC, ETH, SOL, LUNA, AVAX] with data taken from yahoo finance.
With the initial set-up complete, we will now be defining the functions to do the relevant calculations.
genWeights: This function will take in the number of assets in the portfolio and randomly generate the required amount of weights in the portfolio
calcDailyReturns: Applies the logarithmic return formula to get the daily returns for each asset
calcPortMeanReturn: Given the daily returns of each asset, calculates the mean daily return of each asset and takes a weighted sum to get the mean portfolio daily returns
calcRisk: Generates a Var-Cov matrix using the daily returns and square roots to get the standard deviation
The Efficient Frontier
With the initial calculations now complete, we will now be explaining the concept of the efficient frontier.
The efficient frontier is a set of data points with the most efficient ratio of variables. In our case, it is the set of data points that have the highest returns and the lowest risk. Looking at the graph above, we would expect the outcome of our model to be something like this, the efficient frontier would be the curve that gives us the lowest risk, for every level of return. In this case, we can pick a portfolio at a certain risk level given a requested expected return, or vice versa.
So how do we implement this graph? Now that we have defined the functions for the necessary calculations. We will be putting it together by calculating the overall expected returns and risk of the entire portfolio by randomising the weights repeatedly. Appending each random portfolio to a list as a data point.
Putting it all together, this is the result. From this graph, we can see that as the portfolio returns increase, the volatility increases even more. Depending on your risk tolerance and goals, we can optimise our portfolio to get the maximum returns given a threshold for volatility.
By limited the volatility to <5. We identify a portfolio with a weight:
[0.39693431, 0.12716904, 0.28051463, 0.1426872, 0.05269481]
From the exercise above, we can quickly see how Modern Portfolio Theory can be useful in structuring a portfolio. But there are some limitations as well.
This theory completely depends on historical data. Given the volatile nature of crypto, as well as reoccurring market cycles, we will get completely different data depending on whats our lookback period.
Furthermore, Modern Portfolio Theory only measures risk as volatility or variance. It does not measure downside risk. This means that two portfolios with equal variance may be considered equally desirable, but we know that just because something is stable doesn’t mean it’s safer.
Summarising everything, we can easily see how this can be useful in structuring our portfolio. While crypto is known to go out multiples in a short period, it also sucks when it drops 99% in a week. During volatile times, it’s best to build a portfolio that can be relatively muted to volatility to maintain our sanity. Coupled with fundamental research and an understanding of crypto narratives, we can easily build a portfolio that lets us sleep soundly at night.