Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 36 · Projects and Practice

Project: Stock Price Paths with Geometric Brownian Motion

Simulate stock-like price paths with geometric Brownian motion, check their mean and spread, and price a European call by Monte Carlo against the Black-Scholes formula.

In this project you turn Brownian motion into a model for a price that evolves randomly over time, simulate many possible futures, and use them to estimate an option value. This is a teaching exercise in stochastic modelling. It is not financial advice, and real markets break the model's assumptions in many ways.

The model: geometric Brownian motion

A price cannot go below zero, and a 1 dollar move means more for a 10 dollar stock than for a 1,000 dollar stock. So we model the percentage change as random. With drift μ (expected growth rate per year) and volatility σ (standard deviation of returns per √year), the price S(t) follows

Text
dS = μ S dt + σ S dW

Itô calculus (the version of calculus that accounts for the non-zero quadratic variation of Brownian motion) gives the explicit solution

Text
S(t) = S₀ · exp( (μ − σ²/2) t + σ W(t) )

The -σ²/2 correction appears precisely because (dW)² behaves like dt. Because W(t) ~ Normal(0, t), the exponent is normal and S(t) is log-normal, always positive. Useful facts:

Text
E[S(t)] = S₀ e^(μt)
Var[S(t)] = S₀² e^(2μt) (e^(σ²t) − 1)

Notice that the mean grows at rate μ, but the typical (median) path grows at the smaller rate μ − σ²/2.

Step 1: simulate paths

We use the exact solution step by step: over a small step dt, multiply the price by exp((μ − σ²/2) dt + σ √dt Z) with Z a standard normal. There is no discretization error for this model.

Python Simulate price paths

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The mean sits close to S₀ e^(μT), the median is lower (the log-normal distribution has a long right tail), and the standard deviation matches the formula. Even with a positive drift, a sizeable fraction of paths ends below the start.

Step 2: probabilities for barriers and highs

Because we simulate whole paths, we can ask questions about the path: how often does the price touch 120 within a year?

Python Does the price touch a barrier?

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The probability of touching 120 is clearly larger than the probability of ending above it, echoing the reflection principle: paths that touch a level and fall back are plentiful. Monitoring only at discrete time points slightly underestimates the true continuous touching probability.

Step 3: pricing a European call by Monte Carlo

A European call option pays max(S(T) − K, 0) at time T, where K is the strike price. In the standard Black-Scholes setting, its fair value is the discounted expected payoff under the risk-neutral measure, in which the drift μ is replaced by the risk-free interest rate r:

Text
price = e^(−rT) · E[ max(S(T) − K, 0) ]    with S(T) = S₀ exp((r − σ²/2)T + σ√T Z)

The closed-form Black-Scholes formula for this price is

Text
d₁ = [ln(S₀/K) + (r + σ²/2) T] / (σ√T),    d₂ = d₁ − σ√T
price = S₀ Φ(d₁) − K e^(−rT) Φ(d₂)

where Φ is the standard normal distribution function. The Monte Carlo estimate should agree with it up to sampling error, and its standard error shrinks like 1/√(number of paths).

Python Monte Carlo versus Black-Scholes

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The error shrinks roughly like 1/√n: using 100 times more paths buys about one more digit. The same simulation approach prices options with no closed form (such as ones that depend on the whole path), which is why Monte Carlo is a workhorse of quantitative finance.

Real prices are not exactly log-normal: volatility changes over time, and extreme moves are more common than the model predicts. This project illustrates the mathematics of stochastic processes; it does not tell you how any real asset will behave, and it is not investment advice.

Ideas to extend the project

  • Use the compound Poisson idea to add rare price jumps and see how the tails fatten.
  • Estimate μ and σ from a series of daily returns: σ from the standard deviation of log returns times √252.
  • Simulate a portfolio of several correlated assets by correlating the normal shocks.
  • Compare a simple random walk of ±1 steps with the log-price increments and see the same shape appear.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. In geometric Brownian motion, what is E[S(T)] with S(0) = S₀?

    The mean grows at rate μ; the correction −σ²/2 applies to the median and the log-price.
  2. 2. Why is S(T) always positive in this model?

    S(T) = S₀ exp(Normal), and an exponential is always positive.
  3. 3. For option pricing by Monte Carlo, the drift of the simulated price is set to...

    Under the risk-neutral measure the drift is r, and the payoff is discounted at e^(−rT).
  4. 4. You multiply the number of simulated paths by 100. By roughly what factor does the standard error fall?

    The standard error is proportional to 1/√n, so 100 times more paths gives a 10 times smaller error.

Summary

  • Geometric Brownian motion S(t) = S₀ exp((μ − σ²/2)t + σW(t)) models positive, multiplicative randomness; S(t) is log-normal.
  • E[S(T)] = S₀e^(μT), while the median grows at the lower rate μ − σ²/2.
  • Simulating whole paths answers barrier and maximum questions; touching is more likely than ending above a level.
  • Monte Carlo pricing uses the risk-neutral drift r, discounts the average payoff, and converges at rate 1/√n.
  • Models are simplifications; always check their assumptions against data.

Back to the Stochastic Processes track.