Browse lessons
On this page

Learn · Lesson

Linear Algebra for Finance: Vectors, Replication, Markov Chains, and PCA

Linear algebra studies vectors, linear transformations, and systems of equations. In finance, these become portfolios, scenario payoffs, transition models, and risk factors. The same operation—multiplying a matrix by a vector—can answer “What is my payoff in each state?” or “How does today’s probability distribution evolve?”

Learning goals and notation

You should be able to value a portfolio, solve a replication problem, find a stationary distribution, distinguish eigenvalue decomposition from SVD, and interpret a PCA factor model.

We use column vectors throughout. A superscript ᵀ means transpose: it turns a column into a row. In formulas, xᵀy is the dot product. The letter used for a matrix is less important than its dimensions and meaning; here we use H for payoffs and M for Markov transitions to keep them distinct.

SymbolDimensionsMeaning
p, qn × 1Asset prices and share holdings
Hs × nPayoffs of n assets across s future states
πs × 1Probabilities of Markov states
Σn × nCovariance matrix of asset returns
Γn × nOrthonormal eigenvectors of Σ

1. Vectors: a compact language for portfolios

A vector is an ordered list of numbers. With three stocks, write prices and holdings as:

p = [100, 50, 20]ᵀ
q = [  2, -1,  5]ᵀ

The negative holding means one share is short. The marked value of these stock positions is the dot product:

V = pᵀq = Σⱼ pⱼqⱼ = 100×2 + 50×(−1) + 20×5 = 250.

This is the net value of the listed positions; total account wealth must also include cash, borrowing, and other liabilities. All prices must use a common currency or be converted consistently. A universe of n assets gives p and q in ℝⁿ, with prices usually positive and holdings allowed to have either sign.

Adding vectors combines positions. Multiplying q by 2 doubles every holding and doubles its marked value. These are examples of linearity.

Holdings, weights, and profit are different objects

Share holdings q have units of shares. For a portfolio with nonzero total wealth V, a value weight is wⱼ = pⱼqⱼ/V. If all holdings, including cash and financing, are accounted for consistently, the weights sum to one; short positions can have negative weights. Zero-wealth portfolios cannot be normalized this way.

Choose the timing convention qₜ = holdings selected at time t and held from t to t+1. With no intermediate trading, dividends, fees, or financing costs:

PnLₜ₊₁ = qₜᵀ(pₜ₊₁ − pₜ).

If prices change to [103, 48, 19]ᵀ, the example earns 2×3 + (−1)×(−2) + 5×(−1) = 3. Its stock-position value rises from 250 to 253. The short position earns 2 because its price falls.

Some lecture conventions label the holdings for this interval qₜ₊₁. That notation is valid only if the holdings were chosen before the interval’s price change; using future information would introduce look-ahead bias. Dividends add qₜᵀdₜ₊₁ to the formula, while trading costs and financing require separate terms. Changes in holdings also require a cash ledger; a deposit is not a trading gain.

Long/short and zero-cost portfolios

The difference of holdings q and h is d = q − h. If the original portfolios have equal value at the trade date, pᵀd = 0: their difference is a zero-cost portfolio.

At prices [100, 50]ᵀ, holdings d = [1, −2]ᵀ cost zero. If next-period prices are [105, 54]ᵀ, the payoff is 105 − 2×54 = −3. Zero cost does not mean zero risk or arbitrage. In practice, margin, short-sale restrictions, and borrowing costs can require capital even when the net security cost is zero.

2. Geometry: lengths, projections, and orthogonality

The Euclidean length or norm of v is ‖v‖ = √(vᵀv). For nonzero vectors v and z:

vᵀz = ‖v‖ ‖z‖ cos θ.

If vᵀz = 0, they are orthogonal. For example, [1, 1]ᵀ and [1, −1]ᵀ are perpendicular because 1−1 = 0. A unit vector has length one; divide a nonzero vector by its norm to normalize it.

The projection of v onto a unit direction u is (uᵀv)u. The scalar uᵀv tells you how far v extends along that direction. PCA will use precisely this operation.

Financial interpretation depends on the coordinates. Orthogonal share-holding vectors need not produce uncorrelated returns. If X is a return vector with covariance Σ, the covariance between portfolio returns aᵀX and bᵀX is aᵀΣb, not generally aᵀb. Similarly, the norm of share counts is not an economic risk measure and changes under stock splits.

3. Matrices, span, rank, and linear systems

A matrix is a rectangular array representing a linear transformation. If A is m × n and x is n × 1, then Ax is m × 1. Each output is a row’s dot product with x. Matrix multiplication generally depends on order: AB need not equal BA.

The identity matrix I leaves a vector unchanged. A square matrix is symmetric if Aᵀ = A. It is orthogonal if AᵀA = I, so its inverse is Aᵀ and it preserves lengths and angles.

