Sub topic 4
The math of combining assets
This chapter assumes you know what stocks, funds, and ETFs are, can work with percentage returns and averages, and accept that higher expected return usually comes with higher risk. It also assumes you have met volatility (the standard deviation of returns) and correlation (a number from -1 to +1 that describes how two return series move together). Here you will turn those ideas into formulas and code.
Return adds up, risk does not
A portfolio's expected return is the weighted average of its holdings' expected returns. If asset A has an expected 8% a year and asset B has 5%, a 60/40 mix has an expected return of 0.6 * 8% + 0.4 * 5% = 6.8%. Mixing assets never produces a return outside the range of its parts.
Volatility does not work this way. Portfolio volatility is at most the weighted average of the holdings' volatilities, and it is usually lower. That gap is the diversification effect. You get the average return, with less risk than the average of the risks.
The tool for this is variance, which is volatility squared. Variance is the quantity that combines cleanly, so every calculation below works in variance and takes a square root at the end.
The two-asset formula
For two assets with weights w1 and w2 (which sum to 1), volatilities s1 and s2, and correlation rho:
variance = (w1*s1)^2 + (w2*s2)^2 + 2 * w1 * w2 * s1 * s2 * rho
volatility = sqrt(variance)The first two terms are each asset's own contribution. The third term is the interaction. It depends on rho and it is the only place correlation enters. The product s1 * s2 * rho is the covariance of the two assets, which measures how they move together in the original units of return.
The formula has three consequences:
- When
rho = 1, the variance equals(w1*s1 + w2*s2)^2. Volatility is exactly the weighted average and diversification gives no benefit. - When
rho < 1, the interaction term shrinks and volatility falls below the weighted average. - When
rho = -1, the interaction term cancels as much as it can. With the right weights,w1 = s2 / (s1 + s2), the portfolio has zero volatility. Real stocks almost never get near this.
Here is the calculation in Python, using two assets with 20% volatility each and a 50/50 split.
import math
def portfolio_vol(w1, s1, s2, rho):
w2 = 1 - w1
variance = (w1 * s1) ** 2 + (w2 * s2) ** 2 + 2 * w1 * w2 * s1 * s2 * rho
return math.sqrt(variance)
for rho in (1.0, 0.5, 0.0):
print(rho, round(portfolio_vol(0.5, 0.20, 0.20, rho), 4))
# 1.0 0.2
# 0.5 0.1732
# 0.0 0.1414At rho = 0.5 you keep the same expected return as the 20%-volatility holdings and cut risk to about 17.3%. At rho = 0 the risk falls to about 14.1%, which is 20% / sqrt(2).
| Correlation | Portfolio volatility | Reduction from 20% |
|---|---|---|
| 1.0 | 20.0% | 0% |
| 0.5 | 17.3% | about 13% |
| 0.0 | 14.1% | about 29% |
More than two assets
For n assets, every pair of holdings contributes an interaction term. In matrix form:
variance = sum over i, j of w_i * w_j * s_i * s_j * rho_ijHere rho_ii = 1, so the diagonal terms are each asset's own variance. Each off-diagonal pair appears twice, which is where the factor of 2 in the two-asset formula comes from. The number of pairs grows roughly with the square of n, so in a large portfolio the interaction terms outnumber the own-variance terms by far. This is why the average correlation matters more than any individual stock's risk once you hold many names.
This code handles any number of assets:
import math
def portfolio_vol_matrix(weights, vols, corr):
n = len(weights)
variance = 0.0
for i in range(n):
for j in range(n):
variance += weights[i] * weights[j] * vols[i] * vols[j] * corr[i][j]
return math.sqrt(variance)
weights = [0.5, 0.3, 0.2]
vols = [0.20, 0.15, 0.10]
corr = [
[1.0, 0.6, 0.2],
[0.6, 1.0, 0.1],
[0.2, 0.1, 1.0],
]
vol = portfolio_vol_matrix(weights, vols, corr)
avg_vol = sum(w * s for w, s in zip(weights, vols))
print(round(vol, 4), round(avg_vol, 4), round(avg_vol / vol, 2))
# 0.1371 0.165 1.2The weighted average of the three volatilities is 16.5%, but the portfolio runs at about 13.7%. The ratio of the two, about 1.2, is sometimes called the diversification ratio. A value of 1.0 means no benefit, and larger values mean more.
Many holdings: the floor set by correlation
Suppose you hold n stocks in equal weights. Every stock has volatility sigma, and every pair has the same correlation rho. The formula simplifies to:
variance = sigma^2 * (1/n + (1 - 1/n) * rho)The 1/n part comes from the n own-variance terms. Each is (1/n)^2 * sigma^2, and there are n of them. The (1 - 1/n) * rho part comes from the n(n-1) pair terms. As n grows, the first part shrinks toward zero and the second approaches rho. Volatility therefore falls toward a floor:
floor = sigma * sqrt(rho)import math
def equal_weight_vol(n, sigma, avg_rho):
variance = sigma ** 2 * (1 / n + (1 - 1 / n) * avg_rho)
return math.sqrt(variance)
for n in (1, 5, 20, 100, 1000):
print(n, round(equal_weight_vol(n, 0.30, 0.30), 4))
# 1 0.3
# 5 0.199
# 20 0.1736
# 100 0.1662
# 1000 0.1645With sigma = 30% and rho = 0.3, the floor is 0.30 * sqrt(0.30), about 16.4%. Going from 1 to 5 stocks removes about ten percentage points of volatility. Going from 100 to 1000 removes about 0.2. Past a few dozen holdings, adding names buys almost nothing in this model.
The part that diversification removes is idiosyncratic risk, the risk specific to one company. The floor is systematic risk, which comes from forces that move the whole market. The earlier chapter on risk types covered the distinction. In this model, the average correlation is what sets the size of the systematic part.
Where the math misleads
The formulas are exact, but their inputs are estimates. These are the common errors:
- Treating correlation as fixed. Correlations are estimated from past returns and change over time. In sharp market sell-offs, correlations between stocks, and between stock markets, tend to rise. The diversification you computed from calm periods is then smaller than you expected. Later in this tutorial, the chapter on the limits of diversification returns to this.
- Ignoring estimation noise. With a short history, a measured correlation of 0.2 may be consistent with a true value anywhere from about -0.1 to 0.5. Small differences between measured correlations are not meaningful.
- Mixing time units. Volatility and covariance must be on the same horizon. Annual volatility with monthly correlation is fine, because correlation has no units, but do not add monthly and annual variances together. To scale volatility, multiply daily by
sqrt(252)or monthly bysqrt(12). - Using price correlation instead of return correlation. Two trending prices can look highly correlated even when their returns are unrelated. Compute correlation on returns.
- Assuming weights stay put. The formula uses current weights. A holding that has outperformed becomes a larger share, so the risk of the portfolio drifts away from what you calculated. Rebalancing, covered in a later chapter, addresses this.
- Reading low volatility as safety. Volatility measures the size of typical swings. It says nothing about the chance of a permanent loss, such as one company going bankrupt.
Summary of the working model
- Expected return is a weighted average. Risk is not.
- Portfolio variance is the sum of own-variance terms and pairwise interaction terms.
- The lower the correlations, the more volatility falls below the weighted average.
- Adding holdings removes idiosyncratic risk quickly and then hits a floor set by correlation.
- All of this depends on estimated inputs that shift over time.
Exercise
A portfolio holds 60% in asset A (volatility 25%) and 40% in asset B (volatility 10%), with a correlation of 0.2 between them. Compute the portfolio volatility, and compare it with the weighted average of the two volatilities.
Show answer
Variance = (0.60.25)^2 + (0.40.10)^2 + 20.60.40.250.100.2 = 0.0225 + 0.0016 + 0.0024 = 0.0265. Volatility = sqrt(0.0265), about 16.3%. The weighted average is 0.625% + 0.4*10% = 19%. Diversification lowers risk by about 2.7 percentage points.
Exercise
An equal-weight portfolio holds 50 stocks. Each has 24% volatility and every pair has a correlation of 0.25. Using the equal-weight formula, what is the portfolio volatility, and what is the floor as the number of stocks grows without limit?
Show answer
Variance = 0.24^2 (1/50 + (1 - 1/50) 0.25) = 0.0576 (0.02 + 0.245) = 0.0576 0.265 = 0.015264. Volatility = sqrt(0.015264), about 12.4%. The floor is 0.24 * sqrt(0.25) = 12%. Fifty stocks already come within about 0.4 percentage points of it.