Skip to content

Models

Classes

BarrierType

Bases: str, Enum

Functions

from_string classmethod
from_string(s: str)

Convert string to BarrierType

BinomialOptionPricing

Class for Binomial Option Pricing.

Parameters:

Name Type Description Default
inputs OptionInputs

Object containing the following option parameters: - spot : float Current price of the underlying asset - strike : float Strike price of the option - rate : float Risk-free interest rate (as a decimal) - ttm : float Time to maturity in years - volatility : float Implied volatility of the underlying asset (as a decimal) - callprice : float, optional Market price of call option (used for implied volatility calculation) - putprice : float, optional Market price of put option (used for implied volatility calculation)

required
nsteps int

Number of steps

Field(..., gt=0, description='Number of steps')
option_type OptionType

Option type, either 'call' or 'put'

Field(..., description='Call or Put')
exercise_style ExerciseStyle

Exercise style, either 'american' or 'european'

Field(..., description='American or European')
output str

Output type ('price', 'payoff', 'value', 'delta'), by default 'payoff'

'payoff'

Attributes:

Name Type Description
binomialoption ndarray

The calculated option prices (depends on the selected output type)

Methods:

Name Description
plot_tree

Plots the binomial tree based on the selected output type

Functions

plot_tree
plot_tree()

Plot the binomial tree with option values

Black76

Bases: GeneralizedBlackScholes

Black (1976) model for European options on futures or forward contracts.

spot is interpreted as the futures/forward price F. Sets carry b = 0, so carry_factor = e^{-rt}.

Simplified pricing: Call = e^{-rt}·[F·N(d1) − K·N(d2)] Put = e^{-rt}·[K·N(−d2) − F·N(−d1)]

Rho for Black-76 is different from Black-Scholes because F is an independent market observable; only the discount factor depends on r: ∂C/∂r = −t·C / 100 ∂P/∂r = −t·P / 100

Parameters:

Name Type Description Default
inputs OptionInputs

spot should contain the futures/forward price F.

required

Examples:

>>> from quantmod.models import OptionInputs, Black76
>>> b76 = Black76(OptionInputs(spot=100, strike=100, rate=0.05, ttm=1.0, volatility=0.20))
>>> print(b76.results())

BlackScholes

Bases: GeneralizedBlackScholes

Classic Black-Scholes (1973) model for European options on non-dividend-paying stock.

Sets carry b = r, so carry_factor = e^{(b-r)t} = 1 and all GBS formulas collapse to the standard Black-Scholes expressions.

Parameters:

Name Type Description Default
inputs OptionInputs

Validated option parameters (spot, strike, rate, ttm, volatility). Optional: callprice or putprice for implied-volatility calculation.

required

Examples:

>>> from quantmod.models import OptionInputs, BlackScholes
>>> bs = BlackScholes(OptionInputs(spot=100, strike=100, rate=0.05, ttm=1.0, volatility=0.20))
>>> print(bs.results())

BlackScholesOptionPricing

Bases: BlackScholes

.. deprecated:: Use :class:~quantmod.models.BlackScholes instead.

Thin backward-compatibility wrapper around :class:~quantmod.models.BlackScholes. All attributes (call_price, put_price, call_delta, put_delta, gamma, vega, call_theta, put_theta, call_rho, put_rho, impvol) are inherited unchanged.

Parameters:

Name Type Description Default
inputs OptionInputs

Option parameters — see :class:~quantmod.models.OptionInputs.

required

Examples:

>>> from quantmod.models import OptionInputs, BlackScholesOptionPricing
>>> bsop = BlackScholesOptionPricing(
...     OptionInputs(spot=100, strike=100, rate=0.05, ttm=1.0, volatility=0.20)
... )
>>> bsop.call_price
10.4506...

ExerciseStyle

Bases: str, Enum

Functions

from_string classmethod
from_string(s: str)

Convert string to OptionType

GarmanKohlhagen

Bases: GeneralizedBlackScholes

Garman-Kohlhagen (1983) model for European FX options.

Sets carry b = r_d - r_f, so carry_factor = e^{-r_f·t}.

