The Naive Python Implementation That Took 47 Seconds
I ran a basic Monte Carlo options pricer in pure Python on 1 million paths. It took 47 seconds. The same logic with Numba's @jit decorator dropped to 0.9 seconds.
That's not a typo. Same algorithm, same machine (M1 MacBook), 52x faster. The only change was adding three characters to the function definition.
Monte Carlo simulation is embarrassingly parallel — you're running thousands of independent price paths and averaging the payoff. Pure Python handles this terribly because every loop iteration involves interpreter overhead, dynamic type checking, and boxed numeric types. Numba compiles the hot path to machine code ahead of time, bypassing all that.
Here's the baseline European call option pricer in NumPy:
python
import numpy as np
import time
def monte_carlo_call_numpy(S0, K, T, r, sigma, paths=100000, steps=252):
"""
S0: initial stock price
K: strike price
T: time to maturity (years)
r: risk-free rate
sigma: volatility
paths: number of Monte Carlo paths
steps: time steps per path
"""
dt = T / steps
discount = np.exp(-r * T)
# Generate all random shocks at once (paths x steps)
Z = np.random.standard_normal((paths, steps))
# Simulate GBM: S_t = S_0 * exp((r - 0.5*sigma^2)*t + sigma*sqrt(t)*Z)
S = np.zeros((paths, steps + 1))
S[:, 0] = S0
for t in range(1, steps + 1):
---
*Continue reading the full article on [TildAlice](https://tildalice.io/numba-jit-monte-carlo-options-pricing-50x-faster/)*
Top comments (0)