Portfolio Theory
20 min
Modern Portfolio Theory's core insight: a portfolio's risk (variance)
depends not just on each asset's own variance, but on how they move
TOGETHER — their covariance. For two assets with weights w1, w2:
def portfolio_variance_2asset(w1, w2, var1, var2, cov12):
return w1**2 * var1 + w2**2 * var2 + 2 * w1 * w2 * cov12
If cov12 is negative (the assets move in OPPOSITE directions), the
last term REDUCES total variance — that's diversification working
exactly as intended: combining imperfectly-correlated assets lowers risk
below what either asset has alone, without necessarily lowering expected
return.
Same individual variances, same weights -- only the covariance changes, and the portfolio variance drops noticeably as it goes from positive to negative. That's the entire mathematical case for diversification, in one line.
The Sharpe ratio answers "how much return am I getting per unit of risk taken?" — it lets you compare investments with completely different risk levels on a level footing:
def sharpe_ratio(portfolio_return, risk_free_rate, portfolio_std):
return (portfolio_return - risk_free_rate) / portfolio_std
# two portfolios with different risk/return, same Sharpe
print(sharpe_ratio(0.12, 0.03, 0.15)) # 0.6
print(sharpe_ratio(0.08, 0.02, 0.1)) # 0.6 -- same risk-adjusted quality, despite lower raw numbers
A HIGHER raw return isn't automatically "better" if it came with proportionally more risk — the Sharpe ratio is the standard way quant researchers and portfolio managers compare strategies fairly, rather than just chasing whichever number looks biggest.
Write `portfolio_variance_2asset(w1, w2, var1, var2, cov12)`: for a 2-asset portfolio, variance `= w1²·var1 + w2²·var2 + 2·w1·w2·cov12`. Round to 6 decimals.
Write `sharpe_ratio(portfolio_return, risk_free_rate, portfolio_std)`: `(portfolio_return - risk_free_rate) / portfolio_std`, rounded to 4 decimals.
What does the Sharpe ratio measure?
You can compute a 2-asset portfolio's variance (seeing diversification's effect directly) and the Sharpe ratio for comparing risk-adjusted returns.