Experimental Module

Bindings for QuantLib’s experimental features (ql/experimental/).

Warning

These features are from QuantLib’s experimental namespace and may change in future releases.

Volatility

SviSmileSection

class pyquantlib.SviSmileSection

Bases: SmileSection

Stochastic Volatility Inspired (SVI) smile section.

The SVI total variance formula is:

w(k) = a + b * (rho * (k - m) + sqrt((k - m)^2 + sigma^2))

where k = log(K/F) is the log-moneyness.

Parameters (passed as vector [a, b, sigma, rho, m]):

a: vertical translation (level) b: slope (must be >= 0) sigma: ATM curvature (must be > 0) rho: rotation (-1 < rho < 1) m: horizontal translation

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(timeToExpiry: SupportsFloat | SupportsIndex, forward: SupportsFloat | SupportsIndex, sviParameters: collections.abc.Sequence[SupportsFloat | SupportsIndex]) -> None

Constructs from time to expiry, forward, and SVI parameters [a, b, sigma, rho, m].

  1. __init__(expiryDate: Date, forward: SupportsFloat | SupportsIndex, sviParameters: collections.abc.Sequence[SupportsFloat | SupportsIndex], dayCounter: DayCounter = <DayCounter: Actual/365 (Fixed)>) -> None

Constructs from expiry date, forward, SVI parameters [a, b, sigma, rho, m], and day counter.

The SVI (Stochastic Volatility Inspired) model parametrizes total variance:

\[w(k) = a + b \left( \rho (k - m) + \sqrt{(k - m)^2 + \sigma^2} \right)\]

where \(k = \log(K/F)\) is the log-moneyness.

Parameters (passed as vector [a, b, sigma, rho, m]):

Parameter

Description

Constraint

a

Vertical translation (level)

\(a + b\sigma\sqrt{1-\rho^2} \geq 0\)

b

Slope

\(b \geq 0\), \(b(1+\lvert\rho\rvert) \leq 4\)

sigma

ATM curvature (\(\sigma\))

\(\sigma > 0\)

rho

Rotation/skew (\(\rho\))

\(-1 < \rho < 1\)

m

Horizontal translation

-

import pyquantlib as ql

# SVI parameters: [a, b, sigma, rho, m]
svi_params = [0.04, 0.1, 0.3, -0.4, 0.0]

# Create smile section (T=1y, F=100)
smile = ql.SviSmileSection(1.0, 100.0, svi_params)

# Query volatilities
print(smile.volatility(100.0))  # ATM vol
print(smile.volatility(110.0))  # OTM call vol

# Price options
call_price = smile.optionPrice(110.0, ql.OptionType.Call)

Callable Bonds

CallableBondVolatilityStructure

class pyquantlib.base.CallableBondVolatilityStructure

Bases: TermStructure

Abstract base class for callable-bond volatility structures.

__init__(*args, **kwargs)
blackVariance(optionTime: SupportsFloat | SupportsIndex, bondLength: SupportsFloat | SupportsIndex, strike: SupportsFloat | SupportsIndex, extrapolate: bool = False) float

Returns the Black variance.

maxBondLength() float

Returns the maximum bond length.

maxBondTenor() Period

Returns the maximum bond tenor.

maxStrike() float

Returns the maximum strike.

minStrike() float

Returns the minimum strike.

volatility(*args, **kwargs)

Overloaded function.

  1. volatility(optionTime: SupportsFloat | SupportsIndex, bondLength: SupportsFloat | SupportsIndex, strike: SupportsFloat | SupportsIndex, extrapolate: bool = False) -> float

Returns the volatility for a given option time and bond length.

  1. volatility(optionDate: Date, bondTenor: Period, strike: SupportsFloat | SupportsIndex, extrapolate: bool = False) -> float

Returns the volatility for a given option date and bond tenor.

Abstract base class for callable-bond volatility term structures.

CallableBondConstantVolatility

class pyquantlib.CallableBondConstantVolatility

Bases: CallableBondVolatilityStructure

Constant callable-bond volatility.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(referenceDate: Date, volatility: SupportsFloat | SupportsIndex, dayCounter: DayCounter) -> None

Constructs with reference date and scalar volatility.

  1. __init__(referenceDate: Date, volatility: QuoteHandle, dayCounter: DayCounter) -> None