The span of some vectors is all their linear combinations. They are linearly independent if no nontrivial combination equals zero. A basis is an independent spanning set. The rank of a matrix is the dimension of its column space, equivalently its row space.

To solve Ax = b, ask whether b belongs to the column space of A:

SituationConsequence
b is outside the column spaceNo exact solution
b is inside, and A has independent columnsOne exact solution
b is inside, and A has dependent columnsMultiple exact solutions

The null space consists of vectors z satisfying Az = 0. If x solves Ax = b, then x+z also solves it. For n columns, rank(A) + dimension(null space) = n.

For a square matrix, det(A) ≠ 0 means invertibility, so formally x = A⁻¹b. Numerical software usually solves the system directly rather than explicitly forming an inverse. Near-singular systems can amplify small input errors even when an inverse exists.

4. Scenario matrices and replicating a claim

Consider a one-period economy with trading today and settlement at T. Let Hᵢⱼ be asset j’s total terminal payoff in state i, including any relevant distribution. A payoff matrix can contain zero or negative entries for general contracts; strict positivity is not required for linear algebra.

For holdings q and today’s price vector p₀:

Initial cost = p₀ᵀq; terminal payoff vector = Hq.

A contingent claim C specifies a payment in each state. Replicating it means solving Hq = C.

Worked example: one stock and a risk-free bond

Assume two possible states and no restrictions on borrowing or short selling. The bond costs 1 today and pays 1.05 in either state. The stock costs 100 and pays either 120 or 80, with no dividends. A call with strike 100 pays 20 in the up state and 0 in the down state.

                Bond   Stock       Call
Up state         1.05    120         20
Down state       1.05     80          0

H = [1.05  120]     q = [b]     C = [20]
    [1.05   80]         [h]         [ 0]

Replication requires 1.05b + 120h = 20 and 1.05b + 80h = 0. Subtracting gives 40h = 20, hence h = 0.5. Substitution gives b = −40/1.05 ≈ −38.0952.

Buy half a share and borrow 38.0952. The initial cost is 50 − 38.0952 = 11.9048. At maturity the debt is 40: the net payoff is 60−40 = 20 up, or 40−40 = 0 down. No-arbitrage therefore prices the call at 11.9048 under these assumptions.

5. No-arbitrage, completeness, and risk-neutral pricing

In a frictionless finite-state model where each modeled state has positive physical probability, an arbitrage has nonpositive initial cost and nonnegative terminal payoffs, with a strict benefit somewhere: either strictly negative initial cost or a strictly positive payoff in at least one state. A trade with zero cost and zero payoff everywhere is not arbitrage.

The lecture’s zero-cost/positive-payoff definition is a common special case. A negative-cost trade with zero future liabilities also yields an immediate benefit; with a risk-free account it can be converted into a zero-cost positive future payoff.

State prices connect linear algebra to valuation

A state-price vector s assigns today’s price to one unit paid only in each individual future state. Pricing all traded assets means:

Hᵀs = p₀.

In this finite unconstrained model, absence of arbitrage is equivalent to the existence of a strictly positive state-price vector. Such prices are not physical event probabilities.

Suppose a risk-free account costs 1 and pays R > 0 in every state. Then Σᵢsᵢ = 1/R. Define Qᵢ = Rsᵢ; these positive numbers sum to one. This is a risk-neutral probability measure, and a replicated claim has price:

Price(C) = sᵀC = E_Q[C]/R.

In the example, risk-neutral probabilities solve 100 = [120Qᵤ + 80(1−Qᵤ)]/1.05. Thus Qᵤ = 0.625 and Q_d = 0.375. The call price is (0.625×20 + 0.375×0)/1.05 = 11.9048, matching replication. This does not assert that the real-world up probability is 62.5%.

What completeness means

With s states and n assets, the market is complete when rank(H) = s: every state-payoff vector is in H’s column space. Necessarily n ≥ s. In an arbitrage-free complete model, state prices—and, with the risk-free numeraire, risk-neutral probabilities—are unique.

Completeness does not necessarily make the replicating holdings unique. If there are redundant assets, several portfolios can generate the same payoff. No-arbitrage forces all such portfolios to have the same cost. In an incomplete market, attainable claims still have unique replication prices, but unreplicable claims generally do not have a unique no-arbitrage price.

Incomplete example: a bond paying [1, 1]ᵀ cannot replicate [1, 0]ᵀ. Its payoff matrix has rank one, while there are two states. Merely adding another identical bond does not improve the rank.

6. Eigenvalues: directions a transformation preserves

For a square matrix A, a nonzero vector v is an eigenvector if Av = λv. Along this direction, the transformation scales by λ rather than turning the vector into a different direction. Negative λ reverses direction; eigenvalues may be complex for a general real matrix.

If an n × n matrix has n independent eigenvectors, collect them as columns of S:

