gbm_simulator module

gbm_simulator.dispatch_simulation(n, s, r, div_yield, dt, sigma, z, method)[source]

Dispatch the simulation to the appropriate algorithm

gbm_simulator.simulate_gbm(n, s, r, div_yield, t, t_terminal, dt, sigma, method='euler', seed=None)[source]

Simulate a geometric brownian motion path

The GBM is simulated using either the Euler or Milstein method. Instead of a loop, the algorithms have been vectorized for speed.

Euler:

\(S_{t+1} = S_{t} + \mu S_{t} dt + \sigma S_{t} \sqrt{dt} Z_{t+1}\)

Milstein:

\(S_{t+1} = S_{t} + \mu S_{t} dt + \sigma S_{t} \sqrt{dt} Z_{t+1} + .5 \sigma ^ 2 ((\sqrt{dt} Z_{t+1}) ^ 2 - dt)\)

Parameters:
  • n (double) – The number of paths to simulate
  • s (double) – Initial stock price at time t.
  • r (double) – The risk free interest rate.
  • div_yield (double) – Dividend yield.
  • t_terminal (double) – Terminal time T
  • t (double) – Starting time
  • dt (double) – Discretization time step size
  • sigma (double) – Volatility
  • method ({"euler", "milstein"}, defaults "euler") – Numerical method to simulate with
  • seed (int) – Random seed to set for random normal generation
Returns:

sims – An array containing the n simulations as rows and the time steps as columns

Return type:

Numpy array

gbm_simulator.simulate_gbm_euler(n, s, r, div_yield, dt, sigma, z)[source]

GBM simulation using a Euler discretization

gbm_simulator.simulate_gbm_milstein(n, s, r, div_yield, dt, sigma, z)[source]

GBM simulation using a Milstein discretization