Skip to content
Finance Lessons

Portfolio Optimization

From Frontier to Weights

Recap of mean-variance theory, the optimization problem in plain terms, the two inputs (expected returns μ and covariance Σ), what a portfolio of weights even is, and what 'solving for the weights' actually means.

11 min Updated Jun 7, 2026

Portfolio theory gave you a gorgeous picture — an efficient frontier curving up and to the left, a tangency portfolio, a capital market line — and then waved its hands at the part that actually matters to a trader: which assets do I buy, and how much of each? That answer is a list of numbers called weights, and producing it from real data is the entire job of portfolio optimization. This lesson nails down the problem precisely: what you’re solving for, what you feed in, and what “optimal” even means once you stop drawing curves and start computing vectors. Everything in this course is an answer to one question — given my beliefs about the assets, what weights should I hold? — so let’s state that question with no hand-waving.

Before you read — take a guess

You've decided on the perfect efficient portfolio from a chart. What concrete object do you actually need to hand your broker to implement it?

What a portfolio actually is: a vector of weights

Analogy. Think of your capital as a pie and each asset as a slice. The recipe for the pie is just the list of slice sizes: 40% stocks, 30% bonds, and so on. That list — one number per asset — is the portfolio. Change the numbers and you have a different portfolio; nothing else about it is fundamental.

Definition. A portfolio of NN assets is a vector of weights w=(w1,w2,,wN),w = (w_1, w_2, \dots, w_N), where wiw_i is the fraction of total capital invested in asset ii. The defining constraint is that the weights sum to one: i=1Nwi=1.\sum_{i=1}^N w_i = 1. That budget constraint says you invest all your money and no more. A weight can be negative — that’s a short position, where you borrow and sell an asset, using the proceeds to buy more of something else (so the longs can sum to more than 100%). A long-only portfolio additionally requires every wi0w_i \ge 0.

Worked example. You have $100,000. You put $60,000 in a stock fund, $30,000 in bonds, and $10,000 in gold. The weights are w=(60000100000,30000100000,10000100000)=(0.6, 0.3, 0.1),w = \left(\tfrac{60\,000}{100\,000}, \tfrac{30\,000}{100\,000}, \tfrac{10\,000}{100\,000}\right) = (0.6,\ 0.3,\ 0.1), and indeed 0.6+0.3+0.1=10.6 + 0.3 + 0.1 = 1. Now suppose instead you short $20,000 of gold and use the cash to buy $120,000 of stock: w=(1.2, 0.0, 0.2)w = (1.2,\ 0.0,\ -0.2), which still sums to one (1.2+00.2=11.2 + 0 - 0.2 = 1). Same budget, very different bet.

A portfolio is a vector of weightsSum of weights: 100%
-50%0%50%100%55%Stocks38%Bonds13%Gold-6%Cash
Defensive: spread out, all longAggressive: concentrated, one short leg

The optimizer hands you one number per asset — the share of capital it gets. They must sum to 100%, but nothing stops a weight from going negative: that is a short position, funding a bigger bet elsewhere. Drag the tilt to see weights swing from a calm, spread-out mix to an aggressive, concentrated one — and watch the sum stay pinned at 100%.

Info:

Why weights, not dollars

Working in weights instead of dollar amounts makes the math scale-free: the optimal mix for $1,000 is the same as for $1,000,000,000. It also lets us add the constraint “weights sum to 1” cleanly, and it’s why every formula in this course is written in ww, not in cash.

A portfolio has weights w = (0.9, 0.5, −0.4) across three assets. Which statement is correct?

The two inputs: expected returns μ and covariance Σ

Every mean-variance optimizer eats exactly two things. Get these wrong and nothing downstream can save you — which is the running theme of this whole course.

Input 1 — expected returns (μ). A vector μ=(μ1,,μN)\mu = (\mu_1, \dots, \mu_N) giving your forecast of each asset’s average future return. This is the reward side. Crucially, these are forecasts — guesses about the future — and they are the hardest thing in finance to estimate accurately.

Input 2 — the covariance matrix (Σ). An N×NN \times N table capturing risk and co-movement. Its diagonal entry Σii=σi2\Sigma_{ii} = \sigma_i^2 is asset ii‘s variance (volatility squared); its off-diagonal entry Σij=σiσjρij\Sigma_{ij} = \sigma_i \sigma_j \rho_{ij} is the covariance between assets ii and jj, where ρij\rho_{ij} is their correlation. This is the risk side, and it encodes the diversification that makes portfolios worth building in the first place.

