liveBook · Manning

Standard deviation

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

Standard deviation is a measure of the dispersion of investment returns around their mean, commonly interpreted as return volatility.

Standard deviation measures how widely investment returns vary around their mean. In portfolio construction it is used interchangeably with return volatility: a lower value represents lower volatility. Plotting expected return against standard deviation turns the trade-off between return and risk into a risk–reward view. section 2.1

For a portfolio, volatility depends on asset weights and on how asset returns move together, not just on each asset’s standalone standard deviation. Given weights w and covariance matrix Cov, portfolio standard deviation is σp = (w @ Cov @ w.T)^0.5. The covariance matrix can be built from standard deviations and correlations as diag(σ) @ Corr @ diag(σ). Matrix multiplication keeps these calculations concise and avoids explicit loops. section 2.2

Three-stock portfolio

FE, WMT, and AAPL have assumed annual return standard deviations of 15%, 20%, and 35%. With weights of 20%, 30%, and 50%, compute expected portfolio return from the weighted means, then compute portfolio standard deviation from the weights and covariance matrix. Repeating this calculation for 1,000 random weight vectors produces a cloud of portfolios in mean–standard deviation space; its lowest-volatility boundary is the minimum-variance frontier. section 2.1 section 2.3

Listing 2.4 Computing the standard deviation of a portfolio
sigma_p = (w @ Cov @ w.T) ** 0.5
print('Portfolio standard deviation: ', sigma_p)

Use the quadratic-form calculation directly after creating the weight vector and covariance matrix. section 2.2

Standard deviation also supports risk-tolerance discussions. For a stock–bond allocation modeled with a normal distribution, a 95% worst-case loss is placed 1.96 portfolio standard deviations below the mean. This result depends on assumed expected returns, standard deviations, and correlations, so it is a visualization based on inputs rather than a guaranteed loss estimate. section 2.5

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

How deep it goes
Derives portfolio volatility through covariance matrices and matrix multiplication, while deferring the minimum-variance-frontier derivation.
Examples
Uses FE, WMT, and AAPL; random portfolio weights; and a stock–bond slider showing a 95% worst-case loss.
What it assumes
Requires only awareness of efficient Python matrix operations; introduces the needed vector and matrix calculations without requiring linear algebra expertise.
What you can do after
Apply it via NumPy to compute portfolio volatility and compare simulated portfolios in risk–reward space.
How it connects
Connects expected return, portfolio weights, covariance, correlation, minimum-variance frontier, efficient frontier, and risk tolerance.

Also explained in

Compare how 15 books explain standard deviation →

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.