A lightweight Python Monte Carlo engine for vanilla European options. It simulates geometric Brownian motion paths with optional variance reduction and provides pricing, confidence intervals, and delta estimation.
- Vectorized GBM simulation with configurable paths/steps.
- Variance reduction: antithetic variates and control variate using the known expectation of (S_T).
- Pricing returns estimate, standard error, and 95% confidence interval.
- Delta via bump-and-revalue for robustness.
- Black-Scholes closed form for validation.
- Tests covering price accuracy, deterministic zero-vol edge case, and delta sanity.
pip install -r requirements.txt(Requires Python 3.10+ and NumPy.)
python monte_carlo_option_pricing.pyExample:
from mc_pricing import MonteCarloPricer, OptionSpec, black_scholes_price
spec = OptionSpec(
spot=100.0,
strike=100.0,
rate=0.05,
vol=0.2,
maturity=1.0,
is_call=True,
)
pricer = MonteCarloPricer(
spec,
n_paths=50_000,
n_steps=50,
antithetic=True,
control_variate=True,
seed=123,
)
price, std_err, ci = pricer.price()
print(f"MC price: {price:.4f} (SE={std_err:.4f}) CI={ci}")
print(f"Black-Scholes: {black_scholes_price(spec):.4f}")
print(f"Delta (MC bump): {pricer.delta():.4f}")pytest -qmc_pricing/pricer.py: Core Monte Carlo pricer, option spec, Black-Scholes helper.monte_carlo_option_pricing.py: CLI example.examples/monte_carlo_demo.ipynb: Notebook demo.tests/: Unit tests for price accuracy and Greeks.
- Set
seedfor reproducibility. n_pathsandn_stepstrade off precision vs runtime; more paths tighten the CI.control_variatecan materially reduce variance for vanilla European payoffs.