Trading Dev AcademyFree quant education

Free lesson · Math & notation

Vectors, matrices and transpose notation

Open interactive lessonPractice calculationsExplore labs

Start with the idea

Write a two-asset example explicitly. Once the dimensions and signs work there, vector notation lets the same operations scale to a larger book.

Symbols, units & horizon
  • w: ordered vector of signed capital weights
  • r: matching decimal return vector
  • T: transpose, not elapsed time here
  • Σ: covariance matrix in squared return units
  • Σᵢⱼ: covariance of assets i and j
  • Σ with limits: summation rather than the matrix name
  • i, j: asset indices

When and why to use this

Use a dot product for return and a quadratic form for variance. This is the bridge between arithmetic and portfolio models.

A vector is an ordered list. A portfolio’s weights form one vector and the assets’ returns form another. A matrix is a rectangular table; a covariance matrix records a relationship for each pair of assets. Superscript T or ⊤ means transpose: swap rows and columns.

wTr=∑iwiri,wTΣw=∑i∑jwiwjΣij
Algebra and arithmetic

Multiply two-vector and two-matrix expressions

  1. For w=(w₁,w₂), r=(r₁,r₂), wTr=w1r1+w2r2.
  2. First calculate Σw, then take the dot product with w. Expanding a symmetric two-by-two matrix gives w12Σ11+2w1w2Σ12+w22Σ22.
Work it by hand

w=(.5,.5), r=(.02,−.01) gives return .005. With diagonal covariance (.01,.04) and zero covariance, variance=.0125.

Capital Σ in this context is a matrix, while Σ with limits can be a summation symbol. The entry Σᵢⱼ is row i, column j. Matrix multiplication is ordered: multiply matching coordinates and add. The superscript −1 on a matrix means its inverse, if one exists, not taking each entry’s reciprocal.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

# Dependency: numpy. Asset ordering must match in all arrays.
import numpy as np

def portfolio_moments(weights, returns, covariance):
    w, r, cov = map(np.asarray, (weights, returns, covariance))
    return float(w @ r), float(w @ cov @ w)

print(portfolio_moments([.5, .5], [.02, -.01], [[.01, 0], [0, .04]]))

Continue learning

Math & Notation Essentials — all lessons
  1. Start with numbers, variables and an equals sign
  2. Percentages, basis points and units
  3. Rearrange an equation without changing its meaning
  4. Powers, square roots, exponentials and logarithms
  5. Read sums, indices, averages and squared deviations
  6. Probability, expectation and conditioning
  7. Vectors, matrices and transpose notation
  8. Derivatives, integrals and approximations

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations