Models Module

Heston

HestonModel

class pyquantlib.HestonModel

Bases: CalibratedModel

Heston stochastic volatility model.

__init__(process: HestonProcess) None

Constructs Heston model from process.

kappa() float

Returns mean-reversion speed.

rho() float

Returns correlation.

sigma() float

Returns volatility of volatility.

theta() float

Returns long-term variance.

v0() float

Returns initial variance.

Parameter

Symbol

Description

v0

\(v_0\)

Initial variance

kappa

\(\kappa\)

Mean reversion speed

theta

\(\theta\)

Long-term variance

sigma

\(\sigma\)

Volatility of variance (vol of vol)

rho

\(\rho\)

Correlation between spot and variance

heston_process = ql.HestonProcess(
    ql.YieldTermStructureHandle(risk_free),
    ql.YieldTermStructureHandle(dividend),
    ql.QuoteHandle(spot),
    v0=0.04, kappa=1.0, theta=0.04, sigma=0.5, rho=-0.7,
)
model = ql.HestonModel(heston_process)

engine = ql.AnalyticHestonEngine(model)
option.setPricingEngine(engine)

PiecewiseTimeDependentHestonModel

class pyquantlib.PiecewiseTimeDependentHestonModel

Bases: CalibratedModel

Piecewise time-dependent Heston stochastic volatility model.

__init__(riskFreeRate: YieldTermStructureHandle, dividendYield: YieldTermStructureHandle, s0: QuoteHandle, v0: SupportsFloat | SupportsIndex, theta: Parameter, kappa: Parameter, sigma: Parameter, rho: Parameter, timeGrid: TimeGrid) None

Constructs time-dependent Heston model.

dividendYield() YieldTermStructureHandle

Returns dividend yield term structure.

kappa(t: SupportsFloat | SupportsIndex) float

Returns kappa at time t.

rho(t: SupportsFloat | SupportsIndex) float

Returns rho at time t.

riskFreeRate() YieldTermStructureHandle

Returns risk-free rate term structure.

s0() float

Returns initial spot price.

sigma(t: SupportsFloat | SupportsIndex) float

Returns sigma at time t.

theta(t: SupportsFloat | SupportsIndex) float

Returns theta at time t.

timeGrid() TimeGrid

Returns the time grid.

v0() float

Returns initial variance.

HestonModelHandle

class pyquantlib.HestonModelHandle

Bases: pybind11_object

Handle to HestonModel objects.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__() -> None

Creates an empty handle.

  1. __init__(ptr: object, registerAsObserver: bool = True) -> None

Creates a handle linked to the given object.

asObservable() Observable

Converts to Observable for observer registration.

Returns the shared_ptr to the current object link.

empty() bool

Returns true if the handle is empty.

get() HestonModel

Returns the underlying shared_ptr. Raises error if empty.

BatesModel

class pyquantlib.BatesModel

Bases: HestonModel

Bates stochastic volatility model with jumps.

__init__(process: BatesProcess) None

Constructs from a Bates process.

delta() float

Returns jump size volatility.

lambda_() float

Returns jump intensity.

nu() float

Returns mean jump size.

Extends HestonModel with jump parameters:

Parameter

Symbol

Description

lambda

\(\lambda\)

Jump intensity

nu

\(\nu\)

Mean jump size

delta

\(\delta\)

Jump size volatility

bates_process = ql.BatesProcess(
    risk_free, dividend, spot,
    0.04, 1.0, 0.04, 0.5, -0.7,  # v0, kappa, theta, sigma, rho
    0.1, -0.05, 0.1,              # lambda, nu, delta
)
model = ql.BatesModel(bates_process)
engine = ql.BatesEngine(model)

Short Rate Models

Vasicek

class pyquantlib.Vasicek

Bases: OneFactorAffineModel

Vasicek short-rate model: dr = a(b - r)dt + sigma*dW.

__init__(r0: SupportsFloat | SupportsIndex = 0.05, a: SupportsFloat | SupportsIndex = 0.1, b: SupportsFloat | SupportsIndex = 0.05, sigma: SupportsFloat | SupportsIndex = 0.01, lambda: SupportsFloat | SupportsIndex = 0.0) None

Constructs Vasicek model with initial rate, mean reversion, long-term rate, volatility, and risk premium.

a() float

Returns mean reversion speed.

b() float

Returns long-term mean rate.

discountBondOption(type: OptionType, strike: SupportsFloat | SupportsIndex, maturity: SupportsFloat | SupportsIndex, bondMaturity: SupportsFloat | SupportsIndex) float

Returns discount bond option price.

r0() float

Returns initial short rate.

sigma() float

Returns volatility.

property lambda_

Returns risk premium.

Parameter

Symbol

Description

r0

\(r_0\)

Initial short rate

a

\(a\)

Mean reversion speed

b

\(b\)

Long-term mean rate

sigma

\(\sigma\)

Volatility

The Vasicek model follows the SDE: \(dr_t = a(b - r_t)dt + \sigma dW_t\)

vasicek = ql.Vasicek(r0=0.05, a=0.3, b=0.03, sigma=0.01)

# Price a discount bond option
price = vasicek.discountBondOption(ql.Call, 0.95, 1.0, 2.0)

HullWhite

class pyquantlib.HullWhite

Bases: Vasicek, TermStructureConsistentModel

Hull-White extended Vasicek model: dr = (theta(t) - a*r)dt + sigma*dW.

static convexityBias(futurePrice: SupportsFloat | SupportsIndex, t: SupportsFloat | SupportsIndex, T: SupportsFloat | SupportsIndex, sigma: SupportsFloat | SupportsIndex, a: SupportsFloat | SupportsIndex) float

