Finance · 14 min read · ~29 min study · advanced
Portfolio Theory and CAPM
Mean-variance optimization, the efficient frontier, CAPM — the maths behind diversification.
Portfolio Theory and CAPM: The Maths Behind Diversification
Mean-variance optimization, the efficient frontier, and the Capital Asset Pricing Model — how modern finance thinks about building portfolios.
"Don't Put All Your Eggs in One Basket" — But With Maths
Diversification is one of those ideas that feels obviously true. Spreading your money across multiple investments reduces risk. But it took Harry Markowitz's 1952 paper to formalise why and how much, and the result was worth a Nobel Prize.
The insight is elegant: portfolio risk depends not just on the riskiness of individual assets, but on how they move together. Two volatile assets that move in opposite directions can combine into a surprisingly calm portfolio. The maths of this — covariance matrices, optimization, and a bit of calculus — is the foundation of modern portfolio management.
Portfolio Return and Risk
For a portfolio of ( n ) assets with weights ( w_1, w_2, \ldots, w_n ):
Expected return:
[ E[R_p] = \sum_{i=1}^{n} w_i E[R_i] = \mathbf{w}^T \boldsymbol{\mu} ]
Portfolio variance:
[ \sigma_p^2 = \sum_{i=1}^{n} \sum_{j=1}^{n} w_i w_j \sigma_{ij} = \mathbf{w}^T \Sigma \mathbf{w} ]
That second formula is the important one. The covariance matrix ( \Sigma ) captures all the pairwise relationships. If assets are perfectly correlated (( \rho = 1 )), diversification provides no benefit. If they are negatively correlated, you get risk reduction for free.
The Efficient Frontier
Imagine plotting every possible portfolio on a graph: expected return on the y-axis, risk (standard deviation) on the x-axis. The upper boundary of this cloud — the set of portfolios that deliver the maximum return for each level of risk — is the efficient frontier.
Any rational investor would choose a portfolio on the frontier. Anything below it is suboptimal: you could get the same return with less risk (or more return with the same risk) by shifting to the frontier.
Finding the frontier is an optimization problem:
[ \min_{\mathbf{w}} \mathbf{w}^T \Sigma \mathbf{w} \quad \text{s.t.} \quad \mathbf{w}^T \boldsymbol{\mu} = r_{\text{target}}, \quad \mathbf{w}^T \mathbf{1} = 1 ]
Vary the target return and you trace out the entire frontier.
The Minimum-Variance Portfolio
The leftmost point on the efficient frontier — the portfolio with the absolute lowest risk — is the minimum-variance portfolio. Its weights are:
[ \mathbf{w}_{\text{mv}} = \frac{\Sigma^{-1} \mathbf{1}}{\mathbf{1}^T \Sigma^{-1} \mathbf{1}} ]
You need the inverse of the covariance matrix, which is why linear algebra is not optional for quant finance. In practice, inverting a noisy estimated covariance matrix is fraught with problems, which is why techniques like shrinkage estimation (Ledoit-Wolf) are widely used.
The Capital Asset Pricing Model (CAPM)
Markowitz told us how to build optimal portfolios. William Sharpe took the next step: if everyone builds Markowitz-optimal portfolios, what does the market look like?
The CAPM says the expected return of any asset is:
[ E[R_i] = R_f + \beta_i (E[R_m] - R_f) ]
where:
- ( R_f ) is the risk-free rate
- ( E[R_m] ) is the expected market return
- ( \beta_i = \frac{\text{Cov}(R_i, R_m)}{\text{Var}(R_m)} ) measures the asset's sensitivity to the market
What Beta Means
- ( \beta = 1 ): moves with the market
- ( \beta > 1 ): amplifies market moves (tech stocks, cyclicals)
- ( \beta < 1 ): dampens market moves (utilities, consumer staples)
- ( \beta < 0 ): moves opposite to the market (rare)
Beta is computed by running a regression of the asset's excess returns against the market's excess returns. The slope coefficient is beta.
The Security Market Line
The CAPM relationship, plotted with beta on the x-axis and expected return on the y-axis, is the Security Market Line (SML). Assets above the line offer excess return (positive alpha). Assets below it are overpriced.
Finding alpha — return not explained by systematic risk — is the central quest of quantitative investing. The CAPM says alpha should not exist in an efficient market. Empirical evidence says otherwise, which led to factor models.
Factor Models
The CAPM uses a single factor (the market). Reality is more complex. The Fama-French three-factor model adds:
- SMB (Small Minus Big): small-cap stocks tend to outperform
- HML (High Minus Low): value stocks tend to outperform
Modern quant equity strategies use dozens of factors: momentum, quality, low volatility, profitability, and many more. Each factor represents a systematic source of return — or risk, depending on your perspective.
The relationship to regression is direct:
[ R_i - R_f = \alpha + \beta_1 F_1 + \beta_2 F_2 + \cdots + \beta_k F_k + \epsilon ]
The betas measure factor exposures. Alpha is the unexplained excess return. Building and testing factor models is core buy-side quant work.
The Sharpe Ratio
Named after William Sharpe, the Sharpe ratio measures risk-adjusted return:
[ S = \frac{E[R_p] - R_f}{\sigma_p} ]
A Sharpe ratio above 1 is generally considered good. Above 2 is excellent. Above 3 and people start getting suspicious (is it real, or have you overfit?).
The tangency portfolio — the portfolio on the efficient frontier with the highest Sharpe ratio — is theoretically the optimal risky portfolio. According to the CAPM, it should be the market portfolio.
Limitations and Reality
Portfolio theory is elegant but makes strong assumptions:
- Returns are normally distributed (they are not — fat tails)
- Correlations are stable (they spike in crises)
- Covariance matrices can be estimated accurately (they cannot, with typical sample sizes)
These limitations do not invalidate the framework — they make it a starting point rather than an endpoint. Real quant work involves dealing with these messy realities.
Portfolio Theory in Python
import numpy as np
# 3-asset portfolio
mu = np.array([0.08, 0.12, 0.06]) # Expected returns
cov = np.array([
[0.04, 0.006, 0.002],
[0.006, 0.09, 0.009],
[0.002, 0.009, 0.01]
])
# Equal-weight portfolio
w = np.array([1/3, 1/3, 1/3])
port_return = w @ mu
port_vol = np.sqrt(w @ cov @ w)
sharpe = (port_return - 0.03) / port_vol # Assuming 3% risk-free
print(f"Return: {port_return:.2%}, Vol: {port_vol:.2%}, Sharpe: {sharpe:.2f}")
Dive Deeper
Portfolio theory is where linear algebra, optimization, and statistics converge. covers the entire journey — from the maths foundations through to constructing and backtesting real portfolios in Python.
For additional reading, Investopedia's Modern Portfolio Theory guide and the CFA Institute's resources are both solid.
Frequently Asked Questions
What is Modern Portfolio Theory in simple terms?
Modern Portfolio Theory (MPT), developed by Harry Markowitz in 1952, shows that you can reduce portfolio risk without reducing expected returns through diversification. The key insight is that an asset's risk should be evaluated not in isolation but by how it contributes to overall portfolio risk — its correlation with other assets matters as much as its individual volatility.
What is the CAPM and why does it matter?
The Capital Asset Pricing Model (CAPM) predicts that an asset's expected return depends only on its systematic risk (beta — sensitivity to market movements). Unsystematic (stock-specific) risk can be diversified away and therefore is not rewarded. While CAPM has well-known limitations in practice, it remains a foundational framework and is still used for cost of capital estimation and performance attribution.
Is Modern Portfolio Theory still relevant?
Yes, though with important caveats. MPT's core insight — that diversification reduces risk — is unassailable. However, the assumptions (normally distributed returns, stable correlations) break down during market stress. Modern practice uses robust estimation, shrinkage estimators, and risk management techniques to address these limitations.
What maths do I need for portfolio theory?
You need linear algebra (covariance matrices, matrix operations), optimization (quadratic programming, constrained optimization), and statistics (estimation, hypothesis testing). Python with NumPy and SciPy is the standard implementation tool.
Want to go deeper on Portfolio Theory and CAPM: The Maths Behind Diversification?
This article covers the essentials, but there's a lot more to learn. Inside , you'll find hands-on coding exercises, interactive quizzes, and structured lessons that take you from fundamentals to production-ready skills — across 50+ courses in technology, finance, and mathematics.
Free to get started · No credit card required
Keep Reading
[Finance
Understanding Financial Markets: A Practical Guide for Aspiring Quants
Equity, fixed income, FX, derivatives — how financial markets actually work, who the participants are, and where quantitative engineers fit in.](/quant-knowledge/finance/understanding-financial-markets)[Mathematics
Linear Algebra for Quant Finance: Vectors, Matrices, and Why They Run Everything
Portfolio weights are vectors. Covariance is a matrix. Risk decomposition uses eigenvalues. Here is the linear algebra every quant actually needs.](/quant-knowledge/mathematics/linear-algebra-for-quant-finance)[Mathematics
Optimization in Quant Finance: Finding the Best Portfolio (and Everything Else)
From Markowitz to gradient descent — optimization is how quants find optimal portfolios, calibrate models, and minimize risk. Here is how it works.](/quant-knowledge/python/numpy-for-quantitative-finance)[Finance
Risk Management in Quantitative Finance: VaR, Stress Testing & Beyond (2026)
A comprehensive guide to quantitative risk management — Value at Risk, expected shortfall, credit risk, stress testing, and the mathematical tools behind modern risk frameworks.](/quant-knowledge/finance/risk-management-in-quantitative-finance)
What You Will Learn
- Explain "don't put all your eggs in one basket" — but with maths.
- Build portfolio return and risk.
- Calibrate the efficient frontier.
- Compute the minimum-variance portfolio.
- Design the capital asset pricing model (capm).
- Implement factor models.
Prerequisites
- Derivatives intuition — see Derivatives intuition.
- Options Greeks — see Options Greeks.
- Comfort reading code and basic statistical notation.
- Curiosity about how the topic shows up in a US trading firm.
Mental Model
Markets are auctions for risk. Every product, model, and strategy in this section is a way of pricing or transferring some piece of risk between counterparties — and US markets give you the deepest, most regulated, most algorithmic version of that auction in the world. For Portfolio Theory and CAPM, frame the topic as the piece that mean-variance optimization, the efficient frontier, CAPM — the maths behind diversification — and ask what would break if you removed it from the workflow.
Why This Matters in US Markets
US markets are the deepest, most algorithmic, most regulated capital markets in the world. The SEC, CFTC, FINRA, and Federal Reserve govern equities, options, futures, treasuries, and OTC derivatives. The big buy-side (Bridgewater, AQR, Citadel, Two Sigma, Renaissance) and the major sell-side (GS, MS, JPM, Citi, BofA) hire heavily against the material in this section.
In US markets, Portfolio Theory and CAPM tends to surface during onboarding, code review, and the first incident a junior quant gets pulled into. Questions on this material recur in interviews at Citadel, Two Sigma, Jane Street, HRT, Jump, DRW, IMC, Optiver, and the major bulge-bracket banks.
Common Mistakes
- Quoting risk-free rates without saying which curve (T-bill, OIS, fed funds futures).
- Treating implied volatility as a forecast instead of a market-clearing quantity.
- Using realized correlation as a hedge ratio without accounting for regime change.
- Treating Portfolio Theory and CAPM as a one-off topic rather than the foundation it becomes once you ship code.
- Skipping the US-market context — copying European or Asian conventions and getting bitten by US tick sizes, settlement, or regulator expectations.
- Optimizing for elegance instead of auditability; trading regulators care about reproducibility, not cleverness.
- Confusing model output with reality — the tape is the source of truth, the model is a hypothesis.
Practice Questions
- Compute the delta of an at-the-money call on SPY with one month to expiry under Black-Scholes (σ=18%, r=5%).
- Why does the implied volatility surface for SPX exhibit a skew rather than a flat smile?
- Define the Sharpe ratio and explain why it is annualized.
- Why does delta-hedging a sold straddle on SPY produce P&L proportional to realized minus implied variance?
- What does a 100 bps move in the 10-year Treasury yield typically do to a 30-year fixed-rate mortgage rate?
Answers and Explanations
- Δ = N(d1) where d1 = (ln(S/K) + (r + σ²/2)T) / (σ√T). With S=K, T=1/12, σ=0.18, r=0.05: d1 ≈ (0 + (0.05 + 0.0162)·0.0833) / (0.18·0.2887) ≈ 0.106; N(0.106) ≈ 0.542. Delta ≈ 0.54.
- Because investors pay a premium for downside protection (left tail) and equity returns are negatively correlated with volatility; out-of-the-money puts therefore trade rich relative to OTM calls.
- Sharpe = (excess return) / (volatility). Annualization (multiply by √252 for daily returns) puts strategies of different frequencies on comparable footing — a key requirement for comparing US asset managers.
- Because the hedger captures gamma·dS² over time; integrating gives Σ gamma·(dS)², and theta paid over the life is set by implied variance. Net P&L tracks σ_realized² − σ_implied² scaled by gamma exposure.
- Roughly 75-100 bps move the same direction; mortgages are priced off the 10y plus a spread that includes prepayment risk and originator margin, which both move with rates.
Glossary
- Delta — first derivative of option price with respect to underlying.
- Gamma — second derivative; rate of change of delta.
- Vega — sensitivity of option price to implied volatility.
- Theta — time decay; daily P&L from holding the option as expiry approaches.
- Implied volatility — the σ that, when plugged into Black-Scholes, recovers the market price.
- Skew — variation of implied volatility across strikes.
- Spread — the difference between two prices; a yield curve, an option spread, or a cross-instrument arb.
- Sharpe ratio — annualized excess return divided by annualized volatility; the standard performance metric in US asset management.
Further Study Path
- Understanding Financial Markets — Equity, fixed income, FX, derivatives — how markets actually work and where quants fit in.
- Time Value of Money — Present value, future value, discounting, NPV — the concept that underpins all of finance.
- Bonds and Fixed Income — Pricing, yield to maturity, duration, convexity — the fixed-income concepts behind interest-rate modeling.
- Python for Quant Finance: Fundamentals — Variables, functions, data structures, classes, and error handling — the core Python every quant role expects.
- Advanced Python for Financial Applications — Decorators, generators, and context managers — the patterns that separate beginner Python from production quant code.
Key Learning Outcomes
- Explain "don't put all your eggs in one basket" — but with maths.
- Apply portfolio return and risk.
- Recognize the efficient frontier.
- Describe the minimum-variance portfolio.
- Walk through the capital asset pricing model (capm).
- Identify factor models.
- Articulate the pn0 ratio.
- Trace portfolio as it applies to portfolio theory and capm.
- Map capm as it applies to portfolio theory and capm.
- Pinpoint theory as it applies to portfolio theory and capm.
- Explain how portfolio theory and capm surfaces at Citadel, Two Sigma, Jane Street, or HRT.
- Apply the US regulatory framing — SEC, CFTC, FINRA — relevant to portfolio theory and capm.
- Recognize a single-paragraph elevator pitch for portfolio theory and capm suitable for an interviewer.
- Describe one common production failure mode of the techniques in portfolio theory and capm.
- Walk through when portfolio theory and capm is the wrong tool and what to use instead.
- Identify how portfolio theory and capm interacts with the order management and risk gates in a US trading stack.
- Articulate a back-of-the-envelope sanity check that proves your implementation of portfolio theory and capm is roughly right.
- Trace which US firms publicly hire against the skills covered in portfolio theory and capm.
- Map a follow-up topic from this knowledge base that deepens portfolio theory and capm.
- Pinpoint how portfolio theory and capm would appear on a phone screen or onsite interview at a US quant shop.