Theoretical unconstrained efficient frontier
We define a portfolio P of N risky assets. Each asset has a weight in portfolio P and we set , the vector of weights. We also define the N-vector of expectation for our N assets: . Finally, we set the variance-covariance matrix of the N risky assets as:
where each is the covariance between asset i and j.
The efficient portfolio solves the problem:
is a given portfolio expected return and e is the unit Nx1 vector. This minimization problem doesn’t set strong constraints on weights. It assumes they can be either positive or negative without any min or max boundaries for each individual assets. We only assume that the sum of weights must be equal to 1 and the total portfolio expectation is set to a fix number: .
We solve this optimization problem by setting its Lagrangian function.
Taking the first derivative of to which should be equal to 0, we have:
Taking the first derivative of to which should be equal to 0, we have:
We set because is symmetric. And we also set . Note that , and are scalars.
Consequently, we have a system of two equations where and are the variables to solves:
This system solutions are: and
Application: Mean-Variance scatter-plot
Let’s see how to chose the number of asset in our portfolio. The more we diversify, the less volatility our portfolio should have. We chose to study the size impact on the minimum variance portfolio total annualized volatility. It is defined as the set of weights which solve the following problem:
By the same reasoning as in the theoretical part of the article we find that:
The following graph shows the total portfolio annualized volatility as a function of the number of assets. As expected it is a decreasing function. Our portfolio of 1 asset (BTC) is a 62% volatile portfolio. If we increase our portfolio to hold 13 assets, the total volatility decrease to less than 50%. If we keep increasing the total number of assets to 50, our annualized volatility decrease to less than 20% per annum.
The dilemma here is to select enough assets to diversify our portfolio and have a manageable number of assets to deal when rebalancing without much costs. Remember that this portfolio is unconstrained meaning our weights can have any number. The only portfolio constraint is that the sum of weight should equal 1. We decide to take 15 asset for the following parts of this article.
With and a lookback period of 2 months, we can build the markowitz efficient frontier for our crypto universe. The frontier line is the expectation value for a given amount of risk the investor assumes for his portfolio. It can also be defined as the risk he/she wants to take for a given level of return. At the end of of the theoretical paragraph, we have defined a weight vector as a function of the total portfolio expectation . We can then define , our total portfolio variance as a function of the portfolio expectation. This is the red line in the graph below:
Note that this graph has been drawn with data from DEC 21 and JAN 22 where the crypto space was mostly down making annualized returns in our graph ridiculous.
If we want to take a 60% volatility risk in our portfolio, here are the appropriate weights to give to our assets:
Unconstrained Weights Portfolio
Now that we have defined the optimized unconstrained mean variance portfolio according to Markowitz theory, I have tried to backtest the performance of such a strategy over a 2 year period on 15 cryptocurrencies. Every start of the month, we select a universe of 15 crypto currencies, based on the most traded cryptos over the last 2 months. We pick the means and variances observed on the market over this timeframe as our input for the portfolio construction. The portfolio weight vector at any rebalancing date is a function of the investor expected return for her portfolio. We set this expected return as the return such as the corresponding variance according to the mean variance theoretical function is the mean of volatilities seen in our market universe. Below is the evolution of such a portfolio with a starting value of 1000 USD (blue line) and the corresponding BTCUSD price evolution (red line).
This example emphasize one of the key aspects of this construction: uncontrolled leverage. As our optimisation constraints only set that our sum of weights should be equal to 1 and our portfolio expected return should be equal to , individual weights are unbounded with either positive or negative value. As a consequence, even if your portfolio hits 160k USD value in august 2021, it went to 121 USD in November 2020. Bear in mind that you started this strategy with an initial value of 1000 USD so as of this date, you were down 90%. Let us have a look at the portfolio composition around this date:
The portfolio is mainly long 263% of BTCUSDT and short 117% of XRPUSDT. Other weights are importants but less significant. During this timeframe, XRP tripled its value against USD. So why does our theoretical construction find such a big negative weight for XRP ? Well, during the 2 months lookback period we used to estimate our cryptos means and variances, it performed quite negatively compared to other crypto currencies with an important volatility. As a consequence the algorithm set a strong negative number to this asset in its allocation. This is an important aspect of this construction: instability. When there are only small differences in the inputs, especially when assets are highly correlated, portfolio optimisation produces extreme weights. For instance, take a portfolio of 3 assets, all of them with a correlation of 90% to each other. If the three assets have the same expected return but one of them has a higher expected volatility, our portfolio construction will reject it from our allocation. Why? Because it brings the same level of return as the two other assets for a higher risk.
Constrained Weights Portfolio
We take the same problem and add the constraint that any weight in our portfolio must be positive. As the sum of weights equal 1, all weights are a a number between 0 and 1. This optimisation problem doesn’t have a closed form, but we can easily find a solution by using a numerical optimizer such as python cvxpy library. It aims at solving any convex function under admitted constraints. Here are the results of such a strategy on the previous 2 years:
This portfolio clearly outperforms BTC during the last two years timeframe. It goes near 20k for the first time in May 2021 and then cross this level around mid November while BTC was near 69k USD. However, the portfolio still has very important drawdowns, more than 50% from beginning of May 2021 to end of July 2021. This is expected as BTC and all major cryptocurrencies suffered the same kind of pullbacks during this period. Below is the composition in may 2021:
The portfolio is mostly a composition of 30.5% ETH, 24.3% BNB, 12.9% FIL and 8.9% VET. BTC was out of this composition as other assets outperformed it earlier in 2021.
Adding the positive constraint on our optimization problem add strong boundaries to each weight (between 0 and 100%) which solved the uncontrolled leverage seen on the previous section. However we can still have an unstable allocation with almost everything allocated to a few assets. This is the case if we take a look at the composition for the month of August 2021:
Almost 83% of the portfolio is allocated to BTC. We still want to build a portfolio with different assets to achieve diversification. As a consequence, we tried another strategy by adding another constraint to the optimisation problem: a maximum weight for each assets. If we have an equally weighted portfolio, each assets has a weights. We take an arbitrary max bound to . Here is the backtest result:
The red line is the performance of this strategy. The blue line is the performance of the previous strategy evolution with positive weights bounded to only 100% and the green line is the BTC performance for this timeframe. The additional constraint on the maximum weight for each asset to seems to improve the performance on the period. Drawdowns are relatively similars in terms of % loss while the max return on the period has been improved in this new strategy with more diversification. Now, we tried to add some leverage to this strategy with a x2 leverage for any positions taken on this red line strategy:
Performances are crazy in a good and bad way. Good because we almost reached 330k USD in May 2021 with a 1000 USD initial investment. Bad because the drawdown following this peak is more than 80%. Note that it bounces back to 250k in November 2021. This is typically the kind of drawdown we saw for the unconstrained construction. Adding leverage to an optimized portfolio seems to be a dangerous game as it amplifies significantly your risk.
In this article, we have shown how to build a theoretical Markowitz portfolio and what are the limits of such a construction. It mostly suffers of instabilities like excessive weight leverage (either positive or negative) and portfolio concentration as it strongly overweights assets with very good risk / returns characteristics and underweights those with deeply negative scores. We have seen how to improve this theoretical construction by using a numerical solver and adding new constrains to each portfolio weights. By adding the rule that each weight must be positive, we have removed the excessive use of leverage in the portfolio optimization, reducing the risk of ruin for the investor. By adding a maximum weight size of for each asset, we have improved the strategy performance over the previous two years. If you have already worked on portfolio optimisation topics and are keen to provide some insights, feel free to comment or drop me an email.