From these two inputs, the portfolio’s expected return and variance are compact matrix expressions: E[rp]=wμ,Var(rp)=wΣw.\mathbb{E}[r_p] = w^\top \mu, \qquad \mathrm{Var}(r_p) = w^\top \Sigma\, w.

Worked example (two assets). Let μ=(8%, 4%)\mu = (8\%,\ 4\%), with volatilities σ1=20%\sigma_1 = 20\%, σ2=10%\sigma_2 = 10\%, and correlation ρ=0.3\rho = 0.3. The covariance matrix is Σ=(0.2020.200.100.30.200.100.30.102)=(0.040.0060.0060.01).\Sigma = \begin{pmatrix} 0.20^2 & 0.20\cdot 0.10\cdot 0.3 \\ 0.20\cdot 0.10\cdot 0.3 & 0.10^2 \end{pmatrix} = \begin{pmatrix} 0.04 & 0.006 \\ 0.006 & 0.01 \end{pmatrix}. For an equal-weight portfolio w=(0.5,0.5)w = (0.5, 0.5):

  • Expected return: wμ=0.5(8%)+0.5(4%)=6%w^\top \mu = 0.5(8\%) + 0.5(4\%) = 6\%.
  • Variance: wΣw=0.52(0.04)+0.52(0.01)+2(0.5)(0.5)(0.006)=0.01+0.0025+0.003=0.0155w^\top \Sigma w = 0.5^2(0.04) + 0.5^2(0.01) + 2(0.5)(0.5)(0.006) = 0.01 + 0.0025 + 0.003 = 0.0155.
  • Volatility: 0.015512.45%\sqrt{0.0155} \approx 12.45\%.

Notice the volatility (12.45%) is below the simple average of the two asset vols (20%+10%2=15%\tfrac{20\% + 10\%}{2} = 15\%). That gap is diversification, and it lives entirely in the off-diagonal covariance term. If the assets were perfectly correlated (ρ=1\rho = 1), that term would be bigger and the gap would vanish.

The two inputs and what they carry.

Pick the right option for each blank, then check.

Mean-variance optimization needs two inputs: the vector , which carries the reward, and the , which carries the risk and co-movement. The portfolio's expected return is and its variance is .

The optimization problem, stated plainly

Now we can write down what we’re actually solving. Mean-variance optimization comes in a few equivalent flavors, but they all trade off the same two quantities: reward (wμw^\top\mu) and risk (wΣww^\top\Sigma w).

Flavor 1 — minimize risk for a target return. Pick the lowest-variance portfolio that achieves a required expected return rr^*: minw wΣws.t.wμ=r,  1w=1.\min_w\ w^\top \Sigma\, w \quad \text{s.t.}\quad w^\top \mu = r^*,\ \ \mathbf{1}^\top w = 1.

Flavor 2 — maximize the risk–reward trade-off. Maximize a utility that rewards return and penalizes variance, where λ\lambda is your risk aversion: maxw wμλ2wΣws.t.1w=1.\max_w\ w^\top \mu - \tfrac{\lambda}{2}\, w^\top \Sigma\, w \quad \text{s.t.}\quad \mathbf{1}^\top w = 1.

Flavor 3 — maximize the Sharpe ratio. Find the portfolio with the best return per unit of risk (the tangency portfolio): maxw wμrfwΣw.\max_w\ \frac{w^\top \mu - r_f}{\sqrt{w^\top \Sigma\, w}}.

As you sweep the target return rr^* (or the risk aversion λ\lambda) across all values, the solutions trace out the efficient frontier you already know. So “solving for the weights” means: fix what you want (a target, a risk aversion, or the best Sharpe), then find the weight vector that achieves it with no waste.

Each target return picks one efficient weight vector12.9% · 13.0%
Efficient frontierInefficient (dominated)Feasible portfoliosMinimum-variance portfolio
0%4%8%12%16%0%4%8%12%16%20%Risk (volatility)Expected return
Expected return
12.9%
Risk (volatility)
13.0%

Drag the marker up the efficient arc. Each position you stop at corresponds to one target return — and behind that single point sits a whole weight vector the optimizer computed. The leftmost tip is the minimum-variance portfolio; everything inside the cloud is a portfolio you could hold but shouldn't, because something on the frontier dominates it.

Warning:

The catch this whole course is about

Notice all three problems take μ and Σ as if they were known. They are not — they’re estimated from noisy history. Almost every disaster in portfolio optimization traces back to feeding a beautiful exact optimizer with garbage-y, error-laden inputs. Hold that thought; lessons 4–6 are entirely about it.

