liveBook · Manning

Matrix-matrix multiplication

As explained in Build a Robo-Advisor with Python (From Scratch)

Matrix multiplication is an algebraic operation that combines rows of one matrix with columns of another to produce a new matrix or vector.

Matrix multiplication combines portfolio weights, asset returns, volatilities, and correlations into compact calculations. It replaces explicit summations and double summations with readable, efficient operations. section 2.2 section 2.9

For weights w and expected asset returns μ, the expected portfolio return is the dot product μᵀw. In NumPy, the @ operator expresses this directly. With weights [0.2, 0.3, 0.5], the demonstrated portfolio return is 9.5%. section 2.2

The same pattern handles risk. Multiplying a diagonal volatility matrix, a correlation matrix, and its transpose produces the covariance matrix; multiplying wᵀ, Cov, and w produces portfolio variance, whose square root is standard deviation.

Portfolio return and risk

Represent FE, WMT, and AAPL with weights and asset statistics. Evaluate μ @ w.T for expected return, then compute (w @ Cov @ w.T) ** 0.5 for portfolio standard deviation. These outputs support comparisons among portfolios seeking higher returns for a given risk. section 2.2

How Build a Robo-Advisor with Python (From Scratch) covers it

How deep it goes
Explains vector and covariance expressions with executable NumPy examples, while stopping short of broader linear-algebra theory.
Examples
Uses FE, WMT, and AAPL weights, asset statistics, covariance construction, and portfolio standard-deviation calculations.
What it assumes
Assumes basic portfolio weights and asset statistics, while teaching unfamiliar readers the needed vector operations through concise commands.
What you can do after
Apply it via NumPy to calculate portfolio returns, covariance matrices, and risk measures without explicit loops.
How it connects
Connects expected return, standard deviation, covariance matrices, correlation matrices, and portfolio construction.

Also explained in

Compare how 8 books explain matrix-matrix multiplication →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Robo-Advisor with Python (From Scratch). The section links point to the parts of the book it draws on.