Two rate sensitivities are exposed:

  • Rho (∂C/∂r_d): sensitivity to domestic rate (via results().call_rho).
  • Phi (∂C/∂r_f): sensitivity to foreign rate (via results().call_phi).

Parameters:

Name Type Description Default
inputs OptionInputs

Must include foreign_rate r_f. spot is the FX spot rate (domestic units per one unit of foreign currency).

required

Examples:

>>> from quantmod.models import OptionInputs, GarmanKohlhagen
>>> gk = GarmanKohlhagen(OptionInputs(
...     spot=1.10, strike=1.10, rate=0.03, ttm=0.25,
...     volatility=0.08, foreign_rate=0.01,
... ))
>>> print(gk.results())

GeneralizedBlackScholes

Core GBS pricing engine.

Concrete model subclasses pass validated OptionInputs and set the cost-of-carry b. Subclasses override _rho() and _clone() where the relationship between b and r differs from the default (∂b/∂r = 1).

Parameters:

Name Type Description Default
inputs OptionInputs

Validated option inputs (Pydantic model).

required
carry float

Cost-of-carry b. Set by each concrete subclass.

required
Notes

The generalised pricing formula (Haug, 2007) unifies Black-Scholes, Merton, Black-76, and Garman-Kohlhagen through a single carry parameter:

d1 = [ln(S/K) + (b + σ²/2)·t] / (σ√t)
d2 = d1 - σ√t
C  = S·e^{(b-r)t}·N(d1)  -  K·e^{-rt}·N(d2)
P  = K·e^{-rt}·N(-d2)    -  S·e^{(b-r)t}·N(-d1)

Functions

results
results() -> OptionGreeks

Return all computed prices and Greeks as an :class:OptionGreeks dataclass.

Returns:

Type Description
OptionGreeks

Merton

Bases: GeneralizedBlackScholes

Merton (1973) continuous-dividend model for options on stocks or indices with a known continuous dividend yield q.

Sets carry b = r - q, so carry_factor = e^{-qt}.

Additional Greek

Phi (∂C/∂q and ∂P/∂q) — price change per 1% change in dividend yield. Accessible via results().call_phi and results().put_phi.

Parameters:

Name Type Description Default
inputs OptionInputs

Must include dividend_yield (default 0.0 in OptionInputs).

required

Examples:

>>> from quantmod.models import OptionInputs, Merton
>>> mt = Merton(OptionInputs(spot=100, strike=100, rate=0.05, ttm=1.0,
...                          volatility=0.20, dividend_yield=0.03))
>>> print(mt.results())

MonteCarloOptionPricing

Monte Carlo option pricing engine.

Supports multiple exercise styles, sampling methods, and variance-reduction techniques under a unified interface.

Supported exercise styles
  • European : standard payoff at expiry.
  • Asian : payoff based on the arithmetic average of the price path.
  • Barrier : all four barrier types (up-and-out, up-and-in, down-and-out, down-and-in) with optional cash rebate.
  • American : early-exercise via Longstaff-Schwartz (2001) least-squares regression.
Sampling methods
  • pseudo : Mersenne Twister pseudo-random numbers; fast and broadly applicable. Antithetic variates are applied when antithetic=True (default) to halve variance at no extra simulation cost.
  • sobol : Scrambled Sobol quasi-random sequence (via scipy.stats.qmc.Sobol). Provides O(1/N) convergence vs O(1/√N) for pseudo-random, particularly effective for smooth payoffs (European, Asian). n_simulations is automatically rounded up to the nearest power of 2.

Parameters:

Name Type Description Default
inputs OptionInputs

Validated option parameters (spot, strike, rate, ttm, volatility).

required
n_simulations int

Number of simulation paths. For Sobol, rounded up to the nearest power of 2. Default: 10_000.

10000
n_steps int

Number of time steps per path. Higher values improve barrier and Asian pricing accuracy. Default: 252 (one trading year).

252
option_type OptionType or str

'call' or 'put'. Default: OptionType.CALL.

CALL
exercise_style ExerciseStyle or str

'european', 'asian', 'barrier', or 'american'. Default: ExerciseStyle.EUROPEAN.

EUROPEAN
barrier_level float

Barrier level. Required when exercise_style='barrier'.

None
barrier_rebate float

Cash amount paid when an out-barrier is breached. Default: 0.0.

0.0
barrier_type BarrierType or str

One of 'up_and_out', 'up_and_in', 'down_and_out', 'down_and_in'. Required when exercise_style='barrier'.

None
sampler ('pseudo', 'sobol')

Random number generator. Default: 'pseudo'.

'pseudo'
seed int

Random seed for reproducibility. Applies to pseudo-random only. Default: None.

None
antithetic bool

Apply antithetic variates (pseudo-random only). Default: True.

True

Raises:

Type Description
ValueError

If barrier_level or barrier_type is missing when exercise_style='barrier', or if an unsupported style is requested.

Examples:

European call — pseudo-random with antithetic variates:

>>> from quantmod.models import OptionInputs, MonteCarloOptionPricing, OptionType
>>> inputs = OptionInputs(spot=100, strike=100, rate=0.05, ttm=1.0, volatility=0.20)
>>> mc = MonteCarloOptionPricing(inputs, n_simulations=100_000,
...                              option_type=OptionType.CALL)
>>> print(mc.results())

Up-and-out barrier call — Sobol quasi-random:

>>> from quantmod.models import BarrierType, ExerciseStyle
>>> mc = MonteCarloOptionPricing(
...     inputs,
...     n_simulations=16_384,
...     option_type=OptionType.CALL,
...     exercise_style=ExerciseStyle.BARRIER,
...     barrier_level=120.0,
...     barrier_type=BarrierType.UP_AND_OUT,
...     sampler='sobol',
... )
>>> print(mc.results())

Asian call (arithmetic average):

>>> mc = MonteCarloOptionPricing(
...     inputs,
...     n_simulations=50_000,
...     option_type=OptionType.CALL,
...     exercise_style=ExerciseStyle.ASIAN,
... )
>>> print(mc.results())

American put — Longstaff-Schwartz:

>>> mc = MonteCarloOptionPricing(
...     inputs,
...     n_simulations=50_000,
...     n_steps=100,
...     option_type=OptionType.PUT,
...     exercise_style=ExerciseStyle.AMERICAN,
... )
>>> print(mc.results())

Functions

results
results() -> MonteCarloResult

Return the pricing result as a :class:MonteCarloResult dataclass.

Provides a consistent interface with the GBS models (e.g. :meth:~quantmod.models.BlackScholes.results).

Returns:

Type Description
MonteCarloResult

Pricing result with price, std_error, confidence_interval, n_simulations, and sampler.

Examples:

>>> from quantmod.models import OptionInputs, MonteCarloOptionPricing
>>> inputs = OptionInputs(spot=100, strike=100, rate=0.05, ttm=1.0, volatility=0.20)
>>> mc = MonteCarloOptionPricing(inputs, n_simulations=50_000)
>>> print(mc.results())

MonteCarloResult dataclass

Results from a Monte Carlo option pricing run.

Attributes:

Name Type Description
price float

Estimated option price (discounted expected payoff).

std_error float

Standard error of the Monte Carlo estimate.

confidence_interval tuple[float, float]

95% confidence interval (lower, upper).

n_simulations int

Number of simulation paths used.

sampler str

Sampling method: 'pseudo' or 'sobol'.

OptionGreeks dataclass

Prices and all first-order Greeks for a European option.

All sensitivities are expressed per unit of parameter change:

Attributes:

Name Type Description
model str

Human-readable model name (e.g. "Black-Scholes").

d1 float

Standardised moneyness-adjusted parameter d1.

d2 float

d2 = d1 - σ√t.

call_price float

Theoretical call option price.

put_price float

Theoretical put option price.

call_delta float

∂C/∂S — sensitivity of call price to $1 move in spot.

put_delta float

∂P/∂S — sensitivity of put price to $1 move in spot.

gamma float

∂²C/∂S² = ∂²P/∂S² — rate of change of delta per $1 move in spot.

vega float

∂C/∂σ = ∂P/∂σ — price change per 1% (0.01) change in volatility.