Constructs with reference date and quoted volatility.

  1. __init__(settlementDays: SupportsInt | SupportsIndex, calendar: Calendar, volatility: SupportsFloat | SupportsIndex, dayCounter: DayCounter) -> None

Constructs with settlement days and scalar volatility.

  1. __init__(settlementDays: SupportsInt | SupportsIndex, calendar: Calendar, volatility: QuoteHandle, dayCounter: DayCounter) -> None

Constructs with settlement days and quoted volatility.

  1. __init__(referenceDate: Date, volatility: base.Quote, dayCounter: DayCounter) -> None

Constructs with reference date and quote (handle created internally).

  1. __init__(settlementDays: SupportsInt | SupportsIndex, calendar: Calendar, volatility: base.Quote, dayCounter: DayCounter) -> None

Constructs with settlement days and quote (handle created internally).

vol = ql.CallableBondConstantVolatility(today, 0.10, ql.Actual365Fixed())
# or with a Quote
vol = ql.CallableBondConstantVolatility(today, ql.SimpleQuote(0.10),
                                         ql.Actual365Fixed())

TreeCallableFixedRateBondEngine

class pyquantlib.TreeCallableFixedRateBondEngine

Bases: PricingEngine

Numerical lattice engine for callable fixed rate bonds.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(model: base.ShortRateModel, timeSteps: SupportsInt | SupportsIndex) -> None

Constructs tree engine with model and time steps.

  1. __init__(model: base.ShortRateModel, timeSteps: SupportsInt | SupportsIndex, termStructure: YieldTermStructureHandle) -> None

Constructs tree engine with model, time steps, and term structure.

  1. __init__(model: base.ShortRateModel, timeGrid: TimeGrid) -> None

Constructs tree engine with model and time grid.

  1. __init__(model: base.ShortRateModel, timeSteps: SupportsInt | SupportsIndex, termStructure: base.YieldTermStructure) -> None

Constructs tree engine (handle created internally).

TreeCallableZeroCouponBondEngine

class pyquantlib.TreeCallableZeroCouponBondEngine

Bases: TreeCallableFixedRateBondEngine

Numerical lattice engine for callable zero coupon bonds.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(model: base.ShortRateModel, timeSteps: SupportsInt | SupportsIndex) -> None

Constructs tree engine with model and time steps.

  1. __init__(model: base.ShortRateModel, timeSteps: SupportsInt | SupportsIndex, termStructure: base.YieldTermStructure) -> None

Constructs tree engine (handle created internally).

hw_model = ql.HullWhite(curve_handle, 0.03, 0.01)
engine = ql.TreeCallableFixedRateBondEngine(hw_model, 100)
bond.setPricingEngine(engine)
print(bond.cleanPrice())

BlackCallableFixedRateBondEngine

class pyquantlib.BlackCallableFixedRateBondEngine

Bases: PricingEngine

Black-formula callable fixed rate bond engine.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(fwdYieldVol: QuoteHandle, discountCurve: YieldTermStructureHandle) -> None

Constructs with forward yield volatility quote and discount curve.

  1. __init__(yieldVolStructure: QuantLib::Handle<QuantLib::CallableBondVolatilityStructure>, discountCurve: YieldTermStructureHandle) -> None

Constructs with callable bond volatility structure and discount curve.

  1. __init__(fwdYieldVol: base.Quote, discountCurve: base.YieldTermStructure) -> None

Constructs with quote and term structure (handles created internally).

  1. __init__(yieldVolStructure: base.CallableBondVolatilityStructure, discountCurve: base.YieldTermStructure) -> None

Constructs with vol structure and term structure (handles created internally).

BlackCallableZeroCouponBondEngine

class pyquantlib.BlackCallableZeroCouponBondEngine

Bases: BlackCallableFixedRateBondEngine

Black-formula callable zero coupon bond engine.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(fwdYieldVol: base.Quote, discountCurve: base.YieldTermStructure) -> None

Constructs with quote and term structure (handles created internally).

  1. __init__(fwdYieldVol: QuoteHandle, discountCurve: YieldTermStructureHandle) -> None

Constructs with forward yield volatility quote handle and discount curve handle.

