Markowitz applied to crypto assets

Theoretical unconstrained efficient frontier

We define a portfolio P of N risky assets. Each asset has a w_{i} weight in portfolio P and we set w=(w_{1},...,w_{N})^{T}, the vector of weights. We also define \mu the N-vector of expectation for our N assets: \mu=(\mu_{1}, ...,\mu_{N})^{T} . Finally, we set the variance-covariance matrix of the N risky assets as:

\begin{center} \Omega=\begin{bmatrix}  \sigma_{1}^2 & ... &\sigma_{1N} \\ . & . & .\\\sigma_{N1} & ... &\sigma_{N}^2 \\ \end{bmatrix}

where each \sigma_{ij} is the covariance between asset i and j.

The efficient portfolio solves the problem:

\begin{Center} Min\ w^T\Omega w \end{Center}

u.c.\begin{Center} \left\{\begin{array}{ll}w^T\mu=E_0\\w^Te=1\end{array}\right\end{Center}

E_0 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: E_0.

We solve this optimization problem by setting L(w,\lambda_1,\lambda_2)=\ w^T\Omega w-\lambda_1(w^T\mu-E_0)-\lambda_2(w^Te-1) its Lagrangian function.

\begin{Center}\frac{\partial L(w,\lambda_1,\lambda_2)}{\partial w}=0\Leftrightarrow 2\Omega w-\lambda_1\mu-\lambda_2e=0\end{Center}

\Leftrightarrow w=\frac{1}{2}(\lambda_1\Omega^{-1}\mu+\lambda_2\Omega^{-1}e)

Taking the first derivative of L(w,\lambda_1,\lambda_2) to \lambda_1 which should be equal to 0, we have:

\begin{Center}w^T\mu=E_0\Leftrightarrow E_0=\frac{1}{2}(\lambda_1\mu^T\Omega^{-1}\mu+\lambda_2e^T\Omega^{-1}\mu)\end{Center}

Taking the first derivative of L(w,\lambda_1,\lambda_2) to \lambda_2 which should be equal to 0, we have:

\begin{Center}w^Te=1\Leftrightarrow 1=\frac{1}{2}(\lambda_1\mu^T\Omega^{-1}e+\lambda_2e^T\Omega^{-1}e)\end{Center}

We set A=e^T\Omega^{-1}\mu=\mu^T\Omega^{-1}e because \Omega^{-1} is symmetric. And we also set B=\mu^T\Omega^{-1}\mu, C= e^T\Omega^{-1}e. Note that A, B and C are scalars.

Consequently, we have a system of two equations where \lambda_1 and \lambda_2 are the variables to solves:

\begin{Center} E_0=\frac{1}{2}(\lambda_1B+\lambda_2A)\end{Center}

\begin{Center} 1=\frac{1}{2}(\lambda_1A+\lambda_2C)\end{Center}

We set: d=BC-A^2

This system solutions are: \lambda_1=\frac{2}{d}(CE_0-A) and \lambda_2=\frac{2}{d}(B-AE_0)

Thus: w = \frac{1}{d}((CE_0-A)\Omega^{-1}\mu + (B-A E_0)\Omega^{-1}e)

Application: Mean-Variance scatter-plot

Let’s see how to chose the number of asset N 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 w_{min} which solve the following problem:

\begin{Center}Min\ w_{min}^T\Omega w_{min}\end{Center}

u.c. \  w_{min}^Te=1

By the same reasoning as in the theoretical part of the article we find that:

w_{min}=\frac{\Omega^{-1}e}{e^T\Omega^{-1}e}

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 N=15 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 E_0. We can then define Var Portfolio(E_0)=w^T\Omega w(E_0), 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:

BTCUSDT 111.49%
ETHUSDT -22.69%
LUNAUSDT -9.02%
BNBUSDT -1.64%
FTMUSDT 23.12%
MATICUSDT -15.07%
SOLUSDT -24.51%
SANDUSDT 11.52%
DOTUSDT -24.15%
ADAUSDT 12.45%
XRPUSDT 77.24%
AVAXUSDT -1.75%
GALAUSDT -44.85%
NEARUSDT 4.19%
ATOMUSDT 3.66%
Crypto weights for the efficient portfolio with 60% annualized volatility

Backtests

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).

Performance Unconstrained Weights Portfolio

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 E_0, 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:

Portfolio Composition November 2020

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:

Performance Positive Weights Portfolio

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 \frac{1}{N} weights. We take an arbitrary max bound to \frac{2}{N}. Here is the backtest result:

Portfolio Performance with positive weights constraints

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 \frac{2}{N}% 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:

Portfolio Performance with positive weights constraints and leverage

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.

Conclusion

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 \frac{2}{N}% 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.

Leave a Reply