Trading Dev AcademyFree quant education

Free lesson · Linear algebra

Start with lists: addition, scaling and a dot product

Open interactive lessonPractice calculationsExplore labs

Start with the idea

  • A vector is an ordered list of numbers.
  • Match entries by position before combining them.
Symbols, units & horizon
  • a,b: ordered two-entry vectors
  • aᵢ,bᵢ: entries at position i
  • i: position index, 1 or 2
  • Σ: sum over the indicated positions
  • ·: dot product
  • entries: dimensionless in this example

When and why to use this

Use matched weighted sums for portfolio returns and linear predictions. Covariance matrices add relationships between those entries.

  • Scalar: a single number.
  • Use vectors a=(1,2) and b=(3,4).
  • Add matching entries: a+b=(4,6).
  • Multiply every entry by a scalar: 2a=(2,4).
  • A dot product multiplies matching entries and adds the products.
  • A matrix is a rectangular list of such entries. Matrix multiplication repeats dot products.
a⋅b=∑i=12aibi=1×3+2×4=11
Core rule · definition and worked arithmetic

Start with lists: addition, scaling and a dot product

  1. Match the first entries: 1×3=3.
  2. Match the second entries: 2×4=8.
  3. Add the products: 3+8=11. The result is one number, not a vector.
Work it by hand

Weights (.25,.75) and returns (.04,.08) give .25×.04+.75×.08=.07, a 7% weighted return over the same horizon.

Use the rule

  • Name the inputs and units.
  • Work the small example by hand.
  • Check the result before continuing to the next lesson.

Before moving on

Explain the core rule in one sentence, reproduce the worked calculation and solve both practice variations.

Research sources, review dates and limitations

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.

def dot(a,b):
    if not a or len(a)!=len(b): raise ValueError("Matching nonempty vectors required")
    return sum(x*y for x,y in zip(a,b))

print(dot([1,2],[3,4]), dot([.25,.75],[.04,.08]))

Continue learning

Linear Algebra — all lessons
  1. Start with lists: addition, scaling and a dot product
  2. Your portfolio is a vector; your risk is a matrix
  3. Eigenvalues: where the risk actually lives
  4. Regression, conditioning, and regularisation

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