Linear Algebra for Quantitative Finance › A Complete Example: Minimum Variance Portfolio
Quantitative FinanceAll chapters Linear Algebra for Quantitative Finance › A Complete Example: Minimum Variance PortfolioOne section · Sections in this chapter6 / 9 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Let's bring together the linear algebra concepts to solve a standard portfolio optimization problem: finding the portfolio with minimum variance subject to being fully invested.
The optimization problem is:
subject to:
where is a vector of ones (enforcing that weights sum to 1, meaning the portfolio is fully invested).
This problem asks which portfolio, among all portfolios with net weights summing to 100%, has the smallest variance. The objective function is the quadratic form we encountered earlier, portfolio variance expressed in matrix notation. The equality constraint fixes net investment but still allows short positions and gross leverage. Nonnegative weights, , prohibit shorts and give gross exposure of one under this net budget. A gross-exposure cap above one limits leverage and shorts but does not prohibit them; a cap of one together with the budget equality excludes both.
The following closed form assumes that is symmetric positive definite, so exists and the minimizer is unique. If is singular and merely positive semi-definite, the inverse is undefined and minimizers may be non-unique; use a generalized-inverse, regularized, or constrained formulation instead. Simply replacing the inverse with a pseudoinverse in this normalized expression need not solve the constrained problem. A direction with is a nullspace direction. If its coordinates sum to a nonzero value, normalizing by that sum gives budget-one weights with zero variance. Under the positive-definite assumption, Lagrange multipliers give:
where:
- : the optimal weight vector that minimizes portfolio variance
- : the inverse of the covariance matrix
- The numerator jointly accounts for all variances and covariances; it does not guarantee positive weights or an asset-by-asset ordering
- The denominator normalizes these weights to sum to 1
The appearance of in the solution formula is typical of quadratic optimization with linear constraints. Intuitively, the inverse covariance matrix reweights assets to account for correlation. An asset that seems low-variance in isolation might contribute more risk than expected if it's highly correlated with other holdings. Under the chosen covariance estimate and net-budget constraint, this adjustment identifies the model's unconstrained minimum-variance allocation; estimation error or practical constraints can change the implementable result.
# Find the minimum variance portfolio
ones = np.ones(3)
# Solve Sigma y = 1 without explicitly forming the inverse
unnormalized_weights = np.linalg.solve(sample_cov, ones)
# This uses a matrix factorization internally and avoids an explicit inverse.
# Normalize the solution so the weights sum to one
denominator = ones @ unnormalized_weights
min_var_weights = unnormalized_weights / denominator
# Calculate portfolio statistics
min_var_portfolio_var = min_var_weights @ sample_cov @ min_var_weights
min_var_portfolio_vol = np.sqrt(min_var_portfolio_var) * np.sqrt(252)
# Compare with equal-weight portfolio
equal_weights = np.array([1 / 3, 1 / 3, 1 / 3])
equal_weight_var = equal_weights @ sample_cov @ equal_weights
equal_weight_vol = np.sqrt(equal_weight_var) * np.sqrt(252)Minimum Variance Portfolio: -------------------------------------------------- Optimal weights: Asset 1: 19.59% Asset 2: 61.58% Asset 3: 18.83% Annualized volatility: 21.04% Equal-Weight Portfolio: -------------------------------------------------- Weights: [0.33333333 0.33333333 0.33333333] Annualized volatility: 22.21% Volatility reduction: 1.17 percentage points


The minimum variance portfolio allocates more to lower-volatility assets and uses the covariance relationships in this sample to reduce overall portfolio risk. The implementation solves directly and then normalizes , obtaining the analytical result without explicitly forming . This follows the numerical guidance introduced earlier in the chapter.
Key Parameters
The key parameters for linear algebra operations in quantitative finance are:
- Portfolio weights (w): The fraction of portfolio value allocated to each asset. Must sum to 1 for a fully invested portfolio.
- Covariance matrix (Σ): Captures variance of individual assets (diagonal) and co-movement between assets (off-diagonal). Must be positive semi-definite.
- Eigenvalues (λ): Represent sample variance along each principal direction. Larger eigenvalues identify directions that explain more variance in the fitted covariance model; they do not by themselves establish economic importance.
- Eigenvectors (V): Define principal directions of variation. For covariance matrices, they form orthogonal sample variance directions that analysts may investigate as candidate factor patterns; eigendecomposition alone does not establish economic meaning or stability.
- Condition number: In the 2-norm, the ratio of largest to smallest singular value. For a positive definite covariance matrix, this equals the ratio of its largest to smallest eigenvalue. High values indicate sensitivity in linear solves and inversion.