# Black engine requires exactly one call/put date
vol = ql.CallableBondConstantVolatility(today, 0.10, dc)
engine = ql.BlackCallableFixedRateBondEngine(vol, discount_curve)
bond.setPricingEngine(engine)
print(bond.cleanPrice())
print(bond.impliedVolatility(target_price, curve, 1e-8, 200, 0.001, 0.50))

Credit

CdsOption

class pyquantlib.CdsOption

Bases: Option

Option on a credit default swap.

__init__(swap: CreditDefaultSwap, exercise: Exercise, knocksOut: bool = True) None

Constructs a CDS option.

atmRate() float

Returns the at-the-money rate.

impliedVolatility(*args, **kwargs)

Overloaded function.

  1. impliedVolatility(price: SupportsFloat | SupportsIndex, termStructure: YieldTermStructureHandle, defaultProbTS: DefaultProbabilityTermStructureHandle, recoveryRate: SupportsFloat | SupportsIndex, accuracy: SupportsFloat | SupportsIndex = 0.0001, maxEvaluations: SupportsInt | SupportsIndex = 100, minVol: SupportsFloat | SupportsIndex = 1e-07, maxVol: SupportsFloat | SupportsIndex = 4.0) -> float

Returns the implied volatility.

  1. impliedVolatility(price: SupportsFloat | SupportsIndex, termStructure: base.YieldTermStructure, defaultProbTS: base.DefaultProbabilityTermStructure, recoveryRate: SupportsFloat | SupportsIndex, accuracy: SupportsFloat | SupportsIndex = 0.0001, maxEvaluations: SupportsInt | SupportsIndex = 100, minVol: SupportsFloat | SupportsIndex = 1e-07, maxVol: SupportsFloat | SupportsIndex = 4.0) -> float

Returns the implied volatility (handles created internally).

riskyAnnuity() float

Returns the risky annuity.

underlyingSwap() CreditDefaultSwap

Returns the underlying CDS.

BlackCdsOptionEngine

class pyquantlib.BlackCdsOptionEngine

Bases: PricingEngine

Black-formula CDS option engine.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(defaultProbTS: DefaultProbabilityTermStructureHandle, recoveryRate: SupportsFloat | SupportsIndex, termStructure: YieldTermStructureHandle, vol: QuoteHandle) -> None

Constructs the Black CDS option engine.

  1. __init__(defaultProbTS: base.DefaultProbabilityTermStructure, recoveryRate: SupportsFloat | SupportsIndex, termStructure: base.YieldTermStructure, vol: base.Quote) -> None

Constructs the Black CDS option engine (handles created internally).

termStructure() YieldTermStructureHandle

Returns the term structure handle.

volatility() QuoteHandle

Returns the volatility handle.

SVI Helper Functions

pyquantlib.sviTotalVariance(a: SupportsFloat | SupportsIndex, b: SupportsFloat | SupportsIndex, sigma: SupportsFloat | SupportsIndex, rho: SupportsFloat | SupportsIndex, m: SupportsFloat | SupportsIndex, k: SupportsFloat | SupportsIndex) float

Computes SVI total variance: a + b * (rho * (k - m) + sqrt((k - m)^2 + sigma^2)).

Parameters:
  • a – vertical translation

  • b – slope

  • sigma – ATM curvature

  • rho – rotation

  • m – horizontal translation

  • k – log-moneyness (log(K/F))

pyquantlib.checkSviParameters(a: SupportsFloat | SupportsIndex, b: SupportsFloat | SupportsIndex, sigma: SupportsFloat | SupportsIndex, rho: SupportsFloat | SupportsIndex, m: SupportsFloat | SupportsIndex, tte: SupportsFloat | SupportsIndex) None

Validates SVI parameters for no-arbitrage conditions.

Checks:
  • b >= 0

  • |rho| < 1

  • sigma > 0

  • a + b * sigma * sqrt(1 - rho^2) >= 0

  • b * (1 + |rho|) <= 4

# Compute total variance directly
k = 0.1  # log-moneyness
var = ql.sviTotalVariance(0.04, 0.1, 0.3, -0.4, 0.0, k)

# Validate parameters (raises on invalid)
ql.checkSviParameters(0.04, 0.1, 0.3, -0.4, 0.0, 1.0)