GBMSimulatePathsQ

class quantmetrics.price_calculators.gbm_pricing.gbm_paths_Q.GBMSimulatePathsQ(model: LevyModel, option: Option)[source]

Bases: object

Implements the paths simulation for a Geometric Brownian Motion (GBM) model under the risk-neutral measure.

Parameters

modelLevyModel

A LevyModel object specifying the underlying asset’s model and its parameters.

optionOption

An Option object specifying the option parameters: interest rate, strike price, time to maturity, dividend yield and the equivalent martingale measure.

simulate(num_timesteps: int, num_paths: int, seed: int) Dict[str, ndarray][source]

Generate paths for the Geometric Brownian Motion (GBM) model.

Parameters

num_timestepsint

Number of time steps.

num_pathsint

Number of simulated paths.

seedint

Seed for random number generator.

Returns

dict

A dictionary containing:

  • time_steps (np.ndarray): The simulated time steps.

  • S_exact (np.ndarray): The simulated GBM paths using the exact solution.

  • S_euler (np.ndarray): The simulated GBM paths using the Euler-Maruyama discretization.

Notes

The Euler-Maruyama discretization for the \(i^{th}\) timestep and \(j^{th}\) path, reads:

\[s_{i+1, j} \approx s_{i,j} + (r-q) s_{i,j} \Delta t + \sigma s_{i,j} (W_{i+1, j} - W_{i,j}),\]

with \(\Delta t = t_{i+1} - t_i\), for any \(i=1,2,\cdots , m, \ s_0 = S(t_0)=S_0\), \(j = 1,2,\cdots, N\) and \(W_{i+1, j} - W_{i,j} \sim \mathcal{N}(0, \Delta t)\)

The GBM process has as exact solution in the time interval \([t_i, t_{i+1}]\),

\[S(t_{i+1})=S(t_i)\exp\left\{(r-q-\frac{\sigma^2}{2})\Delta t + \sigma [W(t_{i+1}) - W(t_i)] \right\}\]

where

  • \(S_0\) is the underlying price.

  • \(r\) is the risk-free interest rate.

  • \(q\) is the dividend yield.

  • \(\sigma\) is the volatility.

Examples

>>> from quantmetrics.levy_models import GBM
>>> from quantmetrics.option_pricing import Option
>>> from quantmetrics.price_calculators.gbm_pricing.gbm_paths_Q import GBMSimulatePathsQ
>>> gbm = GBM() # S0=50, sigma=0.2
>>> option = Option(K=np.array([20,50,80])) # r=0.05, q=0.02, T=0.5
>>> paths = GBMSimulatePathsQ(gbm, option).simulate(num_timesteps=200, num_paths=10000,seed=42)
>>> payoff = np.maximum(paths["S_exact"][:,-1].reshape(-1,1) - option.K, 0)
>>> option_price = np.mean(np.exp(-option.r*option.T) * payoff, axis=0)
>>> option_price
array([2.99914386e+01, 3.13832975e+00, 1.25147041e-03])

References