Linear Algebra for Quantitative Finance › Vectors in Finance

Michael BrenndoerferOctober 23, 20259 min read
Quantitative FinanceAll chapters
Part 1 of 15Mathematical Foundations
Chapter 5Linear Algebra for Quantitative Finance › Vectors in Finance
Reading section 2 of 9 · Vectors in Finance · 9 minSection 2 of 9 · 9 min

Book contents

Section 2 of 9 · 9 min read

Linear Algebra for Quantitative Finance › Vectors in FinanceOne section · Sections in this chapter2 / 9 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

A vector is an ordered list of numbers. In finance, vectors appear everywhere: asset returns, portfolio weights, and factor exposures. The power of vectors lies in how we can manipulate them mathematically to answer financial questions.

Why do we need vectors rather than simply tracking individual numbers? Consider the alternative: if you manage a portfolio of 500 stocks, you could track 500 separate weight variables and 500 separate return variables. But this approach quickly becomes unwieldy. You'd need to write out 500 terms every time you calculate portfolio return, and any formula involving all assets would span pages. Vectors solve this organizational challenge by packaging related quantities into a single mathematical object that we can manipulate as a unit. This abstraction isn't merely notational convenience; it reveals structure. Operations that require hundreds of scalar terms can be written compactly and evaluated with standard vector routines.

Vector Basics

Consider a portfolio containing three assets. We can represent the weights allocated to each asset as a vector:

w=[w1w2w3]=[0.40.350.25]\mathbf{w} = \begin{bmatrix} w_1 \\ w_2 \\ w_3 \end{bmatrix} = \begin{bmatrix} 0.4 \\ 0.35 \\ 0.25 \end{bmatrix}

where:

  • w\mathbf{w}: the portfolio weight vector
  • wiw_i: the fraction of portfolio value allocated to asset ii

Here w1=0.4w_1 = 0.4 means 40% of the portfolio value is in asset 1. The vector w\mathbf{w} lives in R3\mathbb{R}^3 (three dimensional real space) because it has three components. Geometrically, each asset corresponds to an axis, and the weight vector points to a specific location in this three-dimensional "asset space." Every possible portfolio allocation corresponds to some point in this space. Portfolio constraints, like requiring weights to sum to one, define surfaces or regions within it.

Similarly, we can represent the returns of these three assets on a given day:

r=[r1r2r3]=[0.02−0.010.015]\mathbf{r} = \begin{bmatrix} r_1 \\ r_2 \\ r_3 \end{bmatrix} = \begin{bmatrix} 0.02 \\ -0.01 \\ 0.015 \end{bmatrix}

where:

  • r\mathbf{r}: the return vector for a single time period
  • rir_i: the return of asset ii (expressed as a decimal, so 0.02 = 2%)

This says asset 1 returned 2%, asset 2 lost 1%, and asset 3 gained 1.5%. Notice how naturally this representation captures a snapshot of market behavior: all three returns belong together because they occurred simultaneously, and the vector keeps them organized as a coherent unit.

Vector Operations

The fundamental vector operations translate directly into financial calculations:

Scalar multiplication scales every element by a constant. If you double your position in everything:

2w=[0.80.70.5]2\mathbf{w} = \begin{bmatrix} 0.8 \\ 0.7 \\ 0.5 \end{bmatrix}

Geometrically, multiplication by a positive scalar stretches or shrinks a nonzero vector without changing its direction. A negative scalar reverses its orientation, and zero maps it to the zero vector. Financially, scaling risky-asset weights by a positive factor preserves their relative allocations while changing exposure relative to the same equity base. Doubling the weights above gives 200% risky-asset exposure, which requires a cash or borrowing weight of -100% to keep net weights summing to one. The gross linear gains and losses from those assets double; the total portfolio return also includes financing and trading costs. Doubling both the positions and the capital instead leaves the normalized weights unchanged.

Vector addition combines vectors element-wise. If r1\mathbf{r}_1 and r2\mathbf{r}_2 are returns on consecutive days:

r1+r2=[r1,1+r1,2r2,1+r2,2r3,1+r3,2]\mathbf{r}_1 + \mathbf{r}_2 = \begin{bmatrix} r_{1,1} + r_{1,2} \\ r_{2,1} + r_{2,2} \\ r_{3,1} + r_{3,2} \end{bmatrix}

where ri,tr_{i,t} denotes the return of asset ii on day tt.

For small returns, this approximates cumulative returns (the exact formula uses geometric compounding). Vector addition also models combining different portfolios. If two funds with values C1C_1 and C2C_2 are combined at the same valuation time, their combined weight vector is exactly (C1w(1)+C2w(2))/(C1+C2)(C_1\mathbf{w}^{(1)}+C_2\mathbf{w}^{(2)})/(C_1+C_2) before transaction costs or other value changes. The numerator adds the allocated amounts in each asset; dividing by the total capital converts those amounts back into weights. Equal capital contributions give the average of the two weight vectors, not their unscaled sum.

The Dot Product: Portfolio Returns

The dot product (or inner product) of two vectors is the sum of the products of corresponding elements:

w⋅r=w1r1+w2r2+w3r3=∑i=1nwiri\mathbf{w} \cdot \mathbf{r} = w_1 r_1 + w_2 r_2 + w_3 r_3 = \sum_{i=1}^{n} w_i r_i

where:

  • nn: the number of assets in the portfolio.

