Mathematics13 min read·

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.

Why Matrices Are Not Optional

If calculus is the engine of quant finance, linear algebra is the chassis. You cannot build a portfolio without vectors. You cannot measure risk without a covariance matrix. You cannot decompose risk factors without eigenvalues. And you cannot run a regression without solving a linear system.

The good news is that the linear algebra you need is specific and practical. You do not need to prove that every finite-dimensional vector space has a basis. You need to understand what a matrix multiplication does, why the covariance matrix matters, and what eigenvalues tell you about risk.


Vectors: More Than Arrows

A vector is an ordered list of numbers. In finance, vectors represent:

  • Portfolio weights: ( \mathbf{w} = [0.4, 0.3, 0.2, 0.1] ) — 40% in asset 1, 30% in asset 2, etc.
  • Returns: ( \mathbf{r} = [0.02, -0.01, 0.03, 0.015] ) — daily returns for four assets
  • Factor exposures: how sensitive each asset is to different risk factors

The dot product of two vectors combines them element-wise:

[ \mathbf{w} \cdot \mathbf{r} = \sum_{i=1}^{n} w_i r_i ]

This is your portfolio return — the weighted sum of individual asset returns. One line of maths, and it scales to any number of assets.

In NumPy, this is literally np.dot(weights, returns) or weights @ returns. The notation translates directly to code.


Matrices: Organising Relationships

A matrix is a grid of numbers. The most important matrix in quant finance is the covariance matrix ( \Sigma ), which captures how assets move together:

[ \Sigma = \begin{bmatrix} \sigma_1^2 & \sigma_{12} & \sigma_{13} \ \sigma_{21} & \sigma_2^2 & \sigma_{23} \ \sigma_{31} & \sigma_{32} & \sigma_3^2 \end{bmatrix} ]

  • Diagonal entries: individual asset variances
  • Off-diagonal entries: covariances between pairs of assets

Portfolio Variance

The variance of a portfolio is:

[ \sigma_p^2 = \mathbf{w}^T \Sigma \mathbf{w} ]

This single expression captures the risk of a portfolio of any number of assets, accounting for all correlations. It is why portfolio theory works.

If the assets were uncorrelated (off-diagonal entries zero), portfolio variance would just be the weighted sum of individual variances. But assets are correlated, and those cross-terms determine whether diversification helps or not.


Matrix Operations You Will Use

OperationWhat It DoesFinance Example
Transpose ( A^T )Flip rows and columnsConverting row vectors to columns
Matrix multiply ( AB )Combine transformationsPortfolio variance ( w^T \Sigma w )
Inverse ( A^{-1} )"Undo" a matrixSolving for optimal weights
Determinant (A)

Solving Linear Systems

Many finance problems reduce to solving ( Ax = b ):

  • Regression: finding the best-fit coefficients is ( \hat{\beta} = (X^T X)^{-1} X^T y )
  • Yield curve bootstrapping: solving for zero rates from bond prices
  • Hedging: finding the right combination of instruments to neutralise risk

Eigenvalues and Eigenvectors

An eigenvector of a matrix is a direction that the matrix only stretches (or shrinks), without rotating:

[ A \mathbf{v} = \lambda \mathbf{v} ]

where ( \lambda ) is the eigenvalue — the scaling factor.

Principal Component Analysis (PCA)

PCA finds the eigenvectors of the covariance matrix. They represent the independent directions of risk:

  • First principal component: the direction of maximum variance — for equities, this is usually "the market"
  • Second component: the next most important direction — perhaps "value vs growth"
  • Third and beyond: increasingly minor risk factors

PCA is used extensively in risk management to:

  • Reduce the dimensionality of a large portfolio
  • Identify the main drivers of risk
  • Build factor models
  • Compress yield curve movements into a few factors

The eigenvalues tell you how much variance each component explains. If the first three components explain 95% of variance, you can safely ignore the rest.


The Covariance Matrix in Depth

The covariance matrix deserves special attention because it is genuinely central. It appears in:

  • Portfolio construction: optimal weights depend on ( \Sigma^{-1} )
  • Risk budgeting: decomposing portfolio risk by asset contribution
  • Value at Risk: parametric VaR uses ( \sigma_p = \sqrt{w^T \Sigma w} )
  • Factor models: factor covariance matrices model systematic risk

Positive Definiteness

A valid covariance matrix must be positive semi-definite — all eigenvalues must be non-negative. This ensures portfolio variance is never negative (which would be physically meaningless).

In practice, estimated covariance matrices from noisy data can fail this condition. Fixing them (shrinkage, nearest positive definite matrix) is a real-world problem quants deal with regularly.


Linear Algebra in Python

NumPy was built for this:

import numpy as np # Portfolio of 3 assets weights = np.array([0.5, 0.3, 0.2]) returns = np.array([0.02, -0.01, 0.03]) # Portfolio return port_return = weights @ returns # Covariance matrix (usually estimated from data) cov_matrix = np.array([ [0.04, 0.006, 0.002], [0.006, 0.09, 0.009], [0.002, 0.009, 0.01] ]) # Portfolio variance port_var = weights @ cov_matrix @ weights port_vol = np.sqrt(port_var)

The code is almost identical to the mathematical notation. That direct mapping is one of the reasons Python became the dominant language in quant finance.


Where to Go Next

Linear algebra connects to almost everything else: probability (covariance matrices), statistics (regression), optimisation (portfolio construction), and calculus (gradients as vectors).

Quantt covers all of these connections with interactive modules that let you compute with matrices, visualise eigenvectors, and build real portfolio calculations. The maths and the code work together, just like they do on an actual trading desk.

For additional reading, 3Blue1Brown's Essence of Linear Algebra video series is genuinely the best visual explanation of these concepts anywhere on the internet. Highly recommended.

Want to go deeper on Linear Algebra for Quant Finance: Vectors, Matrices, and Why They Run Everything?

This article covers the essentials, but there's a lot more to learn. Inside Quantt, 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