Transcription
Let's compare two assets. Bitcoin, as crypto, has a low chance of losing money and a low chance of doing a 10x. Blue pepper has had 10x potential, but a ragpool possibility. Neither of this is better than the other. It depends on your degeneracy. In a Pareto ordering, these assets are incomparable.
Now take Ethereum. In this time window, Bitcoin gives you better returns for less risk. Mathematically, Ethereum is dominated. There is zero logical reason to hold it. It is strictly worse. And we call this a Pareto dominance relation. We say X dominates Y if X is strictly better in at least one criterion and not worse in any other. It means there is no tradeoff, no upside. It's just mathematically inferior.
If we add even more assets, the best forms something called a Pareto frontier: the set of all choices that are not dominated. You can consider basically all of them. But most of you, including me, just care about raw money. So why do we even care about minimizing this x-axis?
So let's compare two charts. You probably feel that these wiggles are bad. By exactly. So, first thing is that if you shorten the timeline, you know that holding here would be extremely painful and difficult not to sell. That's also related to the lack of liquidity. If you suddenly need cash here, you might be forced to sell during a drawdown for a loss.
And the second thing is that what I did was a huge oversimplification where I acted like I knew the future. Expected return is pretty much never the same as it was a year ago, and it is notoriously difficult to estimate. Risk is slightly easier.
American economist and statistician Milton Friedman popularized the rule of economics that there ain't no such thing as a free lunch. And the concept is simple: everything has an opportunity cost. If you want a higher return, you must take on higher risk. But what if we try to work against Friedman? What if we optimize these two competing variables: achieve the highest return possible while maintaining the smallest risk?
So, first, we need some way to quantify risk. We've just talked about how these wiggles are an example. Intuitively, the bigger the wiggle, the bigger the risk. But how can we get the size of them using math? So, when I first look at this problem, I wanted to make a straight line through the chart and measure the difference between it and, let's call it, a local peak in each wiggle. But measuring just the peaks isn't enough because risk happens everywhere. So, my next instinct was to measure the area of the gaps between the line and the wiggles. I wasn't exactly right, but it is intuitively close.
So, since our market data is discrete, just daily closing prices, let's switch to something like this in order not to confuse you with calculus. So, each bar here shows the percentage change of a value from day to day. And our previously unnamed line is the average of these changes. And so, our area is the sum of all of these distances between daily changes and the average line. But if we did this, the negative and positive deviations would cancel each other out. So, let's remove the sign, or even better, square them so it punishes bigger risks even more.
Now, the only issue is that 10 years of data will take much more area than one year. We don't want the total area. We want the average area per day. So, we divide the total sum by the number of observations. And some of you familiar with statistics probably already realize that we just came up with the variance formula. Variance is the sum of all distances between mean and deviation divided by the number of observations. We square the distance so positive and negative deviations don't cancel each other out. And now, because we squared units, we can't have dollars squared. We take the square root of it. And this gives us the standard deviation, which we usually just call volatility. And this number is the typical size of price movements. Basically, the size of those wiggles on a chart.
But it's pretty much always better to work with annualized volatility. On average, there should be around 252 trading days per year, though some people will use 253. Because daily price changes are very close to being independent events, their variances simply add together over time. Meaning, we can multiply our daily variance by 252. And then, to get our standard deviation, our actual volatility, we just take the square root, leaving us with this formula.
And so, volatility gave us a way to quantify how risky a single asset is. But a portfolio is made of multiple assets. And to understand how risk behaves in a portfolio, we first need to understand how assets move relative to each other: correlation.
So, let's take a break from math and just use Python. Here are assets. I intentionally picked assets from different areas of the market so we can actually see diversification in action. In this line, we fetch our prices. Compilot might want you to write something like this. I doubt it will compile. It is obsolete. We now use auto_adjust here as an argument. And we do it. We adjust our prices for stuff like dividends and stocks. Otherwise, we might get paid a dividend, price would drop, and script would see it as a loss. Then we get percentage returns. That's basically the bar chart I showed you moments ago. We can just take prices because Bitcoin at $60k and Nvidia at $200 are not comparable. And that's here is the most important line. It creates the correlation matrix, and the rest is just the visualization of it.
So, let's run it. So, this is the correlation matrix, and it tells us how a variable in each row correlates with a variable in each column. So, this row shows how Bitcoin moves with other assets. And to find how it relates to, for example, Ethereum, let's find the ETH column and then find where they intersect. You can see that Bitcoin here is correlated with Ethereum by a magnitude of 0.84. And this number is the correlation coefficient. It is a score between -1 and 1 inclusive. Numbers close to 1, like Bitcoin and Ethereum. These assets go up together, they crash together. Mathematically, this is called a positive linear dependence. And that means if you draw a scatter plot comparing their daily price changes, you will see that every time Bitcoin has a huge day, Ethereum does too. And that means that you can group them in such a way that you can draw a straight line through it. The closer the correlation is to 1, the closer they are to it.
And take note that the diagonal is always 1 because essentially we are asking, does Bitcoin move with Bitcoin? Yes. And the correlation matrix is symmetric, meaning that we can reflect it on its diagonal. And that is because Bitcoin is correlated to Ethereum the same way as Ethereum is to Bitcoin. And that's why you often see people hiding this upper half without losing any information.
So, if 1 meant tight leash, 0 would mean no leash at all. It means no linear relationship between those assets exists. Although, to be clear, more complex nonlinear relationships could still exist. For now, let's assume that if one stock crashes, this one might go up, it might go down, it might go sideways. In odd cases, you might also find negative correlations. Most of you would be S&P 500 and market fear index. In reality, most of your correlations will be in the range from 0 to 1.
But the correlation matrix has one thing that doesn't let us immediately use it in calculating risk. Imagine you have two government bonds that barely move 1% a month. When one creeps up, the other one creeps up with it. Their correlation score is 0.95. And now imagine two highly leveraged crypto tokens that swing 40% a day. When one crashes, the other one crashes right beside it. And their correlation score is also 0.95. So, to calculate the actual risk, we need those percentage swing sizes back. And that's why we combine these two concepts with length today: the direction, correlation, and the size, volatility, into a single metric which we call covariance.
So, when we calculate this for every single pair of assets, we upgrade our correlation matrix into a covariance matrix. And if you remember that our correlation matrix had a bunch of ones on its diagonal, well, if you multiply an asset's volatility by its own volatility, which I remind you was standard deviation, you get standard deviation squared. And by definition, that is variance. The diagonal of this new matrix shows the absolute variance of each individual asset, while the rest of it shows how their risks split into each other.
So, let's take a look at the actual risk formula for a simple two-asset portfolio. The left side of this equation, those weights W1 and W2, represent the percentage of your money in each asset. Because you only have 100% of your capital, let's keep stuff like borrowing or shorting. Those weights are fractions between 0 and 1. Sigma squared is the variance of each asset. And now, watch this. This formula looks awfully similar to the perfect square binomial. The only thing that is different is the raw term here, the correlation.
So, let's rewrite it like this. We are left with this formula, which we can split into two parts. The left-hand side is our base risk. If the correlation between assets were 1, meaning they move perfectly together, the right-hand side would zero out, and the equation would collapse into a perfect square, and that means diversification would do absolutely nothing. But when correlation is less than 1, which is pretty much always, it gets subtracted from the total risk. This part is our diversification benefit.
Harry Markowitz discovered the same thing. While your risk mathematically shrinks, your expected return does not. Expected return is just a simple straight-up weighted average. By diversifying, we are literally destroying risk without impacting our expected returns. And that's why Harry Markowitz famously stated, "Diversification is the only free lunch in finance." And that's why the entire English Wikipedia is obsessing over lunches.
Okay, that was a lot. So, let's use this to find the perfect combination of Bitcoin, Nvidia, and gold. So, the easiest thing to do is to find the percentage of assets that guarantee the lowest variance and the highest expected return. I don't think it will be interesting to derive yet another formula. So, we will just use this. We want to make our script useful for any portfolio. So, let's use the formula for N assets. W is the weight vector. So, basically an array of the percentage composition of our portfolio. Sigma is the covariance matrix. And this fun little T is transpose, so rotating this array 90 degrees. The expected return is similar, but mu is the expected return for each asset. I know it looks different than the sums, but trust me, it's just the matrix notation. And that's a result. We want to minimize the risk (the x-axis) and maximize return (the y-axis).
So, let's try another combination. And now another. We can do it for a while, but why not let the computer guess for us, and we will see what it had come up with. And what we actually did, randomly sampling the portfolio weights, was a Monte Carlo simulation. And now we are left with this result. It is called an efficient frontier, basically the same thing as this Pareto frontier from the beginning of the video. Mathematically speaking, all portfolios on the edge are optimal, and all portfolios inside are dominated. For each risk, you cannot find assets with a higher return than one on the efficient frontier. And the same is true that for the same return, you can no longer minimize your standard deviation by finding another combination. I intentionally left the efficient frontier line kind of junky. Calculating thousands of sets of weights is just computationally intensive.
And this is where the underlying math reveals something remarkable: the two-fund separation theorem. It proves that any portfolio on the efficient frontier can be constructed as a linear combination of any two distinct portfolios already located on it. So, if you find a safe portfolio A and a degenerate portfolio B, every other point on the curve is just a mix of two. If you want to stay between them, you just balance the weights. But the math also allows for leverage. The equation only requires that your weights add up to 100%. It never states anything about that both have to be positive. By doing this, you essentially extend the curve, pushing your portfolio further up and to the right.
But this model assumes you only have access to risky assets. What happens if we try to add a zero-risk asset? In the real world, let's say it's close to cash or treasury bonds. This is the one-fund separation theorem. Instead of mixing two risky portfolios, we draw a line from cash (RF) to our curve. And this line is called the Capital Market Line. And there is only one portfolio on that entire frontier that allows us to draw the steepest possible line. We call this the tangency portfolio. In the point of tangency, the weight of cash is zero, and the weight of the portfolio is one.
Let's actually derive the slope formula. Rise: the numerator is RP (return of our portfolio) minus RF (return of just holding bonds), that's excess return, the extra money we anticipate for taking a risk. And the denominator is the risk of our portfolio minus the risk of holding bonds, which we assumed was zero, so the denominator is just the portfolio volatility. And we get this. If you are already familiar with finance, you noticed that we've just derived the formula for the Sharpe ratio. By maximizing the Sharpe ratio, we are finding the one fund that makes every other combination on the frontier mathematically dominated. Whether you want to be safe or aggressive, you stay on this line. You don't buy a safer stock, you buy more cash. You don't buy a riskier stock, you lever up this perfect fund.
And what we just derived is not just an academic exercise. This math is the foundation of modern portfolio management. Pension funds, hedge funds, ETFs all use versions of this model. If you want to do it on your own, a reasonable Sharpe you should aim for should be over 1.5, maybe even nowadays over 2. Most hedge funds achieve it.
And now you probably ask yourself, if the math of the tangency portfolio is objectively so perfect, why isn't every hedge fund, quant desk, and retail trader holding the exact same set of assets? So, the efficient frontier requires two inputs: expected returns and a covariance matrix. And we actually don't know both of these. In this video, we only estimated both risk and expected returns using the past. Additionally, in a relatively simple manner. Honestly, if you can guess correctly the expected return, you've won the game. You are a billionaire. It is extremely difficult to estimate returns using historical data. Volatility is better, but still tough.
Richard Michaud famously stated that Markowitz's model is an error-maximizing algorithm. Pure math assumes that the historical data is an undeniable estimator of the future and thinks that everything will go the same way. The issue is that this data is full of noise. If you are off by just 1%, the algorithm might decide to allocate 40% of your portfolio to it instead of 5%. Furthermore, standard deviation penalizes all wiggles equally. If an asset suddenly shoots up 50% a day, standard deviation treats it as a high risk, lowering your Sharpe ratio. But no investor on earth considers making 10x their portfolio overnight an issue. And that is why you see people abandon the Sharpe ratio entirely in favor of metrics that only penalize downside wiggles, like the Sortino ratio, or measure maximum drawdowns. There is also a mistake with assuming linear correlations. There is even a saying that during a crisis, all correlations tend to 1. And more fundamentally, this approach is flawed because we are trying to model risk in terms of the likelihood of losses. But we never asked why do these losses might occur. Markowitz gave us the mathematical foundation, and the real challenge is everything that math doesn't capture.