Match each piece of the optimization setup to what it means.

Pick a term, then click its definition.

What “solving” looks like — and why it’s not just plug-and-play

For the simplest case (no short-sale or box constraints, just the budget constraint), the optimizer has a closed-form solution: a tidy formula involving the inverse of the covariance matrix, Σ1\Sigma^{-1}. You’ll meet it in detail in lesson 3. The key structural fact — and the seed of every problem to come — is that the answer depends on inverting Σ.

Why that matters. Inverting a matrix is exquisitely sensitive to errors when the matrix is ill-conditioned — when some assets are nearly redundant (highly correlated). A near-singular Σ has an inverse with gigantic entries, and those gigantic entries multiply your estimation errors into gigantic, unstable weights. This is the mechanical reason the naive optimizer behaves so badly, and it’s why the back half of this course is devoted to taming Σ (with shrinkage) and constraining ww (with bounds and penalties).

When constraints enter, the closed form usually disappears and you solve numerically with a quadratic program — a standard, fast, reliable optimization routine that handles “weights sum to 1”, “no shorts”, “no more than 5% in any one name”, “turnover below 20%”, and so on, all at once. Real desks almost always run the constrained, numerical version, never the raw closed form.

If the unconstrained problem has a clean formula, why would anyone bother with the slower numerical version?

Because the clean formula will happily hand you a portfolio that is 340% long one stock and 290% short another — mathematically optimal for your (noisy) inputs, operationally insane, and probably illegal for a long-only mandate. The numerical quadratic program lets you bolt on the constraints that keep the answer tradeable: no shorting, position caps, sector limits, a turnover budget, a cap on how far you drift from a benchmark. Those constraints aren’t a compromise of the theory — they’re a crucial defense against estimation error, because they physically prevent the optimizer from taking the extreme positions that estimation noise tempts it into. In practice, sensible constraints often improve out-of-sample performance more than any clever tweak to the inputs. The closed form is a teaching tool and a sanity check; the constrained QP is what actually trades.

Why does the dependence on Σ⁻¹ (the inverse of the covariance matrix) make the naive optimizer fragile?

Putting it together

A portfolio is a vector of weights ww summing to one — negative weights are shorts, all-nonnegative is long-only — and that vector is the concrete thing you trade. A mean-variance optimizer takes two inputs: expected returns μ\mu (reward) and the covariance matrix Σ\Sigma (risk and co-movement), from which E[rp]=wμ\mathbb{E}[r_p] = w^\top\mu and Var(rp)=wΣw\mathrm{Var}(r_p) = w^\top\Sigma w. Solving for the weights means minimizing risk for a target return, maximizing a return-minus-risk utility, or maximizing the Sharpe ratio — and sweeping the target traces the efficient frontier. The clean unconstrained solution depends on Σ1\Sigma^{-1}, which is exactly why a near-singular, error-laden Σ\Sigma makes the naive optimizer fragile — the headline problem this course will diagnose and then fix with constraints and shrinkage.

Big picture

From frontier to weights — the whole picture

  • From frontier to weights
    • A portfolio = weights
      • w = (w1, ..., wN), one per asset
      • Budget: weights sum to 1
      • Negative weight = short; all ≥ 0 = long-only
    • Two inputs
      • mu: expected returns (reward), forecasts
      • Sigma: covariance matrix (risk + co-movement)
      • Return = wᵀμ; Variance = wᵀΣw
    • The problem
      • Min variance for a target return
      • Or max (return − risk penalty)
      • Or max Sharpe (tangency)
      • Sweep target → efficient frontier
    • Solving
      • Unconstrained: closed form via Σ⁻¹
      • Σ⁻¹ amplifies input errors → fragility
      • Constrained: quadratic program
      • Constraints defend against estimation noise
A portfolio is a weight vector; the optimizer turns the two inputs μ and Σ into that vector by trading off reward (wᵀμ) against risk (wᵀΣw).

Recap: from frontier to weights

Question 1 of 40 correct

A two-asset portfolio has weights (0.7, 0.3) and expected returns μ = (10%, 5%). What is the portfolio’s expected return?

Check your answer to continue.

Next up — the covariance matrix itself: how it’s built, why it must be positive semidefinite, how its sheer size explodes with the number of assets, and what “ill-conditioned” really means. Σ is the beating heart of every risk calculation in this course, and understanding its structure is the prerequisite for understanding why optimization is so fragile — and how to fix it.

Mark lesson as complete