MatheLinuxMatheLinux
Curriculum
Sign inStart free
Linear Algebra & Optimization for Quants
0%

0 of 18 lessons complete

Lessons

  • Vectors, Dot Products & Norms8m
  • Matrices & Matrix Multiplication8m
  • Linear Systems & Gaussian Elimination8m
  • Inverses & Determinants8m
  • Vector Spaces, Span, Basis & Rank8m
  • Eigenvalues & Eigenvectors8m
  • Diagonalization & Symmetric Matrices8m
  • Quadratic Forms & Positive Definiteness8m
  • The Singular Value Decomposition8m
  • Covariance & Correlation Matrices8m
  • Principal Component Analysis8m
  • Orthogonality & Projections8m
  • Least Squares & the Normal Equations8m
  • Linear Regression & Factor Models8m
  • Convex Sets & Functions8m
  • Gradients & First-Order Conditions8m
  • Constrained Optimization & Lagrange Multipliers8m
  • Mean-Variance Portfolio Optimization8m

MatheLinux — quantitative finance, taught rigorously.

Course content credited to Ibrahim Lanre Adedimeji.

← Linear Algebra & Optimization for Quants

A vector is the most basic object in quantitative finance. When you hold a portfolio of three assets in proportions 50 percent, 30 percent, and 20 percent, you are really holding the vector w=(0.5,0.3,0.2)w = (0.5, 0.3, 0.2)w=(0.5,0.3,0.2). Almost everything that follows in this course is a manipulation of vectors and the matrices that act on them, so we start here.

Vectors in R-n

Formally, the space Rn\mathbb{R}^nRn is the set of all ordered lists of nnn real numbers. A typical element is written

x=(x1,

Knowledge check

Q1. For vectors x and y in R-n, the dot product x dot y equals:

Q2. Two nonzero vectors are orthogonal exactly when:

Q3. The Euclidean norm of a vector x is defined as:

Q4. If a portfolio has weights w and assets have expected returns mu, the expected portfolio return is:

Problems

P1

Let x = (1, 2, 2) and y = (2, 0, 1). Compute cos(theta), the cosine of the angle between them. Give the answer as a decimal.

P2

For a portfolio with weight vector w = (w1, w2) and asset return vector r = (r1, r2), write the portfolio return as a dot product and state the general formula for n assets.

Mark this lesson complete to track progress
x2,…,xn),xi∈R.x = (x_1, x_2, \dots, x_n), \qquad x_i \in \mathbb{R}.
x=(x1​,x2​,…,xn​),xi​∈R.

We think of xxx as an arrow from the origin to the point with those coordinates, or simply as a column of numbers. The number xix_ixi​ is the iii-th component. In finance nnn might be the number of assets, the number of risk factors, or the number of dates in a return series.

Addition and scaling

Two vectors of the same length add component by component, and a scalar c∈Rc \in \mathbb{R}c∈R scales every component:

x+y=(x1+y1,…,xn+yn),c x=(c x1,…,c xn).x + y = (x_1 + y_1, \dots, x_n + y_n), \qquad c\,x = (c\,x_1, \dots, c\,x_n).x+y=(x1​+y1​,…,xn​+yn​),cx=(cx1​,…,cxn​).

These two operations make Rn\mathbb{R}^nRn a vector space. Combining them gives a linear combination a x+b ya\,x + b\,yax+by, the workhorse expression of the whole subject. A portfolio return is exactly such a combination: if assets have returns r1,r2,r3r_1, r_2, r_3r1​,r2​,r3​ and weights w1,w2,w3w_1, w_2, w_3w1​,w2​,w3​, the portfolio return is w1r1+w2r2+w3r3w_1 r_1 + w_2 r_2 + w_3 r_3w1​r1​+w2​r2​.

The dot product

The dot product (or inner product) of two vectors in Rn\mathbb{R}^nRn is the single number

x⋅y=∑i=1nxi yi=x1y1+x2y2+⋯+xnyn.x \cdot y = \sum_{i=1}^{n} x_i\, y_i = x_1 y_1 + x_2 y_2 + \dots + x_n y_n.x⋅y=∑i=1n​xi​yi​=x1​y1​+x2​y2​+⋯+xn​yn​.

It is symmetric, x⋅y=y⋅xx \cdot y = y \cdot xx⋅y=y⋅x, and linear in each argument. The portfolio return above is precisely the dot product w⋅rw \cdot rw⋅r, which is why dot products are everywhere in finance: they collapse a weighted bet across many assets into one expected payoff.

The Euclidean norm

The Euclidean norm (length) of a vector is defined through its own dot product:

∥x∥=x⋅x=∑i=1nxi2.\lVert x \rVert = \sqrt{x \cdot x} = \sqrt{\sum_{i=1}^{n} x_i^2}.∥x∥=x⋅x​=∑i=1n​xi2​​.

For n=2n = 2n=2 this is just the Pythagorean theorem. A unit vector has norm 111; we normalize any nonzero xxx by dividing by its norm, x^=x/∥x∥\hat{x} = x / \lVert x \rVertx^=x/∥x∥.