Computes futures convexity bias.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(termStructure: YieldTermStructureHandle, a: SupportsFloat | SupportsIndex = 0.1, sigma: SupportsFloat | SupportsIndex = 0.01) -> None

Constructs Hull-White model with term structure, mean reversion, and volatility.

  1. __init__(termStructure: base.YieldTermStructure, a: SupportsFloat | SupportsIndex = 0.1, sigma: SupportsFloat | SupportsIndex = 0.01) -> None

Constructs Hull-White model from term structure.

discountBondOption(type: OptionType, strike: SupportsFloat | SupportsIndex, maturity: SupportsFloat | SupportsIndex, bondMaturity: SupportsFloat | SupportsIndex) float

Returns discount bond option price.

Parameter

Symbol

Description

a

\(a\)

Mean reversion speed

sigma

\(\sigma\)

Volatility

The Hull-White model extends Vasicek with time-dependent drift to fit the initial term structure: \(dr_t = (\theta(t) - a \cdot r_t)dt + \sigma dW_t\)

# Create a term structure
today = ql.Date(15, 1, 2026)
ql.Settings.instance().evaluationDate = today
curve = ql.FlatForward(today, 0.05, ql.Actual365Fixed())

# Hull-White model fitted to the curve
hw = ql.HullWhite(curve, a=0.1, sigma=0.01)

# Access the fitted term structure
ts_handle = hw.termStructure()

# Price a discount bond option
price = hw.discountBondOption(ql.Call, 0.95, 1.0, 2.0)

# Compute futures convexity bias
bias = ql.HullWhite.convexityBias(95.0, 0.25, 0.5, 0.01, 0.1)

BlackKarasinski

class pyquantlib.BlackKarasinski

Bases: OneFactorModel, TermStructureConsistentModel

Black-Karasinski model: d(ln r) = (theta(t) - a*ln(r))dt + sigma*dW.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(termStructure: YieldTermStructureHandle, a: SupportsFloat | SupportsIndex = 0.1, sigma: SupportsFloat | SupportsIndex = 0.1) -> None

Constructs Black-Karasinski model with term structure, mean reversion, and volatility.

  1. __init__(termStructure: base.YieldTermStructure, a: SupportsFloat | SupportsIndex = 0.1, sigma: SupportsFloat | SupportsIndex = 0.1) -> None

Constructs Black-Karasinski model from term structure.

Parameter

Symbol

Description

a

\(a\)

Mean reversion speed

sigma

\(\sigma\)

Volatility

The Black-Karasinski model is a lognormal short-rate model: \(d(\ln r_t) = (\theta(t) - a \ln r_t)dt + \sigma dW_t\)

Unlike Hull-White, Black-Karasinski ensures positive interest rates since \(r_t = e^{x_t}\) where \(x_t\) follows an Ornstein-Uhlenbeck process.

# Create a term structure
today = ql.Date(15, 1, 2026)
ql.Settings.instance().evaluationDate = today
curve = ql.FlatForward(today, 0.05, ql.Actual365Fixed())

# Black-Karasinski model fitted to the curve
bk = ql.BlackKarasinski(curve, a=0.1, sigma=0.1)

# Access the fitted term structure
ts_handle = bk.termStructure()

# Model parameters via CalibratedModel interface
params = bk.params()  # [a, sigma]

G2

class pyquantlib.G2

Bases: TwoFactorModel, AffineModel, TermStructureConsistentModel

Two-additive-factor Gaussian model G2++.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(termStructure: YieldTermStructureHandle, a: SupportsFloat | SupportsIndex = 0.1, sigma: SupportsFloat | SupportsIndex = 0.01, b: SupportsFloat | SupportsIndex = 0.1, eta: SupportsFloat | SupportsIndex = 0.01, rho: SupportsFloat | SupportsIndex = -0.75) -> None

Constructs G2++ model with term structure and parameters.

  1. __init__(termStructure: base.YieldTermStructure, a: SupportsFloat | SupportsIndex = 0.1, sigma: SupportsFloat | SupportsIndex = 0.01, b: SupportsFloat | SupportsIndex = 0.1, eta: SupportsFloat | SupportsIndex = 0.01, rho: SupportsFloat | SupportsIndex = -0.75) -> None

Constructs G2++ model from term structure.

a() float

Returns first factor mean reversion speed.

b() float

Returns second factor mean reversion speed.

discountBond(t: SupportsFloat | SupportsIndex, T: SupportsFloat | SupportsIndex, x: SupportsFloat | SupportsIndex, y: SupportsFloat | SupportsIndex) float

Returns discount bond price P(t,T) given state variables x and y.

discountBondOption(type: OptionType, strike: SupportsFloat | SupportsIndex, maturity: SupportsFloat | SupportsIndex, bondMaturity: SupportsFloat | SupportsIndex) float

Returns discount bond option price.

eta() float

Returns second factor volatility.

rho() float

Returns correlation between factors.

sigma() float

Returns first factor volatility.

Parameter

Symbol

Description

a

\(a\)

First factor mean reversion speed

sigma

\(\sigma\)

First factor volatility

b

\(b\)

Second factor mean reversion speed

eta

\(\eta\)

Second factor volatility

rho

\(\rho\)

Correlation between factors

The G2++ model is a two-additive-factor Gaussian model where the short rate is: \(r_t = \varphi(t) + x_t + y_t\)

with \(dx_t = -a x_t dt + \sigma dW^1_t\) and \(dy_t = -b y_t dt + \eta dW^2_t\), and \(dW^1_t dW^2_t = \rho dt\).

# Create a term structure
today = ql.Date(15, 1, 2026)
ql.Settings.instance().evaluationDate = today
curve = ql.FlatForward(today, 0.05, ql.Actual365Fixed())

# G2++ model fitted to the curve
g2 = ql.G2(curve, a=0.1, sigma=0.01, b=0.1, eta=0.01, rho=-0.75)

# Parameter accessors
print(g2.a(), g2.sigma(), g2.b(), g2.eta(), g2.rho())

# Price a discount bond option
price = g2.discountBondOption(ql.Call, 0.95, 1.0, 2.0)

CoxIngersollRoss

class pyquantlib.CoxIngersollRoss

Bases: OneFactorAffineModel

Cox-Ingersoll-Ross short-rate model.

__init__(r0: SupportsFloat | SupportsIndex = 0.05, theta: SupportsFloat | SupportsIndex = 0.1, k: SupportsFloat | SupportsIndex = 0.1, sigma: SupportsFloat | SupportsIndex = 0.1, withFellerConstraint: bool = True) None

Constructs CIR model.

discountBondOption(type: OptionType, strike: SupportsFloat | SupportsIndex, maturity: SupportsFloat | SupportsIndex, bondMaturity: SupportsFloat | SupportsIndex) float

Returns discount bond option price.

Cox-Ingersoll-Ross short-rate model. Parameters accessible via params() (theta, k, sigma, r0).

ExtendedCoxIngersollRoss

class pyquantlib.ExtendedCoxIngersollRoss

Bases: CoxIngersollRoss, TermStructureConsistentModel

Extended Cox-Ingersoll-Ross model fitted to term structure.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(termStructure: YieldTermStructureHandle, theta: SupportsFloat | SupportsIndex = 0.1, k: SupportsFloat | SupportsIndex = 0.1, sigma: SupportsFloat | SupportsIndex = 0.1, x0: SupportsFloat | SupportsIndex = 0.05, withFellerConstraint: bool = True) -> None

Constructs extended CIR model.

  1. __init__(termStructure: base.YieldTermStructure, theta: SupportsFloat | SupportsIndex = 0.1, k: SupportsFloat | SupportsIndex = 0.1, sigma: SupportsFloat | SupportsIndex = 0.1, x0: SupportsFloat | SupportsIndex = 0.05, withFellerConstraint: bool = True) -> None

Constructs extended CIR model (handle created internally).

Extended CIR model fitted to the initial term structure.

ShortRateModelHandle

class pyquantlib.ShortRateModelHandle

Bases: pybind11_object

Handle to a short-rate model.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__() -> None

Creates an empty handle.

  1. __init__(ptr: object, registerAsObserver: bool = True) -> None

Creates a handle linked to the given object.

asObservable() Observable

Converts to Observable for observer registration.

Returns the shared_ptr to the current object link.

empty() bool

Returns true if the handle is empty.

get() base.ShortRateModel

Returns the underlying shared_ptr. Raises error if empty.

model = ql.Vasicek(r0=0.05)
handle = ql.ShortRateModelHandle(model)

RelinkableShortRateModelHandle

class pyquantlib.RelinkableShortRateModelHandle

Bases: ShortRateModelHandle

Relinkable handle to a short-rate model.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__() -> None

Creates an empty relinkable handle.

  1. __init__(ptr: object, registerAsObserver: bool = True) -> None

Creates a relinkable handle linked to the given object.

linkTo(ptr: object = None, registerAsObserver: bool = True) None

Links the handle to a new object instance. Notifies observers.

model1 = ql.Vasicek(r0=0.03)
model2 = ql.Vasicek(r0=0.05)

handle = ql.RelinkableShortRateModelHandle(model1)
handle.linkTo(model2)  # Switch to different model

Calibration Helpers

CalibrationErrorType

class pyquantlib.CalibrationErrorType

Bases: pybind11_object

Type of calibration error calculation.

Members:

RelativePriceError

PriceError

ImpliedVolError

__init__(value: SupportsInt | SupportsIndex) None
ImpliedVolError = <CalibrationErrorType.ImpliedVolError: 2>
PriceError = <CalibrationErrorType.PriceError: 1>
RelativePriceError = <CalibrationErrorType.RelativePriceError: 0>
CalibrationErrorType.name -> str
property value

RateAveraging

class pyquantlib.RateAveraging

Bases: pybind11_object

Rate averaging methods for multi-fixing coupons.

class Type

Bases: pybind11_object

Rate averaging type.

Members:

Simple : Simple averaging: sum of sub-period interest amounts.

Compound : Compound averaging: compounded sub-period rates.

__init__(value: SupportsInt | SupportsIndex) None
Compound = <Type.Compound: 1>
Simple = <Type.Simple: 0>
RateAveraging.Type.name -> str
property value
__init__(*args, **kwargs)
class pyquantlib.RateAveraging.Type

Bases: pybind11_object

Rate averaging type.

Members:

Simple : Simple averaging: sum of sub-period interest amounts.

Compound : Compound averaging: compounded sub-period rates.

__init__(value: SupportsInt | SupportsIndex) None
Compound = <Type.Compound: 1>
Simple = <Type.Simple: 0>
Type.name -> str
property value

SwaptionHelper

class pyquantlib.SwaptionHelper

Bases: BlackCalibrationHelper

Calibration helper for interest-rate swaptions.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(maturity: Period, length: Period, volatility: QuoteHandle, index: IborIndex, fixedLegTenor: Period, fixedLegDayCounter: DayCounter, floatingLegDayCounter: DayCounter, termStructure: YieldTermStructureHandle, errorType: CalibrationErrorType = <CalibrationErrorType.RelativePriceError: 0>, strike: SupportsFloat | SupportsIndex = Null<NullReal>(), nominal: SupportsFloat | SupportsIndex = 1.0, type: VolatilityType = <VolatilityType.ShiftedLognormal: 0>, shift: SupportsFloat | SupportsIndex = 0.0, settlementDays: SupportsInt | SupportsIndex = Null<NullSize>(), averagingMethod: RateAveraging.Type = <Type.Compound: 1>) -> None

Constructs swaption helper with period maturity and length.

  1. __init__(maturity: Period, length: Period, volatility: base.Quote, index: IborIndex, fixedLegTenor: Period, fixedLegDayCounter: DayCounter, floatingLegDayCounter: DayCounter, termStructure: base.YieldTermStructure, errorType: CalibrationErrorType = <CalibrationErrorType.RelativePriceError: 0>, strike: SupportsFloat | SupportsIndex = Null<NullReal>(), nominal: SupportsFloat | SupportsIndex = 1.0, type: VolatilityType = <VolatilityType.ShiftedLognormal: 0>, shift: SupportsFloat | SupportsIndex = 0.0, settlementDays: SupportsInt | SupportsIndex = Null<NullSize>(), averagingMethod: RateAveraging.Type = <Type.Compound: 1>) -> None

Constructs swaption helper from period maturity and length.

  1. __init__(exerciseDate: Date, length: Period, volatility: QuoteHandle, index: IborIndex, fixedLegTenor: Period, fixedLegDayCounter: DayCounter, floatingLegDayCounter: DayCounter, termStructure: YieldTermStructureHandle, errorType: CalibrationErrorType = <CalibrationErrorType.RelativePriceError: 0>, strike: SupportsFloat | SupportsIndex = Null<NullReal>(), nominal: SupportsFloat | SupportsIndex = 1.0, type: VolatilityType = <VolatilityType.ShiftedLognormal: 0>, shift: SupportsFloat | SupportsIndex = 0.0, settlementDays: SupportsInt | SupportsIndex = Null<NullSize>(), averagingMethod: RateAveraging.Type = <Type.Compound: 1>) -> None

Constructs swaption helper with exercise date and swap length.

  1. __init__(exerciseDate: Date, length: Period, volatility: base.Quote, index: IborIndex, fixedLegTenor: Period, fixedLegDayCounter: DayCounter, floatingLegDayCounter: DayCounter, termStructure: base.YieldTermStructure, errorType: CalibrationErrorType = <CalibrationErrorType.RelativePriceError: 0>, strike: SupportsFloat | SupportsIndex = Null<NullReal>(), nominal: SupportsFloat | SupportsIndex = 1.0, type: VolatilityType = <VolatilityType.ShiftedLognormal: 0>, shift: SupportsFloat | SupportsIndex = 0.0, settlementDays: SupportsInt | SupportsIndex = Null<NullSize>(), averagingMethod: RateAveraging.Type = <Type.Compound: 1>) -> None

Constructs swaption helper from exercise date and swap length.

  1. __init__(exerciseDate: Date, endDate: Date, volatility: QuoteHandle, index: IborIndex, fixedLegTenor: Period, fixedLegDayCounter: DayCounter, floatingLegDayCounter: DayCounter, termStructure: YieldTermStructureHandle, errorType: CalibrationErrorType = <CalibrationErrorType.RelativePriceError: 0>, strike: SupportsFloat | SupportsIndex = Null<NullReal>(), nominal: SupportsFloat | SupportsIndex = 1.0, type: VolatilityType = <VolatilityType.ShiftedLognormal: 0>, shift: SupportsFloat | SupportsIndex = 0.0, settlementDays: SupportsInt | SupportsIndex = Null<NullSize>(), averagingMethod: RateAveraging.Type = <Type.Compound: 1>) -> None

Constructs swaption helper with exercise and end dates.

  1. __init__(exerciseDate: Date, endDate: Date, volatility: base.Quote, index: IborIndex, fixedLegTenor: Period, fixedLegDayCounter: DayCounter, floatingLegDayCounter: DayCounter, termStructure: base.YieldTermStructure, errorType: CalibrationErrorType = <CalibrationErrorType.RelativePriceError: 0>, strike: SupportsFloat | SupportsIndex = Null<NullReal>(), nominal: SupportsFloat | SupportsIndex = 1.0, type: VolatilityType = <VolatilityType.ShiftedLognormal: 0>, shift: SupportsFloat | SupportsIndex = 0.0, settlementDays: SupportsInt | SupportsIndex = Null<NullSize>(), averagingMethod: RateAveraging.Type = <Type.Compound: 1>) -> None

Constructs swaption helper from exercise and end dates.

blackPrice(volatility: SupportsFloat | SupportsIndex) float

Returns Black price for given volatility.

modelValue() float

Returns the model value.

swaption() QuantLib::Swaption

Returns the swaption instrument.

underlying() QuantLib::FixedVsFloatingSwap

Returns the underlying swap.

Used for calibrating short-rate models to market swaption prices.

# Create market environment
today = ql.Date(15, 1, 2026)
ql.Settings.instance().evaluationDate = today
curve = ql.FlatForward(today, 0.05, ql.Actual365Fixed())
index = ql.Euribor6M(curve)

# Create swaption helper with 20% implied volatility
vol = ql.SimpleQuote(0.20)
helper = ql.SwaptionHelper(
    maturity=ql.Period(1, ql.Years),
    length=ql.Period(5, ql.Years),
    volatility=vol,
    index=index,
    fixedLegTenor=ql.Period(1, ql.Years),
    fixedLegDayCounter=ql.Thirty360(ql.Thirty360.BondBasis),
    floatingLegDayCounter=ql.Actual360(),
    termStructure=curve,
)

# Access underlying instruments
swap = helper.underlying()
swaption = helper.swaption()

CapHelper

class pyquantlib.CapHelper

Bases: BlackCalibrationHelper

Calibration helper for ATM caps.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(length: Period, volatility: QuoteHandle, index: IborIndex, fixedLegFrequency: Frequency, fixedLegDayCounter: DayCounter, includeFirstSwaplet: bool, termStructure: YieldTermStructureHandle, errorType: CalibrationErrorType = <CalibrationErrorType.RelativePriceError: 0>, type: VolatilityType = <VolatilityType.ShiftedLognormal: 0>, shift: SupportsFloat | SupportsIndex = 0.0) -> None

Constructs cap helper with handles.

  1. __init__(length: Period, volatility: base.Quote, index: IborIndex, fixedLegFrequency: Frequency, fixedLegDayCounter: DayCounter, includeFirstSwaplet: bool, termStructure: base.YieldTermStructure, errorType: CalibrationErrorType = <CalibrationErrorType.RelativePriceError: 0>, type: VolatilityType = <VolatilityType.ShiftedLognormal: 0>, shift: SupportsFloat | SupportsIndex = 0.0) -> None

Constructs cap helper (handles created internally).

blackPrice(volatility: SupportsFloat | SupportsIndex) float

Returns Black price for given volatility.

modelValue() float

Returns the model value.

Calibration helper for ATM caps, used for calibrating short-rate models.

helper = ql.CapHelper(
    ql.Period(5, ql.Years), vol, index, ql.Annual,
    index.dayCounter(), True, curve,
)

HestonModelHelper

class pyquantlib.HestonModelHelper

Bases: BlackCalibrationHelper

Calibration helper for the Heston model.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(maturity: Period, calendar: Calendar, s0: SupportsFloat | SupportsIndex, strikePrice: SupportsFloat | SupportsIndex, volatility: QuoteHandle, riskFreeRate: YieldTermStructureHandle, dividendYield: YieldTermStructureHandle, errorType: CalibrationErrorType = <CalibrationErrorType.RelativePriceError: 0>) -> None

Constructs Heston helper with Real spot price.

  1. __init__(maturity: Period, calendar: Calendar, s0: SupportsFloat | SupportsIndex, strikePrice: SupportsFloat | SupportsIndex, volatility: base.Quote, riskFreeRate: base.YieldTermStructure, dividendYield: base.YieldTermStructure, errorType: CalibrationErrorType = <CalibrationErrorType.RelativePriceError: 0>) -> None

Constructs Heston helper with Real spot (handles created internally).

  1. __init__(maturity: Period, calendar: Calendar, s0: QuoteHandle, strikePrice: SupportsFloat | SupportsIndex, volatility: QuoteHandle, riskFreeRate: YieldTermStructureHandle, dividendYield: YieldTermStructureHandle, errorType: CalibrationErrorType = <CalibrationErrorType.RelativePriceError: 0>) -> None

Constructs Heston helper with Handle<Quote> spot price.

blackPrice(volatility: SupportsFloat | SupportsIndex) float

Returns Black price for given volatility.

maturity() float

Returns the time to maturity.

modelValue() float

Returns the model value.

Calibration helper for the Heston model using market option prices.

helper = ql.HestonModelHelper(
    ql.Period(1, ql.Years), ql.TARGET(), 100.0, 100.0,
    vol, risk_free, div,
)

Parameters

Parameter

class pyquantlib.Parameter

Bases: pybind11_object

Model parameter with constraint.

__init__() None
constraint() base.Constraint

Returns the parameter constraint.

params() Array

Returns parameter values.

setParam(i: SupportsInt | SupportsIndex, x: SupportsFloat | SupportsIndex) None

Sets the i-th parameter value.

size() int

Returns number of parameters.

testParams(params: Array) bool

Tests if parameters satisfy constraint.

ConstantParameter

class pyquantlib.ConstantParameter

Bases: Parameter

Time-constant parameter.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(constraint: base.Constraint) -> None

  2. __init__(value: SupportsFloat | SupportsIndex, constraint: base.Constraint) -> None

Gaussian 1-D Framework

Gsr

class pyquantlib.Gsr

Bases: Gaussian1dModel, CalibratedModel

Gaussian short-rate model (GSR) in forward measure.

FixedReversions() list[bool]

Returns fix-parameter mask with all reversions fixed.

FixedVolatilities() list[bool]

Returns fix-parameter mask with all volatilities fixed.

MoveReversion(i: SupportsInt | SupportsIndex) list[bool]

Returns fix-parameter mask with only reversion i free.

MoveVolatility(i: SupportsInt | SupportsIndex) list[bool]

Returns fix-parameter mask with only volatility i free.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(termStructure: YieldTermStructureHandle, volstepdates: collections.abc.Sequence[Date], volatilities: collections.abc.Sequence[SupportsFloat | SupportsIndex], reversion: SupportsFloat | SupportsIndex, T: SupportsFloat | SupportsIndex = 60.0) -> None

Constructs GSR with constant mean reversion.

  1. __init__(termStructure: YieldTermStructureHandle, volstepdates: collections.abc.Sequence[Date], volatilities: collections.abc.Sequence[SupportsFloat | SupportsIndex], reversions: collections.abc.Sequence[SupportsFloat | SupportsIndex], T: SupportsFloat | SupportsIndex = 60.0) -> None

Constructs GSR with piecewise mean reversion.

  1. __init__(termStructure: YieldTermStructureHandle, volstepdates: collections.abc.Sequence[Date], volatilities: collections.abc.Sequence[QuoteHandle], reversion: QuoteHandle, T: SupportsFloat | SupportsIndex = 60.0) -> None

Constructs GSR with constant mean reversion (floating data).

  1. __init__(termStructure: YieldTermStructureHandle, volstepdates: collections.abc.Sequence[Date], volatilities: collections.abc.Sequence[QuoteHandle], reversions: collections.abc.Sequence[QuoteHandle], T: SupportsFloat | SupportsIndex = 60.0) -> None

Constructs GSR with piecewise mean reversion (floating data).

  1. __init__(termStructure: base.YieldTermStructure, volstepdates: collections.abc.Sequence[Date], volatilities: collections.abc.Sequence[SupportsFloat | SupportsIndex], reversion: SupportsFloat | SupportsIndex, T: SupportsFloat | SupportsIndex = 60.0) -> None

Constructs GSR with constant mean reversion (handle created internally).

  1. __init__(termStructure: base.YieldTermStructure, volstepdates: collections.abc.Sequence[Date], volatilities: collections.abc.Sequence[SupportsFloat | SupportsIndex], reversions: collections.abc.Sequence[SupportsFloat | SupportsIndex], T: SupportsFloat | SupportsIndex = 60.0) -> None

Constructs GSR with piecewise mean reversion (handle created internally).

calibrateReversionsIterative(helpers: collections.abc.Sequence[base.BlackCalibrationHelper], method: base.OptimizationMethod, endCriteria: EndCriteria, constraint: base.Constraint = <base.Constraint object at 0x7f25343703b0>, weights: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = []) None

Calibrates reversions one by one to helpers.

calibrateVolatilitiesIterative(helpers: collections.abc.Sequence[base.BlackCalibrationHelper], method: base.OptimizationMethod, endCriteria: EndCriteria, constraint: base.Constraint = <base.Constraint object at 0x7f2534372ef0>, weights: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = []) None

Calibrates volatilities one by one to helpers.

numeraireTime() float

Returns the forward measure time.

reversion() Array

Returns the mean reversion parameters.

setNumeraireTime(T: SupportsFloat | SupportsIndex) None

Sets the forward measure time.

volatility() Array

Returns the volatility parameters.

Gaussian short-rate (GSR) model in forward measure. Supports constant or piecewise mean reversion and volatility, with both static and floating (Handle-based) data.

# Constant mean reversion
gsr = ql.Gsr(term_structure_handle, [], [0.01], 0.1)

# Piecewise
gsr = ql.Gsr(term_structure, [step_date], [0.01, 0.02], [0.1, 0.15])

MarkovFunctional

class pyquantlib.MarkovFunctional

Bases: Gaussian1dModel, CalibratedModel

Markov Functional 1-factor model.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(termStructure: YieldTermStructureHandle, reversion: SupportsFloat | SupportsIndex, volstepdates: collections.abc.Sequence[Date], volatilities: collections.abc.Sequence[SupportsFloat | SupportsIndex], swaptionVol: SwaptionVolatilityStructureHandle, swaptionExpiries: collections.abc.Sequence[Date], swaptionTenors: collections.abc.Sequence[Period], swapIndexBase: SwapIndex, modelSettings: MarkovFunctionalModelSettings = <MarkovFunctionalModelSettings object at 0x7f25360033b0>) -> None

Constructs swaption smile calibrated model.

  1. __init__(termStructure: YieldTermStructureHandle, reversion: SupportsFloat | SupportsIndex, volstepdates: collections.abc.Sequence[Date], volatilities: collections.abc.Sequence[SupportsFloat | SupportsIndex], capletVol: OptionletVolatilityStructureHandle, capletExpiries: collections.abc.Sequence[Date], iborIndex: IborIndex, modelSettings: MarkovFunctionalModelSettings = <MarkovFunctionalModelSettings object at 0x7f25341b08b0>) -> None

Constructs caplet smile calibrated model.

  1. __init__(termStructure: base.YieldTermStructure, reversion: SupportsFloat | SupportsIndex, volstepdates: collections.abc.Sequence[Date], volatilities: collections.abc.Sequence[SupportsFloat | SupportsIndex], swaptionVol: SwaptionVolatilityStructureHandle, swaptionExpiries: collections.abc.Sequence[Date], swaptionTenors: collections.abc.Sequence[Period], swapIndexBase: SwapIndex, modelSettings: MarkovFunctionalModelSettings = <MarkovFunctionalModelSettings object at 0x7f25341fd430>) -> None

Constructs swaption calibrated model (handle created internally).

  1. __init__(termStructure: base.YieldTermStructure, reversion: SupportsFloat | SupportsIndex, volstepdates: collections.abc.Sequence[Date], volatilities: collections.abc.Sequence[SupportsFloat | SupportsIndex], capletVol: OptionletVolatilityStructureHandle, capletExpiries: collections.abc.Sequence[Date], iborIndex: IborIndex, modelSettings: MarkovFunctionalModelSettings = <MarkovFunctionalModelSettings object at 0x7f25341c2e30>) -> None

Constructs caplet calibrated model (handle created internally).

modelOutputs() MarkovFunctionalModelOutputs

Returns diagnostic model outputs.