call_theta float

∂C/∂t — call price decay per calendar day.

put_theta float

∂P/∂t — put price decay per calendar day.

call_rho float

∂C/∂r — call price change per 1% (0.01) change in domestic rate.

put_rho float

∂P/∂r — put price change per 1% (0.01) change in domestic rate.

implied_vol float

Implied volatility backed out from market price (if supplied); otherwise equals the input volatility.

call_phi (float, optional)

∂C/∂q or ∂C/∂r_f — call price change per 1% change in the secondary rate (dividend yield for Merton, foreign rate for Garman-Kohlhagen).

put_phi (float, optional)

Corresponding put sensitivity to the secondary rate.

OptionInputs

Bases: BaseModel

Validated input parameters for option pricing models.

Attributes:

Name Type Description
spot float

Current price of the underlying asset. Must be > 0.

strike float

Strike price of the option. Must be > 0.

rate float

Domestic risk-free interest rate as a decimal (e.g. 0.05 for 5%). Must be in [0, 1].

ttm float

Time to maturity in years (e.g. 0.25 for 3 months). Must be > 0.

volatility float

Implied volatility as a decimal (e.g. 0.20 for 20%). Must be > 0.

callprice (float, optional)

Observed market price of the call option. When provided, implied volatility is back-solved from this price.

putprice (float, optional)

Observed market price of the put option. When provided, implied volatility is back-solved from this price.

dividend_yield (float, optional)

Continuous dividend yield as a decimal. Default 0.0. Used by the Merton model: b = r - q.

foreign_rate (float, optional)

Foreign risk-free rate as a decimal. Default 0.0. Used by the Garman-Kohlhagen model: b = r - r_f.

Raises:

Type Description
ValidationError

If any parameter fails its constraint (e.g. spot <= 0, rate > 1).

OptionType

Bases: str, Enum

Enum for option types

Functions

from_string classmethod
from_string(s: str)

Convert string to OptionType

Functions

price_option

price_option(model: str, spot: float, strike: float, rate: float, ttm: float, volatility: float, *, dividend_yield: float = 0.0, foreign_rate: float = 0.0, callprice: Optional[float] = None, putprice: Optional[float] = None) -> OptionGreeks

Convenience factory that selects and prices an option using the specified model.

All inputs are validated by the appropriate OptionInputs subclass before pricing. Returns an :class:OptionGreeks dataclass with all prices and first-order Greeks.

Parameters:

Name Type Description Default
model str

Model selector. Accepted values (case-insensitive):

  • "bs" or "black_scholes" → :class:BlackScholes
  • "merton" or "div" → :class:Merton
  • "b76" or "black76" → :class:Black76
  • "gk" or "garman_kohlhagen" → :class:GarmanKohlhagen
required
spot float

Current underlying price (or futures price for Black-76; spot rate for GK).

required
strike float

Option strike price.

required
rate float

Domestic risk-free rate as a decimal (e.g. 0.05 for 5%).

required
ttm float

Time to maturity in years (e.g. 0.25 for 3 months).

required
volatility float

Implied volatility as a decimal (e.g. 0.20 for 20%).

required
dividend_yield float

Continuous dividend yield (Merton model only). Default: 0.0.

0.0
foreign_rate float

Foreign risk-free rate (Garman-Kohlhagen only). Default: 0.0.

0.0
callprice float

Observed market call price; triggers implied-volatility calculation.

None
putprice float

Observed market put price; triggers implied-volatility calculation.

None

Returns:

Type Description
OptionGreeks

Dataclass containing call/put prices and all Greeks.

Raises:

Type Description
ValueError

If an unknown model string is provided.

Examples:

>>> from quantmod.models import price_option
>>> res = price_option("bs", spot=100, strike=100, rate=0.05, ttm=1.0, volatility=0.20)
>>> print(res)
>>> res = price_option("merton", spot=100, strike=100, rate=0.05, ttm=1.0,
...                    volatility=0.20, dividend_yield=0.03)
>>> res = price_option("gk", spot=1.10, strike=1.10, rate=0.03, ttm=0.25,
...                    volatility=0.08, foreign_rate=0.01)