A = SΛS⁻¹, where Λ lists the matching eigenvalues.

Then Aᵗ = SΛᵗS⁻¹ for nonnegative integer t. Repeated multiplication becomes repeated scalar powers. Not every square matrix is diagonalizable. A real symmetric matrix always has an orthonormal eigenbasis and can be written A = ΓΛΓᵀ.

7. Markov chains: probabilities through time

A Markov model assumes the next-state distribution depends on the current state rather than the full past. For column probability vectors, choose the convention:

Mᵢⱼ = P(next state i | current state j).

Every entry is nonnegative and every column sums to one. Then πₜ₊₁ = Mπₜ and πₜ = Mᵗπ₀. A row-vector convention instead uses rows summing to one and multiplication on the right; do not mix conventions.

For buy/sell order states, consider:

M = [0.8  0.3]       π₀ = [1]
    [0.2  0.7]            [0]

Starting in buy, the next distribution is [0.8, 0.2]ᵀ. One more step gives [0.70, 0.30]ᵀ. A stationary distribution satisfies Mπ = π** and its entries sum to one. Solving gives π = [0.6, 0.4]ᵀ*: an eigenvector for λ = 1 normalized as probabilities. The other eigenvalue is 0.5, so deviations from stationarity decay by half each step.

A finite chain always has a stationary distribution, but it need not be unique or be the limit from every starting point. Irreducibility gives uniqueness; irreducibility plus aperiodicity gives convergence from every initial distribution. For example, the alternating matrix [[0,1],[1,0]] has stationary probabilities [0.5,0.5]ᵀ but oscillates forever when started entirely in one state.

Perron–Frobenius and financial applications

For a square matrix with every entry strictly positive, Perron–Frobenius gives a positive eigenvalue equal to the spectral radius, strictly larger in modulus than the others. It is simple, and its positive eigenvector is unique up to scale. For a positive stochastic matrix that eigenvalue is 1. Weaker assumptions such as nonnegativity alone do not guarantee strict dominance or convergence.

Credit-rating models use transition matrices for upgrades, downgrades, and default; default is often modeled as absorbing. Order-flow models can describe persistence of buys and sells. These applications require testing the Markov and time-homogeneity assumptions; an empirical transition matrix is an estimate, not a permanent law. See MIT’s Markov matrices lesson.

8. SVD: a decomposition for every rectangular matrix

Any real m × n matrix A has a singular value decomposition:

A = UDVᵀ.

Here U is m × m and V is n × n, both orthogonal; D is m × n with nonnegative singular values σ₁ ≥ σ₂ ≥ … on its diagonal. The number of positive singular values equals rank(A).

The transformation first changes input coordinates with Vᵀ, stretches along singular directions with D, then changes output coordinates with U. Equivalently:

A = Σᵢ₌₁ʳ σᵢuᵢvᵢᵀ, where r = rank(A).

Each term has rank one. Keeping the largest K terms gives a best rank-K approximation in the Frobenius norm (and also in the spectral norm). The discarded squared Frobenius error is Σᵢ>K σᵢ². SVD also supports least-squares solutions and pseudoinverses when a system has no exact solution or is rank-deficient.

EigendecompositionSVD
Applies to square matrices; diagonalization needs enough eigenvectorsExists for any real rectangular matrix
Av = λv uses one coordinate spaceAvᵢ = σᵢuᵢ connects input and output directions
Eigenvalues can be negative or complexSingular values are real and nonnegative

9. Covariance matrices and portfolio risk

Let X be a random vector of n asset returns with finite second moments and mean μ = E[X]. Define:

Σ = E[(X−μ)(X−μ)ᵀ].

Its diagonal entries are variances; off-diagonal entries are covariances. It is symmetric and positive semidefinite (PSD) because for any vector a:

aᵀΣa = Var(aᵀX) ≥ 0.

Consequently its eigenvalues are nonnegative. PSD does not imply invertibility: perfectly dependent return series can produce zero eigenvalues.

For fixed value weights w over one period, the portfolio return is wᵀX and its variance is wᵀΣw. Unlike the Euclidean norm of holdings, this incorporates how assets move together. Volatility is the square root of variance; covariance and variance use squared return units.

10. PCA: rotate into uncorrelated risk directions

Because Σ is symmetric and PSD:

Σ = ΓΛΓᵀ, with ΓᵀΓ = I and λ₁ ≥ … ≥ λₙ ≥ 0.

The columns γᵢ of Γ are principal directions. Project the centered returns onto them to get principal component scores:

z = Γᵀ(X−μ).

Then E[z] = 0 and Cov(z) = ΓᵀΣΓ = Λ. The scores are uncorrelated, with Var(zᵢ) = λᵢ. They are not generally independent; joint Gaussianity is one sufficient condition. Their variances are not automatically one: whitening requires additional scaling and special care with zero eigenvalues.