modelSettings() MarkovFunctionalModelSettings

Returns the model settings.

numeraireDate() Date

Returns the numeraire date.

numeraireTime() float

Returns the numeraire time.

volatility() Array

Returns the volatility parameters.

Markov Functional 1-factor model calibrated to swaption or caplet smiles.

class pyquantlib.MarkovFunctionalModelSettings

Bases: pybind11_object

Configuration settings for MarkovFunctional model.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__() -> None

Constructs default settings (KahaleSmile + SmileExponentialExtrapolation).

  1. __init__(yGridPoints: SupportsInt | SupportsIndex, yStdDevs: SupportsFloat | SupportsIndex, gaussHermitePoints: SupportsInt | SupportsIndex, digitalGap: SupportsFloat | SupportsIndex, marketRateAccuracy: SupportsFloat | SupportsIndex, lowerRateBound: SupportsFloat | SupportsIndex, upperRateBound: SupportsFloat | SupportsIndex, adjustments: SupportsInt | SupportsIndex, smileMoneyCheckpoints: collections.abc.Sequence[SupportsFloat | SupportsIndex] = []) -> None

Constructs with full parameters.

addAdjustment(a: SupportsInt | SupportsIndex) MarkovFunctionalModelSettings

Adds an adjustment flag.

removeAdjustment(a: SupportsInt | SupportsIndex) MarkovFunctionalModelSettings

Removes an adjustment flag.

withAdjustments(a: SupportsInt | SupportsIndex) MarkovFunctionalModelSettings

Sets adjustment flags.

withDigitalGap(d: SupportsFloat | SupportsIndex) MarkovFunctionalModelSettings

Sets digital gap for smile calibration.

withGaussHermitePoints(n: SupportsInt | SupportsIndex) MarkovFunctionalModelSettings

Sets Gauss-Hermite integration points.

withLowerRateBound(l: SupportsFloat | SupportsIndex) MarkovFunctionalModelSettings

Sets lower rate bound.

withMarketRateAccuracy(a: SupportsFloat | SupportsIndex) MarkovFunctionalModelSettings

Sets market rate inversion accuracy.

withSmileMoneynessCheckpoints(m: collections.abc.Sequence[SupportsFloat | SupportsIndex]) MarkovFunctionalModelSettings

Sets smile moneyness checkpoints.

withUpperRateBound(u: SupportsFloat | SupportsIndex) MarkovFunctionalModelSettings

Sets upper rate bound.

withYGridPoints(n: SupportsInt | SupportsIndex) MarkovFunctionalModelSettings

Sets grid points for state process discretization.

withYStdDevs(s: SupportsFloat | SupportsIndex) MarkovFunctionalModelSettings

Sets standard deviations for state grid coverage.

property adjustments
property digitalGap
property gaussHermitePoints
property lowerRateBound
property marketRateAccuracy
property upperRateBound
property yGridPoints
property yStdDevs
class pyquantlib.MarkovFunctionalModelOutputs

Bases: pybind11_object

Diagnostic output from MarkovFunctional calibration.

__init__(*args, **kwargs)
property adjustmentFactors
property annuity
property atm
property digitalsAdjustmentFactors
property dirty
property expiries
property marketCallPremium
property marketPutPremium
property marketRawCallPremium
property marketRawPutPremium
property marketVega
property marketZerorate
property messages
property modelCallPremium
property modelPutPremium
property modelZerorate
property settings
property smileStrikes
property tenors
# Swaption-calibrated MarkovFunctional
mf = ql.MarkovFunctional(
    term_structure, 0.01, [], [0.01],
    swaption_vol_handle, expiries, tenors, swap_index,
)

Stochastic Local Volatility

HestonSLVFDMModel

class pyquantlib.HestonSLVFDMModel

Bases: LazyObject

Heston stochastic local volatility model calibrated via FDM.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(localVol: LocalVolTermStructureHandle, hestonModel: HestonModelHandle, endDate: Date, params: HestonSLVFokkerPlanckFdmParams, logging: bool = False, mandatoryDates: collections.abc.Sequence[Date] = [], mixingFactor: SupportsFloat | SupportsIndex = 1.0) -> None

Constructs from handles.

  1. __init__(localVol: base.LocalVolTermStructure, hestonModel: HestonModel, endDate: Date, params: HestonSLVFokkerPlanckFdmParams, logging: bool = False, mandatoryDates: collections.abc.Sequence[Date] = [], mixingFactor: SupportsFloat | SupportsIndex = 1.0) -> None

Constructs from objects (handles created internally).

hestonProcess() HestonProcess

Returns the Heston process.

leverageFunction() base.LocalVolTermStructure

Returns the calibrated leverage function.

localVol() base.LocalVolTermStructure

Returns the local volatility surface.

Heston SLV model calibrated via Fokker-Planck FDM. Produces a leverage function that can be passed to FdHestonVanillaEngine.

local_vol = ql.LocalConstantVol(today, 0.20, dc)
heston_model = ql.HestonModel(heston_process)

params = ql.HestonSLVFokkerPlanckFdmParams(xGrid=51, vGrid=51)
slv = ql.HestonSLVFDMModel(local_vol, heston_model, end_date, params)

leverage = slv.leverageFunction()
engine = ql.FdHestonVanillaEngine(heston_model, leverageFct=leverage)

HestonSLVMCModel

class pyquantlib.HestonSLVMCModel

Bases: LazyObject