The angle and cosine formula

The dot product and the norm are tied together by the geometric identity

x⋅y=∥x∥ ∥y∥cos⁡θ,x \cdot y = \lVert x \rVert\,\lVert y \rVert \cos\theta,x⋅y=∥x∥∥y∥cosθ,

where θ\thetaθ is the angle between the two vectors. Solving for the angle gives the cosine formula

cos⁡θ=x⋅y∥x∥ ∥y∥.\cos\theta = \frac{x \cdot y}{\lVert x \rVert\,\lVert y \rVert}.cosθ=∥x∥∥y∥x⋅y​.

Derivation

Apply the law of cosines to the triangle whose two sides are xxx and yyy and whose third side is the difference x−yx - yx−y:

∥x−y∥2=∥x∥2+∥y∥2−2 ∥x∥ ∥y∥cos⁡θ.\lVert x - y \rVert^2 = \lVert x \rVert^2 + \lVert y \rVert^2 - 2\,\lVert x \rVert\,\lVert y \rVert \cos\theta.∥x−y∥2=∥x∥2+∥y∥2−2∥x∥∥y∥cosθ.

Now expand the left side algebraically using the definition of the norm:

∥x−y∥2=(x−y)⋅(x−y)=x⋅x−2 x⋅y+y⋅y=∥x∥2−2 x⋅y+∥y∥2.\lVert x - y \rVert^2 = (x - y)\cdot(x - y) = x\cdot x - 2\,x\cdot y + y\cdot y = \lVert x \rVert^2 - 2\,x\cdot y + \lVert y \rVert^2.∥x−y∥2=(x−y)⋅(x−y)=x⋅x−2x⋅y+y⋅y=∥x∥2−2x⋅y+∥y∥2.

Setting the two expressions equal, the ∥x∥2\lVert x \rVert^2∥x∥2 and ∥y∥2\lVert y \rVert^2∥y∥2 terms cancel, leaving −2 x⋅y=−2 ∥x∥ ∥y∥cos⁡θ-2\,x\cdot y = -2\,\lVert x \rVert\,\lVert y \rVert\cos\theta−2x⋅y=−2∥x∥∥y∥cosθ. Dividing by −2-2−2 yields x⋅y=∥x∥ ∥y∥cos⁡θx\cdot y = \lVert x \rVert\,\lVert y \rVert\cos\thetax⋅y=∥x∥∥y∥cosθ, exactly the identity above.

Orthogonality

When θ=90\theta = 90θ=90 degrees, cos⁡θ=0\cos\theta = 0cosθ=0, so x⋅y=0x \cdot y = 0x⋅y=0. Two vectors are orthogonal precisely when their dot product is zero. In finance, orthogonal return streams are uncorrelated bets that diversify each other, which is the mathematical heart of risk reduction.

Worked numeric example

Let x=(3,4)x = (3, 4)x=(3,4) and y=(4,3)y = (4, 3)y=(4,3). First the dot product:

x⋅y=(3)(4)+(4)(3)=12+12=24.x \cdot y = (3)(4) + (4)(3) = 12 + 12 = 24.x⋅y=(3)(4)+(4)(3)=12+12=24.

The norms:

∥x∥=32+42=25=5,∥y∥=42+32=25=5.\lVert x \rVert = \sqrt{3^2 + 4^2} = \sqrt{25} = 5, \qquad \lVert y \rVert = \sqrt{4^2 + 3^2} = \sqrt{25} = 5.∥x∥=32+42​=25​=5,∥y∥=42+32​=25​=5.

The cosine of the angle:

cos⁡θ=24(5)(5)=2425=0.96.\cos\theta = \frac{24}{(5)(5)} = \frac{24}{25} = 0.96.cosθ=(5)(5)24​=2524​=0.96.

So θ=arccos⁡(0.96)≈16.26\theta = \arccos(0.96) \approx 16.26θ=arccos(0.96)≈16.26 degrees. The vectors point in nearly the same direction, consistent with a high cosine. As a sanity check, z=(4,−3)z = (4, -3)z=(4,−3) gives x⋅z=(3)(4)+(4)(−3)=12−12=0x \cdot z = (3)(4) + (4)(-3) = 12 - 12 = 0x⋅z=(3)(4)+(4)(−3)=12−12=0, so xxx and zzz are orthogonal.

Why quants care

A portfolio is a weight vector www, expected returns form a vector μ\muμ, and the expected portfolio return is the dot product w⋅μw \cdot \muw⋅μ. The cosine formula reappears as the correlation between two return series, and orthogonality is the formal statement that two strategies are uncorrelated. Norms measure the size of a position or the magnitude of a return, and they underlie the risk and tracking-error metrics you will meet later. Mastering these three operations, addition, the dot product, and the norm, gives you the language in which every later model is written.

Adapted from MIT OpenCourseWare (18.06 Linear Algebra / 6.255 Optimization), CC BY-NC-SA.

+
w3​r3​