Worked example: common and relative moves

Suppose the covariance matrix, in decimal-return-squared units, is:

Σ = [0.04  0.03]
    [0.03  0.04]

The eigenpairs are:

  • λ₁ = 0.07, γ₁ = [1,1]ᵀ/√2: a common-movement direction.
  • λ₂ = 0.01, γ₂ = [1,−1]ᵀ/√2: a relative-movement direction.

The first component explains 0.07/(0.07+0.01) = 87.5% of total variance. For a centered observation X−μ = [0.02,0.01]ᵀ, the scores are z₁ ≈ 0.021213 and z₂ ≈ 0.007071.

Keeping only the first direction reconstructs γ₁z₁ = [0.015,0.015]ᵀ. The residual [0.005,−0.005]ᵀ is the relative move that was discarded. Using both directions recovers the observation exactly.

From PCA to a factor model

Partition Γ into the first K columns B = Γ₁ and the remaining columns Γ₂. With f = z₁:K and ε = Γ₂z_K+1:n:

X = μ + Bf + ε.

This equality is exact when the residual is retained; dropping ε gives the low-rank approximation. The residual is orthogonal to the retained directions, and factors and residual are uncorrelated in this covariance construction. Residuals of different assets need not be mutually uncorrelated.

The explained variance ratio of component i is λᵢ/Σⱼλⱼ, and the fraction retained by K components is Σᵢ≤Kλᵢ/Σⱼλⱼ, provided total variance is positive.

For portfolio weights w, component exposures are Γᵀw, so:

Var(wᵀX) = Σᵢ λᵢ(γᵢᵀw)².

Dropping components can understate risk for portfolios exposed to discarded directions. In the two-asset example, w = [1,−1]ᵀ has variance 0.02, entirely in component 2. A model retaining only the 87.5%-explained common component would report zero variance for this spread.

PCA gives statistical factors, not by itself an economic asset-pricing theory or proof of a return premium. Further assumptions are needed to connect factor exposures to expected returns.

Computing PCA from observed data

With T observations in rows and n assets in columns, subtract each column’s sample mean to obtain Z. Using the sample covariance convention:

Σ̂ = ZᵀZ/(T−1).

If Z = UDVᵀ, then V contains the covariance eigenvectors, the sample scores are ZV = UD, and eigenvalues are σᵢ²/(T−1). This links SVD directly to PCA.

Covariance PCA emphasizes high-variance variables. Correlation PCA first standardizes each series, changing the question being asked. Fit means, scales, and components on training data only when evaluating a trading model. Components can change over time; signs are arbitrary, and repeated eigenvalues permit different orthonormal bases of the same eigenspace. See Penn State’s PCA lesson for covariance versus correlation analysis, and CMU’s PCA notes for the distinction between uncorrelated and independent scores.

11. Practice questions

  1. At p = [40,10]ᵀ, what is the cost of q = [2,−3]ᵀ? What is its PnL if prices become [42,9]ᵀ with no cash flows?
  2. Are [1,2]ᵀ and [2,−1]ᵀ orthogonal? Does that imply their portfolio returns are uncorrelated?
  3. Can three assets span every payoff across four states?
  4. In the replication example, what are the holdings and price for a put with strike 100 and payoffs [0,20]ᵀ?
  5. Does a stationary distribution guarantee convergence from every starting state?
  6. A covariance matrix has eigenvalues 9, 3, and 0. What fraction of variance does the first component explain, and what is the rank?
  7. Why might a PCA model with a high explained-variance percentage still miss a portfolio’s main risk?

Answers

  1. Cost 80−30 = 50; PnL 2×2 + (−3)×(−1) = 7.
  2. Yes, their dot product is zero. No: portfolio-return covariance depends on Σ.
  3. No. Rank is at most three, below the four required for completeness.
  4. Subtracting the equations gives stock holding −0.5. Bond holding is 60/1.05 ≈ 57.1429, for initial cost 57.1429−50 = 7.1429. Payoffs are 60−60 = 0 up and 60−40 = 20 down.
  5. No; a periodic chain can oscillate. A finite irreducible, aperiodic chain converges to its unique stationary distribution.
  6. 75%, since 9/12 = 0.75; rank two.
  7. Explained variance is measured across the asset data, while portfolio exposure can concentrate in a discarded low-variance direction.

Further study

  • Dybvig and Ross: Arbitrage, State Prices and Portfolio Theory for the connection between payoff spanning, state prices, and no-arbitrage.
  • MIT: Lecture Notes for Linear Algebra for systems, eigenvalues, covariance, SVD, and stochastic matrices.
  • Rework the two-state replication problem with a different strike and check both terminal payoffs.
  • Estimate a small return covariance matrix, compare covariance and correlation PCA, and measure how much risk a truncated model misses for a long/short portfolio.
Back to Learn