0. Guide to the Python Option Pricing Notebook Series

In this series, we begin with option payoffs and models of the underlying asset, then introduce risk-neutral pricing and calculate option prices using analytical formulas and numerical methods. Throughout the chapters, we address the following question: given the contract, model, and market inputs, how do we calculate an option price and assess the computational error?

Features of the Series

Each numerical method has its own chapter. Chapters 2–6 cover trees, Monte Carlo, finite differences, saddlepoint approximations, and Fourier methods, respectively. Each chapter presents the mathematical derivations, algorithms, and Python implementations for that method.

Mathematics and code appear together. Formulas, algorithm descriptions, and the corresponding Python programs are presented next to each other. The programs are divided into small functions so that readers can relate each calculation to its formula and understand the inputs, outputs, and approximations.

We check results using benchmarks and numerical diagnostics. Each chapter uses analytical solutions, independent numerical benchmarks, parameter sensitivity analyses, or convergence results to identify errors. The main error sources differ across methods: time or space discretization, random sampling, frequency truncation, interval truncation, or distributional approximations.

Chapter Roadmap

Chapter 1 introduces option contracts, asset price models, and risk-neutral pricing, providing a common foundation for the later chapters. Chapters 2–6 are independent of one another and can be studied in any order, depending on your interests or the pricing problem you want to solve. While reading a chapter, you can refer back to the relevant models and formulas in Chapter 1.

Chapter Content File
Chapter 1 Option payoffs, stochastic processes, risk-neutral pricing, Black–Scholes, Greeks, and implied volatility Read Chapter 1
Chapter 2 Binomial and trinomial trees, and backward induction for European and American options 02-trees.ipynb — Coming soon
Chapter 3 Monte Carlo pricing under GBM and more advanced models (Merton jump diffusion, Variance Gamma (VG), and normal inverse Gaussian (NIG)); Asian options and control variates, quasi-Monte Carlo, three methods for estimating Greeks, and least-squares Monte Carlo Part 1 — Coming soon / Part 2 — Coming soon
Chapter 4 Finite difference discretization of the Black–Scholes equation, with projection methods for the early exercise of American options 04-pde.ipynb — Coming soon
Chapter 5 Cumulant generating functions for saddlepoint approximations, tail probabilities, and option pricing 05-saddlepoint.ipynb — Coming soon
Chapter 6 Characteristic functions, Carr–Madan FFT, CONV, and COS methods 06-fourier.ipynb — Coming soon

Monte Carlo simulation can accumulate path information for path-dependent options. Trees, finite differences, and least-squares Monte Carlo can handle exercise decisions for options that allow early exercise. When a model has a known characteristic function, Fourier methods can calculate European option prices; FFT can calculate prices for multiple strikes at once.

How to Read and Use the Notebooks

Read each notebook in cell order. Start with the assumptions, notation, and formulas in the current section, and then read the programs that follow. For each price or plot, identify the calculation implemented by the program, the numerical parameters used, and the checks applied to the results.

The “From Formulas to Code” box before a program heading lists the code variables and their corresponding mathematical symbols, and explains the ordering of path arrays, grid nodes, or time levels. Read the box alongside the formulas, then follow the calculation steps in the code.

First, prepare the Python environment using the README.md in the download package, then run the cells from the beginning of the notebook. Later calculations often use models, functions, or parameters defined in earlier cells. When exploring results, change one input at a time and compare with the original benchmark; this helps identify whether a price change comes from the contract, model, or numerical settings.

Python Programs, Objects, and Imports

The root README.md explains how to create a Python virtual environment, install dependencies, run checks, and build the download package; the Chinese zh/README.md provides an overview of the notebook series. This section explains the roles of the source files, the model and contract objects, and how to import and call pricing functions. The project requires Python 3.11 or later; use the installation commands in README.md.

The Python package source files are in src/quant_option_pricing/. After installation, the package name is quant_option_pricing; use this package path when importing functions and classes. The main source files are listed below, together with their roles:

File Main content
contracts.py European, Bermudan, and American option contract objects
models.py Black–Scholes, Merton, Variance Gamma, and NIG model objects and model calculations
settings.py Numerical settings objects for trees, Monte Carlo, PDE, saddlepoint, and Fourier methods
black_scholes.py Black–Scholes pricing, Greeks, and implied volatility functions
trees.py, monte_carlo.py, pde.py, saddlepoint.py Calculation functions for the numerical methods
fourier_pricing.py, fourier.py Fourier interfaces that accept model, option, and settings objects, and the underlying Fourier calculation functions
The three types of objects used in the programs

For pricing programs that take objects as inputs, model stores model parameters such as volatility, the interest rate, and jump parameters; option stores the current price, strike, maturity, and call/put indicator; settings stores the numerical settings for the method, such as the number of time steps, the number of paths, or truncation parameters.

The call/put indicator is specified by option.cp: 1 denotes a call and -1 denotes a put. Denoting this indicator by \(c\), the terminal payoff for both option types is \(\max(c(S_T-K),0)\).

Exercise opportunities are specified by the contract type: EuropeanOption, BermudanOption, and AmericanOption represent European, Bermudan, and American options, respectively; the exercise style is not stored in settings.

Pricing algorithms are implemented as functions in their respective modules, such as european_crr_price, european_mc_price, american_pde_price, and carr_madan_fft_prices. A model object’s characteristic_function method provides the model’s characteristic function for use by Fourier pricing functions.

In the Carr–Madan FFT example below, we construct the model, contract, and numerical settings objects, then call the pricing function. BlackScholesModel, EuropeanOption, and CarrMadanSettings are imported from the package’s public interface; the pricing function is imported from fourier_pricing.py. If no separate array of strikes is supplied, the function returns an array containing the price for the strike specified in option.

from quant_option_pricing import (
    BlackScholesModel,
    CarrMadanSettings,
    EuropeanOption,
)
from quant_option_pricing.fourier_pricing import carr_madan_fft_prices

model = BlackScholesModel(rate=0.05, volatility=0.20)
option = EuropeanOption.call(spot=100.0, strike=100.0, maturity=1.0)
settings = CarrMadanSettings(alpha=1.5, n=4096, eta=0.25)

call_price = carr_madan_fft_prices(model, option, settings)[0]

Some chapters also include direct calls to the underlying functions. Start by examining the function signature: functions with numerical arguments accept values such as volatility, spot price, strike, and maturity directly; functions with object arguments read the corresponding parameters from model, option, and settings. Then follow the function calls back to the relevant model and numerical algorithm.

Prerequisites and Common Notation

Readers should be familiar with calculus, conditional expectation, the normal distribution, and basic linear algebra, and should be able to define Python functions, use NumPy arrays, and read simple Matplotlib plots. Each chapter explains financial concepts and numerical algorithms as they are introduced; installation and environment setup are described in the README.md in the download package.

Throughout the series, \(S_t\) usually denotes the underlying asset price at time \(t\), \(S_0\) the current price, \(K\) the strike, \(T\) the maturity, \(r\) the continuously compounded risk-free interest rate, and \(\sigma\) the volatility. The terminal payoff of a call is \((S_T-K)^+\), and that of a put is \((K-S_T)^+\). Time is usually measured in years; dividends, interest rates, and other market inputs are specified in the relevant chapters and examples.