Code & Kapital logoCode & KapitalQuant Research Systems
Portfolio ConstructionApril 7, 20268 min read

Research Article

How to Calculate Portfolio Volatility from the Covariance Matrix

Portfolio volatility is not just a weighted average of standalone asset volatilities. It comes from the full covariance structure of the portfolio.

Final result

wᵀΣw

portfolio variance in matrix form

Key insight

Covariance matters

risk depends on co-movement, not just standalone vol

Use case

Risk foundations

the basis for min variance and mean-variance optimization

By Code & Kapital ResearchApplied research for serious practitioners

Research standard

This article is written from a production-first perspective: assumptions are part of the result, not a footnote.

The emphasis is on failure modes, implementation detail, and why process quality matters more than an elegant historical curve.

What are we actually measuring when we say portfolio risk

Portfolio volatility sounds simple at first, but the quantity being measured is not just the average of individual asset volatilities. Once assets are combined, the risk of the portfolio depends on both how risky each asset is alone and how those assets move together.

That is why the variance of a portfolio is written in matrix form. The expression looks compact, but it encodes the full covariance structure of the portfolio in a way that scalar formulas cannot.

Callout

Portfolio risk is a combination problem

The right question is not just how volatile each asset is. It is how the weighted basket behaves once all pairwise interactions are included.

Step 1: Start from the definition of variance

Begin with the standard definition of variance for the portfolio return Rₚ.

Variance definition

Var(Rₚ) = E[(Rₚ - E[Rₚ])²]

Now substitute the portfolio return as a weighted combination of asset returns, Rₚ = wᵀr.

Substitute the portfolio return

Var(wᵀr) = E[(wᵀr - E[wᵀr])²]

Step 2: Use linearity of expectation

Because weights are constants, expectation passes through the linear combination cleanly.

Linearity of expectation

E[wᵀr] = wᵀE[r]
Var(wᵀr) = E[(wᵀ(r - E[r]))²]

Step 3: Rewrite the squared term

The useful algebraic move is to recognize that a scalar square can be written in quadratic form. Let x = r - E[r]. Then (wᵀx)² = wᵀxxᵀw.

Rewrite the square

(wᵀx)² = wᵀxxᵀw
Var(wᵀr) = E[wᵀ(r - μ)(r - μ)ᵀw]

Step 4: Pull constants outside expectation

The weight vector does not depend on the random return realization, so it can be moved outside the expectation operator.

Pull out the weights

= wᵀ E[(r - μ)(r - μ)ᵀ] w

Step 5: Recognize the covariance matrix

The term inside the expectation is exactly the covariance matrix. That is the bridge from the definition of variance to the compact matrix form used throughout portfolio theory.

Covariance matrix

Σ = E[(r - μ)(r - μ)ᵀ]

Final result

Var(wᵀr) = wᵀΣw

This is the core portfolio variance formula. Taking the square root gives portfolio volatility.

Why this formula matters

The formula shows why portfolio risk cannot be understood asset by asset. The covariance matrix carries the interaction terms, which means correlations directly change total portfolio variance even when individual asset volatilities stay the same.

That is exactly why minimum variance optimization uses wᵀΣw as its objective function, and why inverse volatility can only be understood as a simpler approximation that ignores the off-diagonal covariance structure.

Related article

This is the objective function inside minimum variance

Once portfolio variance is written as wᵀΣw, the minimum variance problem becomes much easier to interpret. The optimizer is simply searching for the weight vector that makes this expression as small as possible.

What the matrix form is really doing

Diagonal terms

Standalone risk

Off-diagonal terms

Co-movement

Result

Total portfolio variance

The compact matrix expression combines asset-level risk and cross-asset interaction risk inside a single quadratic form.

Portfolio volatility is not a property of assets in isolation. It is a property of how the weights and covariances interact.
Code & Kapital Research

From definition to construction

The derivation may look abstract, but it is the foundation for a large share of portfolio construction. Once you understand why portfolio variance equals wᵀΣw, the logic behind diversification, minimum variance weighting, and the efficient frontier becomes much more concrete.

That is the real payoff of the formula. It turns portfolio risk from an intuition into something that can be computed, optimized, and interpreted systematically.

Continue the research

Receive future research and product updates directly.

Join the newsletter for serious commentary on backtesting, data engineering, portfolio construction, and the systems behind robust quant work.

Weekly research notes, product updates, and serious quant commentary.

No spam. Unsubscribe anytime.

Related Research

Continue reading

View research archive