Heston stochastic local volatility model calibrated via Monte Carlo.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(localVol: LocalVolTermStructureHandle, hestonModel: HestonModelHandle, brownianGeneratorFactory: base.BrownianGeneratorFactory, endDate: Date, timeStepsPerYear: SupportsInt | SupportsIndex = 365, nBins: SupportsInt | SupportsIndex = 201, calibrationPaths: SupportsInt | SupportsIndex = 32768, mandatoryDates: collections.abc.Sequence[Date] = [], mixingFactor: SupportsFloat | SupportsIndex = 1.0) -> None

Constructs from handles.

  1. __init__(localVol: base.LocalVolTermStructure, hestonModel: HestonModel, brownianGeneratorFactory: base.BrownianGeneratorFactory, endDate: Date, timeStepsPerYear: SupportsInt | SupportsIndex = 365, nBins: SupportsInt | SupportsIndex = 201, calibrationPaths: SupportsInt | SupportsIndex = 32768, mandatoryDates: collections.abc.Sequence[Date] = [], mixingFactor: SupportsFloat | SupportsIndex = 1.0) -> None

Constructs from objects (handles created internally).

hestonProcess() HestonProcess

Returns the Heston process.

leverageFunction() base.LocalVolTermStructure

Returns the calibrated leverage function.

localVol() base.LocalVolTermStructure

Returns the local volatility surface.

Heston SLV model calibrated via Monte Carlo simulation.

bgf = ql.MTBrownianGeneratorFactory(seed=42)
slv = ql.HestonSLVMCModel(
    local_vol, heston_model, bgf, end_date,
    timeStepsPerYear=365, nBins=201, calibrationPaths=4096,
)

leverage = slv.leverageFunction()

HestonSLVFokkerPlanckFdmParams

class pyquantlib.HestonSLVFokkerPlanckFdmParams

Bases: pybind11_object

Parameters for Heston SLV Fokker-Planck FDM calibration.

__init__(xGrid: SupportsInt | SupportsIndex = 301, vGrid: SupportsInt | SupportsIndex = 601, tMaxStepsPerYear: SupportsInt | SupportsIndex = 2000, tMinStepsPerYear: SupportsInt | SupportsIndex = 30, tStepNumberDecay: SupportsFloat | SupportsIndex = 2.0, nRannacherTimeSteps: SupportsInt | SupportsIndex = 2, predictionCorrectionSteps: SupportsInt | SupportsIndex = 2, x0Density: SupportsFloat | SupportsIndex = 0.1, localVolEpsProb: SupportsFloat | SupportsIndex = 0.0001, maxIntegrationIterations: SupportsInt | SupportsIndex = 10000, vLowerEps: SupportsFloat | SupportsIndex = 1e-06, vUpperEps: SupportsFloat | SupportsIndex = 1e-06, vMin: SupportsFloat | SupportsIndex = 1e-06, v0Density: SupportsFloat | SupportsIndex = 1.0, vLowerBoundDensity: SupportsFloat | SupportsIndex = 10.0, vUpperBoundDensity: SupportsFloat | SupportsIndex = 10.0, leverageFctPropEps: SupportsFloat | SupportsIndex = 1e-05, greensAlgorithm: FdmHestonGreensFctAlgorithm = <FdmHestonGreensFctAlgorithm.Gaussian: 1>, trafoType: FdmSquareRootFwdOpTransformationType = <FdmSquareRootFwdOpTransformationType.Log: 2>, schemeDesc: FdmSchemeDesc = <FdmSchemeDesc object at 0x7f252f3d3ab0>) None

Constructs with keyword arguments.

property greensAlgorithm
property leverageFctPropEps
property localVolEpsProb
property maxIntegrationIterations
property nRannacherTimeSteps
property predictionCorrectionSteps
property schemeDesc
property tMaxStepsPerYear
property tMinStepsPerYear
property tStepNumberDecay
property trafoType
property v0Density
property vGrid
property vLowerBoundDensity
property vLowerEps
property vMin
property vUpperBoundDensity
property vUpperEps
property x0Density
property xGrid

Parameter struct for HestonSLVFDMModel calibration. All fields have sensible defaults.

FdmHestonGreensFctAlgorithm

class pyquantlib.FdmHestonGreensFctAlgorithm

Bases: pybind11_object

Algorithm for Heston Fokker-Planck Green’s function.

Members:

ZeroCorrelation

Gaussian

SemiAnalytical

__init__(value: SupportsInt | SupportsIndex) None
Gaussian = <FdmHestonGreensFctAlgorithm.Gaussian: 1>
SemiAnalytical = <FdmHestonGreensFctAlgorithm.SemiAnalytical: 2>
ZeroCorrelation = <FdmHestonGreensFctAlgorithm.ZeroCorrelation: 0>
FdmHestonGreensFctAlgorithm.name -> str
property value

FdmSquareRootFwdOpTransformationType

class pyquantlib.FdmSquareRootFwdOpTransformationType

Bases: pybind11_object

Coordinate transformation for square-root process FD scheme.

Members:

Plain

Power

Log

__init__(value: SupportsInt | SupportsIndex) None
Log = <FdmSquareRootFwdOpTransformationType.Log: 2>
Plain = <FdmSquareRootFwdOpTransformationType.Plain: 0>
Power = <FdmSquareRootFwdOpTransformationType.Power: 1>
FdmSquareRootFwdOpTransformationType.name -> str
property value

Note

Abstract base classes are available in pyquantlib.base for custom model implementations: CalibratedModel, ShortRateModel, OneFactorModel, OneFactorAffineModel, TwoFactorModel, AffineModel, TermStructureConsistentModel, Gaussian1dModel, CalibrationHelper, BlackCalibrationHelper.