Markowitz Mean-Variance Portfolio
How should capital be allocated across $n$ risky assets to balance expected return and variance? Markowitz (1952) recast this as a quadratic program: minimise portfolio variance subject to a target return, a budget constraint, and no short-selling. Sixty years of finance-OR literature has extended the model — CVaR, robust, multi-period, factor-based — but the single-period mean-variance program remains the canonical entry point.
Related sub-applications: CVaR Portfolio (Rockafellar-Uryasev), Robust Portfolio (Goldfarb-Iyengar), Value at Risk & ES.
The Problem
Balancing expected return against portfolio risk
Given $n$ risky assets with expected-return vector $\mu \in \mathbb{R}^n$ and covariance matrix $\Sigma \in \mathbb{R}^{n\times n}$ (symmetric, positive semidefinite), choose portfolio weights $w \in \mathbb{R}^n$ to maximise expected return while controlling variance. Markowitz (1952) posed this as a quadratic program. The utility-penalised form used in this demo is:
(2) $w_i \ge 0 \;\forall i$ — no short-selling (long-only).
(3) $\lambda \ge 0$ — risk-aversion parameter; sweeping $\lambda \in [\lambda_{\min}, \lambda_{\max}]$ traces out the efficient frontier in $(\sigma, \mathbb{E}[r])$ space.
High $\lambda$ produces conservative, diversified portfolios; low $\lambda$ concentrates on the highest-return assets. The solution is unique when $\Sigma$ is positive definite. Probabilities are taken under the physical measure $\mathbb{P}$ — this is a decision problem, not a pricing problem (contrast with Black-Scholes, which operates under the risk-neutral measure $\mathbb{Q}$).
Assumptions & Limitations
What this model assumes — and when those assumptions break
Explicit modelling assumptions
- Single period. One decision horizon; no rebalancing, no dynamic trading. Multi-period portfolio choice requires Merton-style continuous-time or multi-stage stochastic programming.
- Known $\mu$ and $\Sigma$. Both are assumed known with certainty. In practice they are estimated from historical data and carry substantial error — the reason robust (Goldfarb-Iyengar) and Bayesian (Black-Litterman) variants exist.
- Variance is a sufficient risk measure. Equivalent to Gaussian returns, or quadratic utility. Fat-tailed loss distributions are not captured — CVaR / Expected Shortfall addresses this explicitly.
- Stationarity. $\mu$ and $\Sigma$ are constant over the horizon. Real returns exhibit volatility clustering (GARCH), regime shifts, and non-stationarity.
- No transaction costs. No bid-ask spreads, commissions, market impact, or taxes. Real portfolios face 10-50 bps round-trip costs that make frequent rebalancing expensive.
- No short-selling. $w_i \ge 0$ is a constraint. Dropping it (allowing $w_i < 0$) yields the unconstrained mean-variance frontier with closed-form solution $w^* \propto \Sigma^{-1}(\mu - \gamma \mathbf{1})$.
- Continuous, infinitely divisible weights. No lot sizes, no cardinality constraints. Cardinality-constrained variants ($|\{i : w_i > 0\}| \le K$) are MIQPs and NP-hard.
- No leverage. $\mathbf{1}^\top w = 1$ prevents borrowing. Real portfolios may use leverage up to regulatory limits (Reg T, Basel).
The "Markowitz enigma" (Michaud, 1989). Because $\mu$ is notoriously hard to estimate, a Markowitz solver that takes historical means at face value will produce portfolios that are extreme, highly concentrated, and unstable under small re-estimations of $\mu$. This pathology motivates robust optimisation (Ben-Tal & Nemirovski 1998; Goldfarb & Iyengar 2003), Black-Litterman shrinkage, and resampled frontiers — separate sub-applications on this site.
Try It Yourself
Edit assets, returns, and covariance — then compare optimization methods
Portfolio Optimizer
4 Assets · λ = 2.0| Name | Return (%) |
|---|
| Algorithm | E[Return] | Std Dev | Sharpe | Time |
|---|
Reading the Results
Business terms ↔ math symbols, and the definitions behind the KPIs
Real-world ↔ model mapping
| On the desk | In the model |
|---|---|
| Share of capital put into asset $i$ | $w_i$ |
| Annualised expected return of asset $i$ | $\mu_i$ |
| Covariance of asset $i$ and $j$ returns | $\Sigma_{ij}$ |
| Portfolio’s expected annual return | $\mathbb{E}[r_p] = \mu^\top w$ |
| Portfolio’s annual variance | $\sigma_p^2 = w^\top \Sigma w$ |
| Portfolio standard deviation (“risk”) | $\sigma_p = \sqrt{w^\top \Sigma w}$ |
| How aggressively the investor trades return for risk | $\lambda$ |
| “Fully invested” budget line | $\mathbf{1}^\top w = 1$ |
| Long-only constraint | $w_i \ge 0$ |
Definitions of the reported KPIs
- E[Return] — portfolio expected return $\mathbb{E}[r_p] = \mu^\top w$ under the physical measure $\mathbb{P}$.
- Std Dev ($\sigma_p$) — portfolio standard deviation $\sqrt{w^\top \Sigma w}$. This is the iconic risk axis on an efficient-frontier plot.
- Sharpe ratio — risk-adjusted return $\displaystyle S = \frac{\mathbb{E}[r_p] - r_f}{\sigma_p}$ — Sharpe (1966, 1994). This page uses the demo convention $r_f = 0$, so the displayed Sharpe is simply $\mathbb{E}[r_p] / \sigma_p$. A real benchmark would subtract an appropriate risk-free rate. Sharpe is not the only performance metric — see Sortino (downside std only), Treynor (beta-scaled), Information ratio (vs benchmark), and Calmar (return/drawdown).
- Time — wall-clock solve time for the algorithm, in ms. Pedagogical only; real solvers (Mosek, Gurobi, HiGHS, CVXPY) are far faster on problems of this size.
- # Assets (in the weights panel) — count of $w_i > 0.005$, i.e. positions with meaningful capital. A "diversified" portfolio keeps this close to $n$; a concentrated one shrinks it toward 1.
The Algorithms
From naive heuristics to quadratic programming
Equal Weight (1/n)
HeuristicAllocate equally across all assets. Despite its simplicity, the 1/n rule is often surprisingly competitive due to diversification benefits and avoidance of estimation error in returns and covariances.
Minimum Variance
HeuristicFind the portfolio with lowest variance, ignoring expected returns entirely. For the unconstrained case (allowing negative weights), the closed-form is w = Σ-11 / (1TΣ-11). With non-negativity constraints, we use projected gradient descent.
Maximum Return
HeuristicConcentrate 100% of capital in the single asset with the highest expected return. This is the most aggressive strategy with zero diversification — maximum return but also maximum concentration risk.
Mean-Variance QP
ExactSolve the full Markowitz objective max μTw − λ·wTΣw using projected gradient descent. The gradient ∇f = μ − 2λΣw is projected onto the probability simplex after each step. Converges to the global optimum since the objective is concave.
Real-World Complexity
Why production portfolio optimization goes far beyond this demo
Beyond Mean-Variance
- Transaction costs — bid-ask spreads and commissions make frequent rebalancing expensive; turnover constraints are essential
- Tax implications — capital gains taxes create path-dependent optimization; tax-loss harvesting adds integer variables
- Liquidity constraints — large positions cannot be liquidated instantly; market impact models are needed
- Thousands of assets — institutional portfolios span thousands of securities; covariance estimation requires factor models
- Dynamic rebalancing — multi-period stochastic optimization replaces single-period Markowitz in practice
- Factor models — Fama-French, APT, and statistical factor models reduce dimensionality and improve estimation
- ESG constraints — environmental, social, and governance screens add exclusion and tilt constraints
- Tail risk (CVaR) — variance fails to capture fat tails; Conditional Value-at-Risk provides asymmetric risk measures
Key References
Foundational papers in portfolio theory
- (1952). “Portfolio Selection.” The Journal of Finance, 7(1), 77–91. doi:10.1111/j.1540-6261.1952.tb01525.x The founding paper of modern portfolio theory. Casts asset allocation as a quadratic program with $\mu$ and $\Sigma$.
- (1966). “Mutual Fund Performance.” The Journal of Business, 39(1), 119–138. doi:10.1086/294846 Introduces the reward-to-variability ratio, today called the Sharpe ratio.
- (1994). “The Sharpe Ratio.” The Journal of Portfolio Management, 21(1), 49–58. doi:10.3905/jpm.1994.409501 Revised formulation clarifying the ex-ante vs ex-post distinction and proper use of the ratio.
- (1989). “The Markowitz Optimization Enigma: Is ‘Optimized’ Optimal?” Financial Analysts Journal, 45(1), 31–42. doi:10.2469/faj.v45.n1.31 The canonical statement of the estimation-error problem that motivates robust and Bayesian variants.
- (1998). “Robust Convex Optimization.” Mathematics of Operations Research, 23(4), 769–805. doi:10.1287/moor.23.4.769 Foundational theory of robust optimisation, later applied directly to portfolio problems.
- (2003). “Robust Portfolio Selection Problems.” Mathematics of Operations Research, 28(1), 1–38. doi:10.1287/moor.28.1.1.14260 Ellipsoidal and polyhedral uncertainty sets on $\mu$ and $\Sigma$; SOCP reformulation. Basis of this site’s robust-portfolio sub-application.
- (2000). “Optimization of Conditional Value-at-Risk.” Journal of Risk, 2(3), 21–41. doi:10.21314/JOR.2000.038 Replaces variance with the coherent Conditional Value-at-Risk measure; LP reformulation under scenarios. See the CVaR-portfolio sub-application.
- (2007). Robust Portfolio Optimization and Management. Wiley. ISBN 978-0-471-92122-6. Practitioner-level reference covering robust, Bayesian, and resampled approaches to the Markowitz enigma.
- (2007). Optimization Methods in Finance. Cambridge University Press. ISBN 978-0-521-86170-2. OR-first treatment of portfolio optimisation, including QP, SOCP, and SDP formulations with CPLEX / Mosek walkthroughs.
- (1998). Investment Science. Oxford University Press. ISBN 978-0-19-510809-5. Classic textbook covering mean-variance theory, CAPM, arbitrage pricing, and related topics at graduate level.
Related sub-applications
This page covers the single-period Markowitz mean-variance programme. Close cousins within the Finance & Insurance domain pick up where it leaves off — addressing fat tails, estimation error, and risk-measurement under coherent axioms.