This single number is the one-period portfolio simple return when w\mathbf{w} contains beginning-of-period weights, r\mathbf{r} contains same-period simple returns, the weights sum to one, and there are no intra-period cash flows or trading costs. It is not generally the exact portfolio log return when r\mathbf{r} contains log returns. Each asset contributes to the simple return in proportion to both its individual simple return and the fraction of beginning capital allocated to it. The dot product sums these contributions.

Why does this work? Consider a $1 portfolio allocated at the beginning of the period and held without intra-period rebalancing. The amount invested in asset 1 is \w_1,andthisgrowsto, and this grows to $w_1(1 + r_1).Similarlyforeachasset.Withnocashflowsortradingcosts,theendingvalueis. Similarly for each asset. With no cash flows or trading costs, the ending value is $\sum w_i(1 + r_i) = $(\sum w_i + \sum w_i r_i).Sincethefullyinvestedweightssumto1,thisequals. Since the fully invested weights sum to 1, this equals $(1 + \sum w_i r_i),confirmingtheone−periodsimplereturn, confirming the one-period simple return \mathbf{w} \cdot \mathbf{r}$. Portfolios with borrowing or short positions must include their cash or financing leg, and a new period uses the weights prevailing at that period's start.

In[3]:
Code
import numpy as np

# Portfolio weights (must sum to 1 for a fully invested portfolio)
weights = np.array([0.4, 0.35, 0.25])

# Daily returns for three assets
returns = np.array([0.02, -0.01, 0.015])

# Portfolio return is the dot product
portfolio_return = np.dot(weights, returns)
Out[4]:
Console
Asset weights: [0.4  0.35 0.25]
Asset returns: [ 0.02  -0.01   0.015]
Portfolio return: 0.0083 (0.83%)

Calculation: 0.4×0.02 + 0.35×(-0.01) + 0.25×0.015 = 0.0083
Out[5]:
Visualization
Bar chart of three weighted simple-return contributions, with positive contributions in green and negative in red, and a dashed line marking the total one-period portfolio simple return.
One-period portfolio simple return as the sum of beginning weights times same-period asset simple returns. Each bar shows one asset's contribution under the fully invested, no-cash-flow example.

The portfolio earned a 0.83% simple return by beginning the period with 40% in the 2% gainer, 35% in the 1% loser, and 25% in the 1.5% gainer. Under the conditions stated above, this dot product aggregates the asset simple returns into the one-period portfolio simple return.

Vector Norms: Measuring Size

The norm of a vector measures its "size" in various ways. But what does "size" mean for a vector? There's no single answer. Different norms capture different notions of magnitude, each useful in different contexts. The Euclidean norm (or L2 norm) is:

∥v∥2=∑i=1nvi2\|\mathbf{v}\|_2 = \sqrt{\sum_{i=1}^{n} v_i^2}

where:

  • ∥v∥2\|\mathbf{v}\|_2: the L2 (Euclidean) norm of vector v\mathbf{v}
  • viv_i: the ii-th component of the vector
  • nn: the dimension of the vector

The Euclidean norm corresponds to our intuitive notion of distance: it's the straight-line distance from the origin to the point represented by the vector. To connect it to volatility, consider TT daily returns of one asset and first subtract their mean. The L2 norm of that centered vector divided by T\sqrt{T} gives the descriptive standard deviation; dividing by T−1\sqrt{T-1}, for T>1T>1, gives the sample standard deviation. A vector of simultaneous returns across different assets describes a cross-section instead, not a portfolio's time-series volatility.

The L1 norm sums absolute values:

∥v∥1=∑i=1n∣vi∣\|\mathbf{v}\|_1 = \sum_{i=1}^{n} |v_i|

The L1 norm measures total "travel distance" if you could only move along coordinate axes, like navigating a city grid where you can only travel along streets, not diagonally through blocks. In portfolio optimization, an L1 penalty can promote sparse positions when weights may take either sign or when the budget does not already fix their L1 norm. For a long-only, fully invested portfolio, however, ∥w∥1=∑iwi=1\|\mathbf{w}\|_1 = \sum_i w_i = 1, so an L1 penalty alone cannot select a sparser portfolio. An L2 penalty can discourage concentrated weights under a specified objective and constraints, but it does not guarantee an evenly spread allocation.

In[6]:
Code
# Five daily simple returns of one asset
returns_vector = np.array([0.02, -0.01, 0.015, -0.005, 0.01])

l2_norm = np.linalg.norm(returns_vector, ord=2)  # Euclidean norm
l1_norm = np.linalg.norm(returns_vector, ord=1)  # Sum of absolute values
linf_norm = np.linalg.norm(returns_vector, ord=np.inf)  # Max absolute value
Out[7]:
Console
Return vector: [ 0.02  -0.01   0.015 -0.005  0.01 ]
L2 norm: 0.029155
L1 norm: 0.060000
L∞ norm (max absolute): 0.020000

The L2 norm of 0.029 represents the Euclidean magnitude of these five raw returns, not their standard deviation. Centering and normalizing as described above is necessary for a volatility measure: even constant nonzero returns have a positive raw norm but zero standard deviation. The L1 norm of 0.06 sums absolute returns and can support sparsity-inducing penalties when the surrounding constraints do not make it constant. The L∞ norm of 0.02 identifies the largest absolute return, which shows the most extreme daily movement.