liveBook · Manning

Normal distribution

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

A normal distribution is a continuous probability distribution characterized by a symmetric bell-shaped density determined by its mean and standard deviation.

A normal distribution models uncertain outcomes around a mean using a standard deviation. In portfolio risk displays, it turns an estimated portfolio mean and volatility into a distribution of gains and losses. A 95% worst-case loss is placed 1.96 standard deviations below the average, making the trade-off from adding stocks visible in dollar terms. section 2.5

Stock–bond risk slider

For a $1,000,000 portfolio, expected returns, standard deviations, and correlations for stocks and bonds produce a portfolio mean and standard deviation. SciPy's normal density then plots the distribution as the stock allocation changes: higher stock weight raises the highlighted mean but also increases the 95% worst-case loss. section 2.5

A normal model can also simulate a stock-price random walk with drift: draw independent annual dollar changes from a distribution with mean $8 and standard deviation $20, then add each change to the prior price. Across 10,000 ten-year simulations, final prices form a normal-shaped histogram. This model is useful for comparison, but it can generate negative prices and makes percentage return and volatility depend on the price level. section 5.1

Listing 5.1 Simulating stock paths with a normal distribution
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

np.random.seed(123)

num_years = 10
num_sims = 10000
mean = 8
stdev = 20

z = np.random.normal(loc=mean, scale=stdev, size=(num_sims, num_years+1))  #1

P = np.zeros((num_sims, num_years+1))
P[:,0] = 100  #2

for sim in range(num_sims):
    for year in range(1, num_years+1):
        P[sim, year] = P[sim, year-1] + z[sim, year]  #3

plt.xlabel('Year')
plt.ylabel('Price')
plt.plot(P[0:4,:].T);

This implementation draws 10,000 normal annual price changes and cumulatively adds them to a $100 starting price, producing sample paths for inspection. section 5.1

For stock prices, multiplying random returns leads approximately to a lognormal distribution and avoids the normal model's price-level problem. Normal assumptions remain usable as inputs to transition calculations: cumulative distribution function values at adjacent wealth-state midpoints are subtracted to obtain the probability of entering each state. The assumption can be replaced with distributions that allow fat tails. section 5.1 section 6.2.1

Practical cautions for financial simulations:

  • Do not treat normally distributed stock prices as realistic merely because the simulated final-price histogram is bell-shaped; negative prices remain possible. section 5.1
  • Consider generalized error distributions for fat-tailed short-period returns, or bootstrap historical returns to retain non-normality and cross-asset correlation properties. section 5.13
  • Handle zero volatility explicitly when evaluating normal CDFs for transition probabilities, since division by zero otherwise occurs. section 6.2.1

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

How deep it goes
Implements density sampling and CDF differences, while deferring parameter estimation and alternative-distribution implementation.
Examples
Uses a stock–bond slider, $100 stock paths with $8 annual changes, and discrete wealth-state transitions.
What it assumes
Assumes expected returns, standard deviations, correlations, and basic Python array operations as calculation inputs.
What you can do after
Apply it via SciPy and NumPy to visualize losses, generate random price changes, and compute state probabilities.
How it connects
Connects standard deviation, portfolio allocation, Monte Carlo simulation, lognormal distribution, cumulative distribution functions, and dynamic programming.

Also explained in

Compare how 16 books explain normal distribution →

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.