Instruments Module

Bonds

Bond

class pyquantlib.Bond

Bases: Instrument

Base class for bonds.

class engine

Bases: BondGenericEngine

Pricing engine for bonds.

__init__() None
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(settlementDays: SupportsInt | SupportsIndex, calendar: Calendar, issueDate: Date = <Date: null date>, coupons: collections.abc.Sequence[base.CashFlow] = []) -> None

Constructs from settlement days, calendar, issue date, and coupons.

  1. __init__(settlementDays: SupportsInt | SupportsIndex, calendar: Calendar, faceAmount: SupportsFloat | SupportsIndex, maturityDate: Date, issueDate: Date = <Date: null date>, cashflows: collections.abc.Sequence[base.CashFlow] = []) -> None

Constructs from settlement days, calendar, face amount, maturity, issue date, and cashflows.

accruedAmount(d: Date = <Date: null date>) float

Returns the accrued amount at date d.

bondYield(*args, **kwargs)

Overloaded function.

  1. bondYield(dayCounter: DayCounter, compounding: Compounding, frequency: Frequency, accuracy: SupportsFloat | SupportsIndex = 1e-08, maxEvaluations: SupportsInt | SupportsIndex = 100, guess: SupportsFloat | SupportsIndex = 0.05, priceType: BondPriceType = <BondPriceType.Clean: 1>) -> float

Calculates the yield from the engine price.

  1. bondYield(price: BondPrice, dayCounter: DayCounter, compounding: Compounding, frequency: Frequency, settlement: Date = <Date: null date>, accuracy: SupportsFloat | SupportsIndex = 1e-08, maxEvaluations: SupportsInt | SupportsIndex = 100, guess: SupportsFloat | SupportsIndex = 0.05) -> float

Calculates the yield from a given price.

calendar() Calendar

Returns the calendar.

cashflows() list[base.CashFlow]

Returns all cash flows.

cleanPrice(*args, **kwargs)

Overloaded function.

  1. cleanPrice() -> float

Returns the clean price (requires pricing engine).

  1. cleanPrice(yield: SupportsFloat | SupportsIndex, dayCounter: DayCounter, compounding: Compounding, frequency: Frequency, settlement: Date = <Date: null date>) -> float

Returns the clean price given a yield.

dirtyPrice(*args, **kwargs)

Overloaded function.

  1. dirtyPrice() -> float

Returns the dirty price (requires pricing engine).

  1. dirtyPrice(yield: SupportsFloat | SupportsIndex, dayCounter: DayCounter, compounding: Compounding, frequency: Frequency, settlement: Date = <Date: null date>) -> float

Returns the dirty price given a yield.

isExpired() bool

Returns True if the bond has expired.

isTradable(d: Date = <Date: null date>) bool

Returns True if the bond is tradable at date d.

issueDate() Date

Returns the issue date.

maturityDate() Date

Returns the maturity date.

nextCouponRate(d: Date = <Date: null date>) float

Returns the next coupon rate at date d.

notional(d: Date = <Date: null date>) float

Returns the notional amount at date d.

notionals() list[float]

Returns the notional amounts.

previousCouponRate(d: Date = <Date: null date>) float

Returns the previous coupon rate at date d.

redemption() base.CashFlow

Returns the single redemption cash flow.

redemptions() list[base.CashFlow]

Returns the redemption cash flows.

settlementDate(d: Date = <Date: null date>) Date

Returns the settlement date for trade date d.

settlementDays() int

Returns the number of settlement days.

settlementValue(*args, **kwargs)

Overloaded function.

  1. settlementValue() -> float

Returns the settlement value (requires pricing engine).

  1. settlementValue(cleanPrice: SupportsFloat | SupportsIndex) -> float

Returns the settlement value for a given clean price.

startDate() Date

Returns the start date.

ZeroCouponBond

class pyquantlib.ZeroCouponBond

Bases: Bond

Zero coupon bond.

__init__(settlementDays: SupportsInt | SupportsIndex, calendar: Calendar, faceAmount: SupportsFloat | SupportsIndex, maturityDate: Date, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, redemption: SupportsFloat | SupportsIndex = 100.0, issueDate: Date = <Date: null date>) None

Constructs a zero coupon bond.

bond = ql.ZeroCouponBond(2, ql.TARGET(), 100.0, maturity_date)
bond.setPricingEngine(ql.DiscountingBondEngine(curve_handle))
print(bond.cleanPrice())

FixedRateBond

class pyquantlib.FixedRateBond

Bases: Bond

Fixed rate bond.

__init__(settlementDays: typing.SupportsInt | typing.SupportsIndex, faceAmount: typing.SupportsFloat | typing.SupportsIndex, schedule: Schedule, coupons: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], accrualDayCounter: DayCounter, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, redemption: typing.SupportsFloat | typing.SupportsIndex = 100.0, issueDate: Date = <Date: null date>, paymentCalendar: object = None, exCouponPeriod: Period = <Period: 0D>, exCouponCalendar: object = None, exCouponConvention: BusinessDayConvention = <BusinessDayConvention.Unadjusted: 4>, exCouponEndOfMonth: bool = False, firstPeriodDayCounter: object = None) None

Constructs a fixed rate bond.

dayCounter() DayCounter

Returns the accrual day counter.

frequency() Frequency

Returns the coupon frequency.

bond = ql.FixedRateBond(2, 100.0, schedule, [0.05],
                         ql.Thirty360(ql.Thirty360.BondBasis))
bond.setPricingEngine(ql.DiscountingBondEngine(curve_handle))
print(bond.cleanPrice())
print(bond.bondYield(ql.Thirty360(ql.Thirty360.BondBasis),
                      ql.Compounded, ql.Annual))

FloatingRateBond

class pyquantlib.FloatingRateBond

Bases: Bond

Floating rate bond.

__init__(settlementDays: typing.SupportsInt | typing.SupportsIndex, faceAmount: typing.SupportsFloat | typing.SupportsIndex, schedule: Schedule, iborIndex: IborIndex, accrualDayCounter: DayCounter, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, fixingDays: object = None, gearings: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [1.0], spreads: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [0.0], caps: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [], floors: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [], inArrears: bool = False, redemption: typing.SupportsFloat | typing.SupportsIndex = 100.0, issueDate: Date = <Date: null date>, exCouponPeriod: Period = <Period: 0D>, exCouponCalendar: object = None, exCouponConvention: BusinessDayConvention = <BusinessDayConvention.Unadjusted: 4>, exCouponEndOfMonth: bool = False) None

Constructs a floating rate bond.

bond = ql.FloatingRateBond(2, 100.0, schedule, euribor6m,
                            ql.Actual360(), spreads=[0.005])
bond.setPricingEngine(ql.DiscountingBondEngine(curve_handle))
print(bond.cleanPrice())

AmortizingFixedRateBond

class pyquantlib.AmortizingFixedRateBond

Bases: Bond

Amortizing fixed-rate bond.

__init__(settlementDays: typing.SupportsInt | typing.SupportsIndex, notionals: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], schedule: Schedule, coupons: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], accrualDayCounter: DayCounter, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, issueDate: Date = <Date: null date>, exCouponPeriod: Period = <Period: 0D>, exCouponCalendar: object = None, exCouponConvention: BusinessDayConvention = <BusinessDayConvention.Unadjusted: 4>, exCouponEndOfMonth: bool = False, redemptions: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [100.0], paymentLag: typing.SupportsInt | typing.SupportsIndex = 0) None

Constructs an amortizing fixed-rate bond.

dayCounter() DayCounter

Returns the accrual day counter.

frequency() Frequency

Returns the coupon frequency.

notionals = ql.sinkingNotionals(ql.Period(5, ql.Years), ql.Annual, 0.05, 100.0)
schedule = ql.sinkingSchedule(issue_date, ql.Period(5, ql.Years), ql.Annual, ql.TARGET())
bond = ql.AmortizingFixedRateBond(2, notionals, schedule, [0.05],
                                   ql.Thirty360(ql.Thirty360.BondBasis))

sinkingSchedule

pyquantlib.sinkingSchedule(startDate: Date, bondLength: Period, frequency: Frequency, paymentCalendar: Calendar) Schedule

Returns a schedule for French amortization.

sinkingNotionals

pyquantlib.sinkingNotionals(bondLength: Period, frequency: Frequency, couponRate: SupportsFloat | SupportsIndex, initialNotional: SupportsFloat | SupportsIndex) list[float]

Returns notionals for French amortization.

AmortizingFloatingRateBond

class pyquantlib.AmortizingFloatingRateBond

Bases: Bond

Amortizing floating-rate bond.

__init__(settlementDays: typing.SupportsInt | typing.SupportsIndex, notionals: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], schedule: Schedule, index: IborIndex, accrualDayCounter: DayCounter, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, fixingDays: object = None, gearings: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [1.0], spreads: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [0.0], caps: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [], floors: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [], inArrears: bool = False, issueDate: Date = <Date: null date>, exCouponPeriod: Period = <Period: 0D>, exCouponCalendar: object = None, exCouponConvention: BusinessDayConvention = <BusinessDayConvention.Unadjusted: 4>, exCouponEndOfMonth: bool = False, redemptions: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [100.0], paymentLag: typing.SupportsInt | typing.SupportsIndex = 0) None

Constructs an amortizing floating-rate bond.

CmsRateBond

class pyquantlib.CmsRateBond

Bases: Bond

CMS-rate bond.

__init__(settlementDays: typing.SupportsInt | typing.SupportsIndex, faceAmount: typing.SupportsFloat | typing.SupportsIndex, schedule: Schedule, index: SwapIndex, paymentDayCounter: DayCounter, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, fixingDays: object = None, gearings: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [1.0], spreads: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [0.0], caps: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [], floors: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex] = [], inArrears: bool = False, redemption: typing.SupportsFloat | typing.SupportsIndex = 100.0, issueDate: Date = <Date: null date>) None

Constructs a CMS-rate bond.

CPIBond

class pyquantlib.CPIBond

Bases: Bond

CPI inflation-linked bond.

__init__(settlementDays: typing.SupportsInt | typing.SupportsIndex, faceAmount: typing.SupportsFloat | typing.SupportsIndex, baseCPI: typing.SupportsFloat | typing.SupportsIndex, observationLag: Period, cpiIndex: ZeroInflationIndex, observationInterpolation: CPI.InterpolationType, schedule: Schedule, coupons: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], accrualDayCounter: DayCounter, paymentConvention: BusinessDayConvention = <BusinessDayConvention.ModifiedFollowing: 1>, issueDate: Date = <Date: null date>, paymentCalendar: object = None, exCouponPeriod: Period = <Period: 0D>, exCouponCalendar: object = None, exCouponConvention: BusinessDayConvention = <BusinessDayConvention.Unadjusted: 4>, exCouponEndOfMonth: bool = False) None

Constructs a CPI inflation-linked bond.

baseCPI() float

Returns the base CPI value.

cpiIndex() ZeroInflationIndex

Returns the CPI index.

dayCounter() DayCounter

Returns the accrual day counter.

frequency() Frequency

Returns the coupon frequency.

growthOnly() bool

Returns true if the bond pays growth only.

observationInterpolation() CPI.InterpolationType

Returns the observation interpolation type.

observationLag() Period

Returns the observation lag.

bond = ql.CPIBond(2, 100.0, 315.0, ql.Period(3, ql.Months),
                   cpi_index, ql.CPI.Flat, schedule, [0.02],
                   ql.Actual365Fixed())

Callable Bonds

Callability

class pyquantlib.Callability

Bases: Event

Instrument callability (call or put) at a given date.

__init__(price: BondPrice, type: CallabilityType, date: Date) None

Constructs a callability.

date() Date

Returns the call/put date.

price() BondPrice

Returns the call/put price.

type() CallabilityType

Returns the callability type (Call or Put).

class pyquantlib.CallabilityType

Bases: pybind11_object

Callability type: Call or Put.

Members:

Call

Put

__init__(value: SupportsInt | SupportsIndex) None
Call = <CallabilityType.Call: 0>
Put = <CallabilityType.Put: 1>
CallabilityType.name -> str
property value

Value

Description

Call

Issuer can call (redeem early)

Put

Holder can put (sell back early)

call_price = ql.BondPrice(100.0, ql.BondPriceType.Clean)
call = ql.Callability(call_price, ql.CallabilityType.Call,
                       ql.Date(15, ql.June, 2030))

CallableFixedRateBond

class pyquantlib.CallableFixedRateBond

Bases: CallableBond

Callable/puttable fixed rate bond.

__init__(settlementDays: typing.SupportsInt | typing.SupportsIndex, faceAmount: typing.SupportsFloat | typing.SupportsIndex, schedule: Schedule, coupons: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], accrualDayCounter: DayCounter, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, redemption: typing.SupportsFloat | typing.SupportsIndex = 100.0, issueDate: Date = <Date: null date>, putCallSchedule: collections.abc.Sequence[Callability] = []) None

Constructs a callable fixed rate bond.

call_schedule = [
    ql.Callability(ql.BondPrice(100.0, ql.BondPriceType.Clean),
                    ql.CallabilityType.Call, call_date)
    for call_date in call_dates
]
bond = ql.CallableFixedRateBond(2, 100.0, schedule, [0.05],
                                 ql.Actual365Fixed(),
                                 putCallSchedule=call_schedule)
bond.setPricingEngine(ql.TreeCallableFixedRateBondEngine(hw_model, 100))
print(bond.cleanPrice())
print(bond.OAS(clean_price, curve, dc, ql.Continuous, ql.Annual))

CallableZeroCouponBond

class pyquantlib.CallableZeroCouponBond

Bases: CallableBond

Callable/puttable zero coupon bond.

__init__(settlementDays: SupportsInt | SupportsIndex, faceAmount: SupportsFloat | SupportsIndex, calendar: Calendar, maturityDate: Date, dayCounter: DayCounter, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, redemption: SupportsFloat | SupportsIndex = 100.0, issueDate: Date = <Date: null date>, putCallSchedule: collections.abc.Sequence[Callability] = []) None

Constructs a callable zero coupon bond.

Convertible Bonds

SoftCallability

class pyquantlib.SoftCallability

Bases: Callability

Callability with a trigger level for soft-call provisions.

__init__(price: BondPrice, date: Date, trigger: SupportsFloat | SupportsIndex) None

Constructs a soft callability with price, date, and trigger.

trigger() float

Returns the trigger level.

Callability with a trigger level for soft-call provisions.

soft_call = ql.SoftCallability(
    ql.BondPrice(110.0, ql.BondPriceType.Clean),
    call_date, 1.20,
)

ConvertibleBond

class pyquantlib.ConvertibleBond

Bases: Bond

Base class for convertible bonds.

__init__(*args, **kwargs)
callability() list[Callability]

Returns the callability schedule.

conversionRatio() float

Returns the conversion ratio.

Base class for convertible bonds (not directly constructible).

ConvertibleZeroCouponBond

class pyquantlib.ConvertibleZeroCouponBond

Bases: ConvertibleBond

Convertible zero-coupon bond.

__init__(exercise: Exercise, conversionRatio: SupportsFloat | SupportsIndex, callability: collections.abc.Sequence[Callability], issueDate: Date, settlementDays: SupportsInt | SupportsIndex, dayCounter: DayCounter, schedule: Schedule, redemption: SupportsFloat | SupportsIndex = 100.0) None

Constructs a convertible zero-coupon bond.

exercise = ql.AmericanExercise(today, maturity)
bond = ql.ConvertibleZeroCouponBond(
    exercise, 1.0, [], issue_date, 2,
    ql.Actual365Fixed(), schedule,
)
bond.setPricingEngine(ql.BinomialConvertibleEngine(process, "crr", 801))
print(bond.NPV())

ConvertibleFixedCouponBond

class pyquantlib.ConvertibleFixedCouponBond

Bases: ConvertibleBond

Convertible fixed-coupon bond.

__init__(exercise: Exercise, conversionRatio: typing.SupportsFloat | typing.SupportsIndex, callability: collections.abc.Sequence[Callability], issueDate: Date, settlementDays: typing.SupportsInt | typing.SupportsIndex, coupons: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], dayCounter: DayCounter, schedule: Schedule, redemption: typing.SupportsFloat | typing.SupportsIndex = 100.0, exCouponPeriod: Period = <Period: 0D>, exCouponCalendar: object = None, exCouponConvention: BusinessDayConvention = <BusinessDayConvention.Unadjusted: 4>, exCouponEndOfMonth: bool = False) None

Constructs a convertible fixed-coupon bond.

bond = ql.ConvertibleFixedCouponBond(
    exercise, 1.0, call_schedule, issue_date, 2,
    [0.05], ql.Thirty360(ql.Thirty360.BondBasis), schedule,
)

ConvertibleFloatingRateBond

class pyquantlib.ConvertibleFloatingRateBond

Bases: ConvertibleBond

Convertible floating-rate bond.

__init__(exercise: Exercise, conversionRatio: typing.SupportsFloat | typing.SupportsIndex, callability: collections.abc.Sequence[Callability], issueDate: Date, settlementDays: typing.SupportsInt | typing.SupportsIndex, index: IborIndex, fixingDays: typing.SupportsInt | typing.SupportsIndex, spreads: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex], dayCounter: DayCounter, schedule: Schedule, redemption: typing.SupportsFloat | typing.SupportsIndex = 100.0, exCouponPeriod: Period = <Period: 0D>, exCouponCalendar: object = None, exCouponConvention: BusinessDayConvention = <BusinessDayConvention.Unadjusted: 4>, exCouponEndOfMonth: bool = False) None

Constructs a convertible floating-rate bond.

bond = ql.ConvertibleFloatingRateBond(
    exercise, 1.0, [], issue_date, 2,
    euribor6m, 2, [0.005], ql.Actual360(), schedule,
)

EquityTotalReturnSwap

class pyquantlib.EquityTotalReturnSwap

Bases: Swap

Equity total return swap.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(type: SwapType, nominal: SupportsFloat | SupportsIndex, schedule: Schedule, equityIndex: EquityIndex, interestRateIndex: IborIndex, dayCounter: DayCounter, margin: SupportsFloat | SupportsIndex, gearing: SupportsFloat | SupportsIndex = 1.0, paymentCalendar: object = None, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Unadjusted: 4>, paymentDelay: SupportsInt | SupportsIndex = 0) -> None

Constructs an equity TRS with an IBOR interest rate leg.

  1. __init__(type: SwapType, nominal: SupportsFloat | SupportsIndex, schedule: Schedule, equityIndex: EquityIndex, interestRateIndex: OvernightIndex, dayCounter: DayCounter, margin: SupportsFloat | SupportsIndex, gearing: SupportsFloat | SupportsIndex = 1.0, paymentCalendar: object = None, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Unadjusted: 4>, paymentDelay: SupportsInt | SupportsIndex = 0) -> None

Constructs an equity TRS with an overnight interest rate leg.

dayCounter() DayCounter

Returns the day counter.

equityIndex() EquityIndex

Returns the equity index.

equityLeg() list[base.CashFlow]

Returns the equity leg.

equityLegNPV() float

Returns the NPV of the equity leg.

fairMargin() float

Returns the fair margin.

gearing() float

Returns the gearing factor.

interestRateIndex() base.InterestRateIndex

Returns the interest rate index.

interestRateLeg() list[base.CashFlow]

Returns the interest rate leg.

interestRateLegNPV() float

Returns the NPV of the interest rate leg.

margin() float

Returns the floating leg margin.

nominal() float

Returns the notional amount.

paymentCalendar() Calendar

Returns the payment calendar.

paymentConvention() BusinessDayConvention

Returns the payment business day convention.

paymentDelay() int

Returns the payment delay in days.

schedule() Schedule

Returns the payment schedule.

type() SwapType

Returns the swap type (Payer or Receiver).

Equity total return swap: equity leg vs interest rate leg.

trs = ql.EquityTotalReturnSwap(
    ql.SwapType.Payer, 1_000_000.0, schedule,
    equity_index, ibor_index, ql.Actual360(), 0.005,
)
trs.setPricingEngine(ql.DiscountingSwapEngine(curve))
print(trs.NPV())
print(trs.fairMargin())

Swaps

VanillaSwap

class pyquantlib.VanillaSwap

Bases: FixedVsFloatingSwap

Plain vanilla swap: fixed vs IBOR floating leg.

__init__(type: SwapType, nominal: SupportsFloat | SupportsIndex, fixedSchedule: Schedule, fixedRate: SupportsFloat | SupportsIndex, fixedDayCount: DayCounter, floatSchedule: Schedule, iborIndex: IborIndex, spread: SupportsFloat | SupportsIndex, floatingDayCount: DayCounter, paymentConvention: BusinessDayConvention | None = None, useIndexedCoupons: bool | None = None) None

Constructs a vanilla swap.

MakeVanillaSwap

class pyquantlib.MakeVanillaSwap(swapTenor, iborIndex, fixedRate=None, forwardStart=None, **kwargs)[source]

Bases:

Build a VanillaSwap from keyword arguments.

Parameters:
  • swapTenor (Period) – Tenor of the swap.

  • iborIndex (IborIndex) – The floating rate index.

  • fixedRate (float, optional) – Fixed rate. None for par rate.

  • forwardStart (Period, optional) – Forward start period.

  • **kwargs – Builder options mapped to with* methods (e.g. nominal, pricingEngine, fixedLegDayCount, floatingLegSpread, …).

Return type:

VanillaSwap

Pythonic builder for VanillaSwap. Constructor arguments are positional; builder options are keyword arguments.

swap = ql.MakeVanillaSwap(
    ql.Period(5, ql.Years), euribor6m, 0.04,
    nominal=10_000_000.0,
    fixedLegDayCount=ql.Thirty360(ql.Thirty360.BondBasis),
    floatingLegSpread=0.001,
)

OvernightIndexedSwap

class pyquantlib.OvernightIndexedSwap

Bases: FixedVsFloatingSwap

Overnight indexed swap: fixed vs overnight floating leg.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(type: SwapType, nominal: SupportsFloat | SupportsIndex, schedule: Schedule, fixedRate: SupportsFloat | SupportsIndex, fixedDC: DayCounter, overnightIndex: OvernightIndex, spread: SupportsFloat | SupportsIndex = 0.0, paymentLag: SupportsInt | SupportsIndex = 0, paymentAdjustment: BusinessDayConvention = <BusinessDayConvention.Following: 0>, telescopicValueDates: bool = False, averagingMethod: RateAveraging.Type = <Type.Compound: 1>) -> None

Constructs an overnight indexed swap.

  1. __init__(type: SwapType, nominal: SupportsFloat | SupportsIndex, fixedSchedule: Schedule, fixedRate: SupportsFloat | SupportsIndex, fixedDC: DayCounter, overnightSchedule: Schedule, overnightIndex: OvernightIndex, spread: SupportsFloat | SupportsIndex = 0.0, paymentLag: SupportsInt | SupportsIndex = 0, paymentAdjustment: BusinessDayConvention = <BusinessDayConvention.Following: 0>, telescopicValueDates: bool = False, averagingMethod: RateAveraging.Type = <Type.Compound: 1>) -> None

Constructs an OIS with separate fixed and overnight schedules.

averagingMethod() RateAveraging.Type

Returns the rate averaging method.

overnightIndex() object

Returns the overnight index.

overnightLeg() list[base.CashFlow]

Returns the overnight leg cash flows.

overnightLegBPS() float

Returns the BPS of the overnight leg.

overnightLegNPV() float

Returns the NPV of the overnight leg.

Overnight indexed swap: fixed vs overnight floating leg.

sofr = ql.Sofr(curve)
ois = ql.OvernightIndexedSwap(
    ql.SwapType.Receiver, 1_000_000.0, schedule,
    0.035, ql.Actual360(), sofr,
)
ois.setPricingEngine(ql.DiscountingSwapEngine(curve))
print(ois.NPV())
print(ois.fairRate())

ZeroCouponSwap

class pyquantlib.ZeroCouponSwap

Bases: Swap

Zero-coupon interest rate swap.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(type: SwapType, baseNominal: SupportsFloat | SupportsIndex, startDate: Date, maturityDate: Date, fixedPayment: SupportsFloat | SupportsIndex, iborIndex: IborIndex, paymentCalendar: Calendar, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, paymentDelay: SupportsInt | SupportsIndex = 0) -> None

Constructs from fixed payment amount.

  1. __init__(type: SwapType, baseNominal: SupportsFloat | SupportsIndex, startDate: Date, maturityDate: Date, fixedRate: SupportsFloat | SupportsIndex, fixedDayCounter: DayCounter, iborIndex: IborIndex, paymentCalendar: Calendar, paymentConvention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, paymentDelay: SupportsInt | SupportsIndex = 0) -> None

Constructs from fixed rate.

baseNominal() float

Base notional amount.

fairFixedPayment() float

Fair fixed payment amount.

fairFixedRate(dayCounter: DayCounter) float

Fair fixed rate for a given day counter.

fixedLeg() list[base.CashFlow]

Fixed leg.

fixedLegNPV() float

NPV of the fixed leg.

fixedPayment() float

Fixed payment amount.

floatingLeg() list[base.CashFlow]

Floating leg.

floatingLegNPV() float

NPV of the floating leg.

iborIndex() IborIndex

Ibor index.

maturityDate() Date

Maturity date.

startDate() Date

Start date.

type() SwapType

Swap type (payer or receiver).

Zero-coupon swap: single fixed payment vs floating leg.

swap = ql.ZeroCouponSwap(
    ql.SwapType.Receiver, 1_000_000.0, start_date, maturity_date,
    0.04, ql.Actual365Fixed(), schedule, euribor6m,
)
swap.setPricingEngine(ql.DiscountingSwapEngine(curve))
print(swap.NPV())
print(swap.fairFixedPayment(curve))

AssetSwap

class pyquantlib.AssetSwap

Bases: Swap

Bullet bond vs Libor swap.

__init__(payBondCoupon: bool, bond: Bond, bondCleanPrice: SupportsFloat | SupportsIndex, iborIndex: IborIndex, spread: SupportsFloat | SupportsIndex, floatSchedule: Schedule = <Schedule object at 0x7f253434a330>, floatingDayCount: object = None, parAssetSwap: bool = True) None

Constructs an asset swap.

bond() Bond

Underlying bond.

bondLeg() list[base.CashFlow]

Bond leg.

cleanPrice() float

Clean price.

fairCleanPrice() float

Fair clean price.

fairNonParRepayment() float

Fair non-par repayment.

fairSpread() float

Fair spread.

floatingLeg() list[base.CashFlow]

Floating leg.

floatingLegBPS() float

Floating leg BPS.

floatingLegNPV() float

Floating leg NPV.

nonParRepayment() float

Non-par repayment.

parSwap() bool

Whether this is a par swap.

payBondCoupon() bool

Whether bond coupons are paid.

spread() float

Spread.

Asset swap exchanging a bond for a floating rate leg.

asset_swap = ql.AssetSwap(False, bond, 100.0, schedule, euribor6m, 0.0)
asset_swap.setPricingEngine(ql.DiscountingSwapEngine(curve))
print(asset_swap.NPV())
print(asset_swap.fairSpread())

Caps, Floors, and Collars

CapFloor

class pyquantlib.CapFloor

Bases: Instrument

Interest rate cap, floor, or collar.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(type: CapFloorType, floatingLeg: collections.abc.Sequence[base.CashFlow], capRates: collections.abc.Sequence[SupportsFloat | SupportsIndex], floorRates: collections.abc.Sequence[SupportsFloat | SupportsIndex]) -> None

Constructs a cap/floor/collar.

  1. __init__(type: CapFloorType, floatingLeg: collections.abc.Sequence[base.CashFlow], strikes: collections.abc.Sequence[SupportsFloat | SupportsIndex]) -> None

Constructs a cap or floor with uniform strikes.

atmRate(discountCurve: base.YieldTermStructure) float

Returns the ATM rate.

capRates() list[float]

Returns the cap rates.

floatingLeg() list[base.CashFlow]

Returns the floating leg.

floorRates() list[float]

Returns the floor rates.

impliedVolatility(price: SupportsFloat | SupportsIndex, discountCurve: YieldTermStructureHandle, guess: SupportsFloat | SupportsIndex, accuracy: SupportsFloat | SupportsIndex = 0.0001, maxEvaluations: SupportsInt | SupportsIndex = 100, minVol: SupportsFloat | SupportsIndex = 1e-07, maxVol: SupportsFloat | SupportsIndex = 4.0, type: VolatilityType = <VolatilityType.ShiftedLognormal: 0>, displacement: SupportsFloat | SupportsIndex = 0.0) float

Returns the implied volatility.

isExpired() bool

Returns True if expired.

maturityDate() Date

Returns the maturity date.

startDate() Date

Returns the start date.

type() CapFloorType

Returns the cap/floor type.

Cap

class pyquantlib.Cap

Bases: CapFloor

Interest rate cap.

__init__(floatingLeg: collections.abc.Sequence[base.CashFlow], exerciseRates: collections.abc.Sequence[SupportsFloat | SupportsIndex]) None

Constructs a cap.

Floor

class pyquantlib.Floor

Bases: CapFloor

Interest rate floor.

__init__(floatingLeg: collections.abc.Sequence[base.CashFlow], exerciseRates: collections.abc.Sequence[SupportsFloat | SupportsIndex]) None

Constructs a floor.

Collar

class pyquantlib.Collar

Bases: CapFloor

Interest rate collar.

__init__(floatingLeg: collections.abc.Sequence[base.CashFlow], capRates: collections.abc.Sequence[SupportsFloat | SupportsIndex], floorRates: collections.abc.Sequence[SupportsFloat | SupportsIndex]) None

Constructs a collar.

leg = ql.IborLeg(schedule, euribor).withNotionals([1_000_000.0]).build()

cap = ql.Cap(leg, [0.05])
floor = ql.Floor(leg, [0.03])
collar = ql.Collar(leg, [0.05], [0.03])

cap.setPricingEngine(ql.BlackCapFloorEngine(curve, 0.20))
print(cap.NPV())
print(cap.impliedVolatility(cap.NPV(), curve_handle, 0.20))

Forward Rate Agreement

ForwardRateAgreement

class pyquantlib.ForwardRateAgreement

Bases: Instrument

Forward rate agreement (FRA).

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(index: IborIndex, valueDate: Date, type: PositionType, strikeForwardRate: SupportsFloat | SupportsIndex, notionalAmount: SupportsFloat | SupportsIndex, discountCurve: YieldTermStructureHandle = <YieldTermStructureHandle object at 0x7f2534368530>) -> None

Constructs FRA using indexed coupon.

  1. __init__(index: IborIndex, valueDate: Date, type: PositionType, strikeForwardRate: SupportsFloat | SupportsIndex, notionalAmount: SupportsFloat | SupportsIndex, discountCurve: base.YieldTermStructure) -> None

Constructs FRA with term structure (handle created internally).

  1. __init__(index: IborIndex, valueDate: Date, maturityDate: Date, type: PositionType, strikeForwardRate: SupportsFloat | SupportsIndex, notionalAmount: SupportsFloat | SupportsIndex, discountCurve: YieldTermStructureHandle = <YieldTermStructureHandle object at 0x7f25341d14f0>) -> None

Constructs FRA using par-rate approximation.

amount() float

Returns the payoff on the value date.

businessDayConvention() BusinessDayConvention

Returns the business day convention.

calendar() Calendar

Returns the calendar.

dayCounter() DayCounter

Returns the day counter.

fixingDate() Date

Returns the fixing date.

forwardRate() InterestRate

Returns the market forward rate.

isExpired() bool

Returns True if expired.

fra = ql.ForwardRateAgreement(
    euribor, value_date, ql.PositionType.Long,
    0.04, 1_000_000.0, curve,
)
print(fra.NPV())
print(fra.forwardRate())

Swaptions

Swaption

class pyquantlib.Swaption

Bases: Option

Option to enter into an interest rate swap.

class engine

Bases: SwaptionGenericEngine

Base class for swaption pricing engines.

__init__() None
__init__(swap: FixedVsFloatingSwap, exercise: Exercise, delivery: SettlementType = <SettlementType.Physical: 0>, settlementMethod: SettlementMethod = <SettlementMethod.PhysicalOTC: 0>) None

Constructs a swaption.

impliedVolatility(price: SupportsFloat | SupportsIndex, discountCurve: YieldTermStructureHandle, guess: SupportsFloat | SupportsIndex, accuracy: SupportsFloat | SupportsIndex = 0.0001, maxEvaluations: SupportsInt | SupportsIndex = 100, minVol: SupportsFloat | SupportsIndex = 1e-07, maxVol: SupportsFloat | SupportsIndex = 4.0, type: VolatilityType = <VolatilityType.ShiftedLognormal: 0>, displacement: SupportsFloat | SupportsIndex = 0.0, priceType: SwaptionPriceType = <SwaptionPriceType.Spot: 0>) float

Returns the implied volatility.

isExpired() bool

Returns True if the swaption has expired.

settlementMethod() SettlementMethod

Returns the settlement method.

settlementType() SettlementType

Returns the settlement type.

type() SwapType

Returns the underlying swap type.

underlying() FixedVsFloatingSwap

Returns the underlying swap.

MakeSwaption

class pyquantlib.MakeSwaption(swapIndex, optionTenor, strike=None, **kwargs)[source]

Bases:

Build a Swaption from keyword arguments.

Parameters:
  • swapIndex (SwapIndex) – The swap index.

  • optionTenor (Period or Date) – Option tenor (Period) or fixing date (Date).

  • strike (float, optional) – Strike rate. None for ATM.

  • **kwargs – Builder options mapped to with* methods (e.g. nominal, pricingEngine, settlementType, …).

Return type:

Swaption

Pythonic builder for Swaption. Constructor arguments are positional; builder options are keyword arguments.

swap_index = ql.EuriborSwapIsdaFixA(ql.Period(5, ql.Years), curve, curve)
swaption = ql.MakeSwaption(
    swap_index, ql.Period(1, ql.Years), 0.04,
    pricingEngine=engine,
)

Composite Instruments

CompositeInstrument

class pyquantlib.CompositeInstrument

Bases: Instrument

Aggregate of instruments with weighted NPVs.

__init__() None

Constructs an empty composite instrument.

add(instrument: base.Instrument, multiplier: SupportsFloat | SupportsIndex = 1.0) None

Adds an instrument with a multiplier.

isExpired() bool

Returns whether all components are expired.

subtract(instrument: base.Instrument, multiplier: SupportsFloat | SupportsIndex = 1.0) None

Subtracts an instrument with a multiplier.

Instrument composed of weighted sub-instruments.

composite = ql.CompositeInstrument()
composite.add(option1)           # weight = 1.0
composite.add(option2)
composite.subtract(option3)      # weight = -1.0
composite.add(option4, 0.5)      # weight = 0.5
print(composite.NPV())

Credit Instruments

Claims

class pyquantlib.FaceValueClaim

Bases: Claim

Claim on a notional.

__init__() None

Constructs a face value claim.

class pyquantlib.FaceValueAccrualClaim

Bases: Claim

Claim on the notional of a reference security, including accrual.

__init__(referenceSecurity: Bond) None

Constructs from a reference bond.

Claim objects define the loss amount on a default event. FaceValueClaim returns notional * (1 - recoveryRate). FaceValueAccrualClaim adds accrued interest from a reference bond.

claim = ql.FaceValueClaim()
loss = claim.amount(default_date, 1_000_000.0, 0.4)  # 600,000

CreditDefaultSwap

class pyquantlib.CreditDefaultSwap

Bases: Instrument

Credit default swap.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(side: ProtectionSide, notional: SupportsFloat | SupportsIndex, spread: SupportsFloat | SupportsIndex, schedule: Schedule, paymentConvention: BusinessDayConvention, dayCounter: DayCounter, settlesAccrual: bool = True, paysAtDefaultTime: bool = True, protectionStart: Date = <Date: null date>, claim: base.Claim = None, lastPeriodDayCounter: object = None, rebatesAccrual: bool = True, tradeDate: Date = <Date: null date>, cashSettlementDays: SupportsInt | SupportsIndex = 3) -> None

Constructs CDS quoted as running spread only.

  1. __init__(side: ProtectionSide, notional: SupportsFloat | SupportsIndex, upfront: SupportsFloat | SupportsIndex, spread: SupportsFloat | SupportsIndex, schedule: Schedule, paymentConvention: BusinessDayConvention, dayCounter: DayCounter, settlesAccrual: bool = True, paysAtDefaultTime: bool = True, protectionStart: Date = <Date: null date>, upfrontDate: Date = <Date: null date>, claim: base.Claim = None, lastPeriodDayCounter: object = None, rebatesAccrual: bool = True, tradeDate: Date = <Date: null date>, cashSettlementDays: SupportsInt | SupportsIndex = 3) -> None

Constructs CDS quoted as upfront and running spread.

accrualRebateNPV() float

Accrual rebate NPV.

conventionalSpread(conventionalRecovery: SupportsFloat | SupportsIndex, discountCurve: YieldTermStructureHandle, dayCounter: DayCounter, model: CdsPricingModel = <CdsPricingModel.Midpoint: 0>) float

Conventional spread.

couponLegBPS() float

Coupon leg BPS.

couponLegNPV() float

Coupon leg NPV.

coupons() list[base.CashFlow]

Coupon leg.

defaultLegNPV() float

Default leg NPV.

fairSpread() float

Fair running spread.

fairUpfront() float

Fair upfront.

impliedHazardRate(targetNPV: SupportsFloat | SupportsIndex, discountCurve: YieldTermStructureHandle, dayCounter: DayCounter, recoveryRate: SupportsFloat | SupportsIndex = 0.4, accuracy: SupportsFloat | SupportsIndex = 1e-08, model: CdsPricingModel = <CdsPricingModel.Midpoint: 0>) float

Implied hazard rate.

isExpired() bool

Whether the CDS has expired.

notional() float

Notional.

paysAtDefaultTime() bool

Whether default payment is at default time.

protectionEndDate() Date

Protection end date.

protectionStartDate() Date

Protection start date.

rebatesAccrual() bool

Whether accrual is rebated.

runningSpread() float

Running spread.

settlesAccrual() bool

Whether accrual is settled on default.

side() ProtectionSide

Protection side.

upfrontBPS() float

Upfront BPS.

upfrontNPV() float

Upfront NPV.

Credit default swap quoted as running spread or upfront + spread.

cds = ql.CreditDefaultSwap(
    ql.ProtectionSide.Buyer, 10_000_000.0, 0.01,
    schedule, ql.Following, ql.Actual360(),
)
cds.setPricingEngine(ql.MidPointCdsEngine(
    default_curve, 0.4, discount_curve,
))
print(cds.NPV())
print(cds.fairSpread())

cdsMaturity

pyquantlib.cdsMaturity(tradeDate: Date, tenor: Period, rule: DateGeneration.Rule) Date

CDS maturity date from trade date and tenor.

Inflation Swaps

ZeroCouponInflationSwap

class pyquantlib.ZeroCouponInflationSwap

Bases: Swap

Zero-coupon inflation swap.

__init__(type: SwapType, nominal: SupportsFloat | SupportsIndex, startDate: Date, maturity: Date, fixCalendar: Calendar, fixConvention: BusinessDayConvention, dayCounter: DayCounter, fixedRate: SupportsFloat | SupportsIndex, infIndex: ZeroInflationIndex, observationLag: Period, observationInterpolation: CPI.InterpolationType, adjustInfObsDates: bool = False, infCalendar: object = None, infConvention: object = None) None

Constructs a zero-coupon inflation swap.

adjustObservationDates() bool

Returns whether observation dates are adjusted.

dayCounter() DayCounter

Returns the day counter.

fairRate() float

Returns the fair fixed rate.

fixedCalendar() Calendar

Returns the fixed-leg calendar.

fixedConvention() BusinessDayConvention

Returns the fixed-leg business day convention.

fixedLeg() list[base.CashFlow]

Returns the fixed leg.

fixedLegNPV() float

Returns the fixed leg NPV.

fixedRate() float

Returns the fixed rate.

inflationCalendar() Calendar

Returns the inflation calendar.

inflationConvention() BusinessDayConvention

Returns the inflation business day convention.

inflationIndex() ZeroInflationIndex

Returns the inflation index.

inflationLeg() list[base.CashFlow]

Returns the inflation leg.

inflationLegNPV() float

Returns the inflation leg NPV.

nominal() float

Returns the nominal.

observationInterpolation() CPI.InterpolationType

Returns the observation interpolation type.

observationLag() Period

Returns the observation lag.

type() SwapType

Returns the swap type.

Zero-coupon inflation swap: fixed rate vs zero-coupon inflation leg.

YearOnYearInflationSwap

class pyquantlib.YearOnYearInflationSwap

Bases: Swap

Year-on-year inflation swap.

__init__(type: SwapType, nominal: SupportsFloat | SupportsIndex, fixedSchedule: Schedule, fixedRate: SupportsFloat | SupportsIndex, fixedDayCount: DayCounter, yoySchedule: Schedule, yoyIndex: YoYInflationIndex, observationLag: Period, interpolation: CPI.InterpolationType, spread: SupportsFloat | SupportsIndex, yoyDayCount: DayCounter, paymentCalendar: Calendar, paymentConvention: BusinessDayConvention = <BusinessDayConvention.ModifiedFollowing: 1>) None

Constructs a year-on-year inflation swap.

fairRate() float

Returns the fair fixed rate.

fairSpread() float

Returns the fair spread.

fixedDayCount() DayCounter

Returns the fixed-leg day counter.

fixedLeg() list[base.CashFlow]

Returns the fixed leg.

fixedLegNPV() float

Returns the fixed-leg NPV.

fixedRate() float

Returns the fixed rate.

fixedSchedule() Schedule

Returns the fixed schedule.

nominal() float

Returns the nominal.

observationLag() Period

Returns the observation lag.

paymentCalendar() Calendar

Returns the payment calendar.

paymentConvention() BusinessDayConvention

Returns the payment convention.

spread() float

Returns the spread.

type() SwapType

Returns the swap type.

yoyDayCount() DayCounter

Returns the YoY-leg day counter.

yoyInflationIndex() YoYInflationIndex

Returns the YoY inflation index.

yoyLeg() list[base.CashFlow]

Returns the YoY leg.

yoyLegNPV() float

Returns the YoY-leg NPV.

yoySchedule() Schedule

Returns the YoY schedule.

Year-on-year inflation swap: fixed rate vs YoY inflation leg.

YoY Inflation Caps, Floors, and Collars

YoYInflationCapFloor

class pyquantlib.YoYInflationCapFloor

Bases: Instrument

YoY inflation cap, floor, or collar.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(type: YoYInflationCapFloorType, yoyLeg: collections.abc.Sequence[base.CashFlow], capRates: collections.abc.Sequence[SupportsFloat | SupportsIndex], floorRates: collections.abc.Sequence[SupportsFloat | SupportsIndex]) -> None

Constructs a YoY inflation cap/floor/collar.

  1. __init__(type: YoYInflationCapFloorType, yoyLeg: collections.abc.Sequence[base.CashFlow], strikes: collections.abc.Sequence[SupportsFloat | SupportsIndex]) -> None

Constructs a YoY inflation cap or floor with uniform strikes.

atmRate(discountCurve: base.YieldTermStructure) float

Returns the ATM rate.

capRates() list[float]

Returns the cap rates.

floorRates() list[float]

Returns the floor rates.

impliedVolatility(price: SupportsFloat | SupportsIndex, yoyCurve: YoYInflationTermStructureHandle, guess: 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.

isExpired() bool

Returns True if expired.

lastYoYInflationCoupon() YoYInflationCoupon

Returns the last YoY inflation coupon.

maturityDate() Date

Returns the maturity date.

optionlet(n: SupportsInt | SupportsIndex) YoYInflationCapFloor

Returns the n-th optionlet as a single-cashflow cap/floor.

startDate() Date

Returns the start date.

type() YoYInflationCapFloorType

Returns the type.

yoyLeg() list[base.CashFlow]

Returns the YoY leg.

YoYInflationCapFloorType

class pyquantlib.YoYInflationCapFloorType

Bases: pybind11_object

YoY inflation cap/floor type.

Members:

Cap

Floor

Collar

__init__(value: SupportsInt | SupportsIndex) None
Cap = <YoYInflationCapFloorType.Cap: 0>
Collar = <YoYInflationCapFloorType.Collar: 2>
Floor = <YoYInflationCapFloorType.Floor: 1>
YoYInflationCapFloorType.name -> str
property value

Value

Description

Cap

YoY inflation cap

Floor

YoY inflation floor

Collar

YoY inflation collar

YoYInflationCap

class pyquantlib.YoYInflationCap

Bases: YoYInflationCapFloor

YoY inflation cap.

__init__(yoyLeg: collections.abc.Sequence[base.CashFlow], exerciseRates: collections.abc.Sequence[SupportsFloat | SupportsIndex]) None

Constructs a YoY inflation cap.

YoYInflationFloor

class pyquantlib.YoYInflationFloor

Bases: YoYInflationCapFloor

YoY inflation floor.

__init__(yoyLeg: collections.abc.Sequence[base.CashFlow], exerciseRates: collections.abc.Sequence[SupportsFloat | SupportsIndex]) None

Constructs a YoY inflation floor.

YoYInflationCollar

class pyquantlib.YoYInflationCollar

Bases: YoYInflationCapFloor

YoY inflation collar.

__init__(yoyLeg: collections.abc.Sequence[base.CashFlow], capRates: collections.abc.Sequence[SupportsFloat | SupportsIndex], floorRates: collections.abc.Sequence[SupportsFloat | SupportsIndex]) None

Constructs a YoY inflation collar.

MakeYoYInflationCapFloor

pyquantlib.MakeYoYInflationCapFloor(capFloorType, index, length, calendar, observationLag, interpolation, **kwargs)[source]

Build a YoYInflationCapFloor from keyword arguments.

Parameters:
  • capFloorType (YoYInflationCapFloorType) – Cap, Floor, or Collar.

  • index (YoYInflationIndex) – The YoY inflation index.

  • length (int) – Length in years.

  • calendar (Calendar) – Payment calendar.

  • observationLag (Period) – Observation lag.

  • interpolation (CPI.InterpolationType) – Interpolation type.

  • **kwargs – Builder options mapped to with* methods (e.g. nominal, pricingEngine, strike, paymentDayCounter, …).

Return type:

YoYInflationCapFloor

Pythonic builder function for YoY inflation caps and floors. Constructor arguments are positional; builder options are keyword arguments.

cap = ql.MakeYoYInflationCapFloor(
    ql.YoYInflationCapFloorType.Cap, yoy_leg, [0.03],
    pricingEngine=engine,
)

Options

VanillaOption

class pyquantlib.VanillaOption

Bases: OneAssetOption

Plain vanilla option on a single asset.

__init__(payoff: base.StrikedTypePayoff, exercise: Exercise) None
payoff = ql.PlainVanillaPayoff(ql.Call, 100.0)
exercise = ql.EuropeanExercise(today + ql.Period("1Y"))
option = ql.VanillaOption(payoff, exercise)

option.setPricingEngine(engine)
print(f"NPV: {option.NPV():.4f}")
print(f"Delta: {option.delta():.4f}")

BasketOption

class pyquantlib.BasketOption

Bases: MultiAssetOption

Basket option on multiple assets.

__init__(payoff: base.BasketPayoff, exercise: Exercise) None

Constructs with basket payoff and exercise.

Barrier Options

BarrierOption

class pyquantlib.BarrierOption

Bases: OneAssetOption

Barrier option on a single asset.

__init__(barrierType: BarrierType, barrier: SupportsFloat | SupportsIndex, rebate: SupportsFloat | SupportsIndex, payoff: base.StrikedTypePayoff, exercise: Exercise) None

Constructs BarrierOption.

impliedVolatility(price: SupportsFloat | SupportsIndex, process: GeneralizedBlackScholesProcess, accuracy: SupportsFloat | SupportsIndex = 0.0001, maxEvaluations: SupportsInt | SupportsIndex = 100, minVol: SupportsFloat | SupportsIndex = 1e-07, maxVol: SupportsFloat | SupportsIndex = 4.0) float

Returns implied volatility.

Barrier Type

Description

DownIn

Activated when spot falls below barrier

UpIn

Activated when spot rises above barrier

DownOut

Knocked out when spot falls below barrier

UpOut

Knocked out when spot rises above barrier

payoff = ql.PlainVanillaPayoff(ql.Call, 100.0)
exercise = ql.EuropeanExercise(expiry)

option = ql.BarrierOption(ql.BarrierType.DownOut, 80.0, 0.0, payoff, exercise)
option.setPricingEngine(ql.AnalyticBarrierEngine(process))
print(option.NPV())

DoubleBarrierOption

class pyquantlib.DoubleBarrierOption

Bases: OneAssetOption

Double barrier option on a single asset.

__init__(barrierType: DoubleBarrierType, barrier_lo: SupportsFloat | SupportsIndex, barrier_hi: SupportsFloat | SupportsIndex, rebate: SupportsFloat | SupportsIndex, payoff: base.StrikedTypePayoff, exercise: Exercise) None

Constructs DoubleBarrierOption.

impliedVolatility(price: SupportsFloat | SupportsIndex, process: GeneralizedBlackScholesProcess, accuracy: SupportsFloat | SupportsIndex = 0.0001, maxEvaluations: SupportsInt | SupportsIndex = 100, minVol: SupportsFloat | SupportsIndex = 1e-07, maxVol: SupportsFloat | SupportsIndex = 4.0) float

Returns implied volatility.

Type

Description

KnockOut

Knocked out if either barrier is hit

KnockIn

Activated if either barrier is hit

KIKO

Lower KI, upper KO

KOKI

Lower KO, upper KI

option = ql.DoubleBarrierOption(
    ql.DoubleBarrierType.KnockOut, 80.0, 120.0, 0.0, payoff, exercise,
)
option.setPricingEngine(ql.AnalyticDoubleBarrierEngine(process))
print(option.NPV())

PartialTimeBarrierOption

class pyquantlib.PartialTimeBarrierOption

Bases: OneAssetOption

Partial-time barrier option.

__init__(barrierType: BarrierType, barrierRange: PartialBarrierRange, barrier: SupportsFloat | SupportsIndex, rebate: SupportsFloat | SupportsIndex, coverEventDate: Date, payoff: base.StrikedTypePayoff, exercise: Exercise) None

Constructs a partial-time barrier option.

Barrier monitored over a partial time window (start or end of option life).

option = ql.PartialTimeBarrierOption(
    ql.BarrierType.DownOut, ql.PartialBarrierRange.Start,
    80.0, 0.0, cover_date, payoff, exercise,
)
option.setPricingEngine(ql.AnalyticPartialTimeBarrierOptionEngine(process))

SoftBarrierOption

class pyquantlib.SoftBarrierOption

Bases: OneAssetOption

Soft barrier option (proportional knock-in/out over barrier range).

__init__(barrierType: BarrierType, barrierLo: SupportsFloat | SupportsIndex, barrierHi: SupportsFloat | SupportsIndex, payoff: base.StrikedTypePayoff, exercise: Exercise) None

Constructs a soft barrier option.

impliedVolatility(price: SupportsFloat | SupportsIndex, process: GeneralizedBlackScholesProcess, accuracy: SupportsFloat | SupportsIndex = 0.0001, maxEvaluations: SupportsInt | SupportsIndex = 100, minVol: SupportsFloat | SupportsIndex = 1e-06, maxVol: SupportsFloat | SupportsIndex = 4.0) float

Returns implied volatility.

Soft barrier option with proportional knock-in/out over a barrier range.

option = ql.SoftBarrierOption(ql.BarrierType.DownOut, 70.0, 80.0, payoff, exercise)
option.setPricingEngine(ql.AnalyticSoftBarrierEngine(process))

TwoAssetBarrierOption

class pyquantlib.TwoAssetBarrierOption

Bases: Option

Barrier option on two assets.

__init__(barrierType: BarrierType, barrier: SupportsFloat | SupportsIndex, payoff: base.StrikedTypePayoff, exercise: Exercise) None

Constructs a two-asset barrier option.

isExpired() bool

Returns whether the option is expired.

Barrier option where barrier monitoring is on a second (correlated) asset.

option = ql.TwoAssetBarrierOption(ql.BarrierType.DownOut, 80.0, payoff, exercise)
option.setPricingEngine(ql.AnalyticTwoAssetBarrierEngine(process1, process2, rho))

Asian Options

ContinuousAveragingAsianOption

class pyquantlib.ContinuousAveragingAsianOption

Bases: OneAssetOption

Continuous-averaging Asian option.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(averageType: AverageType, payoff: base.StrikedTypePayoff, exercise: Exercise) -> None

Constructs an unseasoned ContinuousAveragingAsianOption.

  1. __init__(averageType: AverageType, startDate: Date, payoff: base.StrikedTypePayoff, exercise: Exercise) -> None

Constructs a seasoned ContinuousAveragingAsianOption with start date.

DiscreteAveragingAsianOption

class pyquantlib.DiscreteAveragingAsianOption

Bases: OneAssetOption

Discrete-averaging Asian option.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(averageType: AverageType, runningAccumulator: SupportsFloat | SupportsIndex, pastFixings: SupportsInt | SupportsIndex, fixingDates: collections.abc.Sequence[Date], payoff: base.StrikedTypePayoff, exercise: Exercise) -> None

Constructs with running accumulator and past fixings count.

  1. __init__(averageType: AverageType, fixingDates: collections.abc.Sequence[Date], payoff: base.StrikedTypePayoff, exercise: Exercise, allPastFixings: collections.abc.Sequence[SupportsFloat | SupportsIndex] = []) -> None

Constructs with all fixing dates.

fixing_dates = [today + ql.Period(f"{i}M") for i in range(1, 13)]

# Geometric average (analytic)
asian_geom = ql.DiscreteAveragingAsianOption(
    ql.AverageType.Geometric, 0.0, 0, fixing_dates, payoff, exercise,
)
asian_geom.setPricingEngine(
    ql.AnalyticDiscreteGeometricAveragePriceAsianEngine(process)
)

# Arithmetic average (Turnbull-Wakeman approximation)
asian_arith = ql.DiscreteAveragingAsianOption(
    ql.AverageType.Arithmetic, 0.0, 0, fixing_dates, payoff, exercise,
)
asian_arith.setPricingEngine(ql.TurnbullWakemanAsianEngine(process))

Lookback Options

ContinuousFloatingLookbackOption

class pyquantlib.ContinuousFloatingLookbackOption

Bases: OneAssetOption

Continuous floating-strike lookback option.

__init__(currentMinmax: SupportsFloat | SupportsIndex, payoff: FloatingTypePayoff, exercise: Exercise) None

Continuous floating-strike lookback option. The strike is determined at expiry as the minimum (call) or maximum (put) of the asset price over the option’s life.

payoff = ql.FloatingTypePayoff(ql.Call)
exercise = ql.EuropeanExercise(expiry)
option = ql.ContinuousFloatingLookbackOption(100.0, payoff, exercise)

ContinuousFixedLookbackOption

class pyquantlib.ContinuousFixedLookbackOption

Bases: OneAssetOption

Continuous fixed-strike lookback option.

__init__(currentMinmax: SupportsFloat | SupportsIndex, payoff: base.StrikedTypePayoff, exercise: Exercise) None

Continuous fixed-strike lookback option. The payoff is based on the maximum (call) or minimum (put) of the asset price over the option’s life.

payoff = ql.PlainVanillaPayoff(ql.Call, 100.0)
exercise = ql.EuropeanExercise(expiry)
option = ql.ContinuousFixedLookbackOption(100.0, payoff, exercise)

ContinuousPartialFloatingLookbackOption

class pyquantlib.ContinuousPartialFloatingLookbackOption

Bases: ContinuousFloatingLookbackOption

Continuous partial floating-strike lookback option.

__init__(currentMinmax: SupportsFloat | SupportsIndex, lambda: SupportsFloat | SupportsIndex, lookbackPeriodEnd: Date, payoff: FloatingTypePayoff, exercise: Exercise) None

Partial floating-strike lookback option with a lookback period ending before expiry.

option = ql.ContinuousPartialFloatingLookbackOption(
    100.0, 1.0, lookback_end, payoff, exercise,
)

ContinuousPartialFixedLookbackOption

class pyquantlib.ContinuousPartialFixedLookbackOption

Bases: ContinuousFixedLookbackOption

Continuous partial fixed-strike lookback option.

__init__(lookbackPeriodStart: Date, payoff: base.StrikedTypePayoff, exercise: Exercise) None

Partial fixed-strike lookback option with a lookback period starting after inception.

option = ql.ContinuousPartialFixedLookbackOption(
    lookback_start, payoff, exercise,
)

Cliquet Options

CliquetOption

class pyquantlib.CliquetOption

Bases: OneAssetOption

Cliquet (ratchet) option with periodic resets.

__init__(payoff: PercentageStrikePayoff, maturity: EuropeanExercise, resetDates: collections.abc.Sequence[Date]) None

Cliquet (ratchet) option with periodic resets. The strike resets at each reset date to the then-current spot price.

payoff = ql.PercentageStrikePayoff(ql.Call, 1.0)
exercise = ql.EuropeanExercise(expiry)
reset_dates = [today + ql.Period(f"{i}M") for i in range(3, 12, 3)]
option = ql.CliquetOption(payoff, exercise, reset_dates)

Compound Options

CompoundOption

class pyquantlib.CompoundOption

Bases: OneAssetOption

Option on an option (compound option).

__init__(motherPayoff: base.StrikedTypePayoff, motherExercise: Exercise, daughterPayoff: base.StrikedTypePayoff, daughterExercise: Exercise) None

Compound option (option on an option). The mother option gives the right to buy/sell the daughter option.

mother_payoff = ql.PlainVanillaPayoff(ql.Call, 5.0)
mother_exercise = ql.EuropeanExercise(today + ql.Period("6M"))
daughter_payoff = ql.PlainVanillaPayoff(ql.Call, 100.0)
daughter_exercise = ql.EuropeanExercise(expiry)
option = ql.CompoundOption(
    mother_payoff, mother_exercise, daughter_payoff, daughter_exercise,
)

Chooser Options

SimpleChooserOption

class pyquantlib.SimpleChooserOption

Bases: OneAssetOption

Simple chooser option (choose call or put at choosing date).

__init__(choosingDate: Date, strike: SupportsFloat | SupportsIndex, exercise: Exercise) None

Simple chooser option. The holder chooses at a future date whether the option is a call or put.

option = ql.SimpleChooserOption(choosing_date, 100.0, exercise)

ComplexChooserOption

class pyquantlib.ComplexChooserOption

Bases: OneAssetOption

Complex chooser option (different strikes and exercises for call/put).

__init__(choosingDate: Date, strikeCall: SupportsFloat | SupportsIndex, strikePut: SupportsFloat | SupportsIndex, exerciseCall: Exercise, exercisePut: Exercise) None

Complex chooser option with different strikes and exercise dates for the call and put legs.

option = ql.ComplexChooserOption(
    choosing_date, call_strike, put_strike, call_exercise, put_exercise,
)

Margrabe Options

MargrabeOption

class pyquantlib.MargrabeOption

Bases: MultiAssetOption

Exchange option (Margrabe): option to exchange one asset for another.

__init__(Q1: SupportsInt | SupportsIndex, Q2: SupportsInt | SupportsIndex, exercise: Exercise) None
delta1() float

Returns delta with respect to first asset.

delta2() float

Returns delta with respect to second asset.

gamma1() float

Returns gamma with respect to first asset.

gamma2() float

Returns gamma with respect to second asset.

Margrabe option (exchange option): the right to exchange one asset for another.

option = ql.MargrabeOption(1, 1, exercise)
option.setPricingEngine(engine)
print(option.delta1(), option.delta2())
print(option.gamma1(), option.gamma2())

Forward-Start Options

ForwardVanillaOption

class pyquantlib.ForwardVanillaOption

Bases: OneAssetOption

Forward-start vanilla option.

__init__(moneyness: SupportsFloat | SupportsIndex, resetDate: Date, payoff: base.StrikedTypePayoff, exercise: Exercise) None

Forward-start vanilla option. The strike is set at a future reset date based on a moneyness ratio.

option = ql.ForwardVanillaOption(1.0, reset_date, payoff, exercise)

Quanto Options

QuantoVanillaOption

class pyquantlib.QuantoVanillaOption

Bases: OneAssetOption

Quanto vanilla option (currency-adjusted).

__init__(payoff: base.StrikedTypePayoff, exercise: Exercise) None
qlambda() float

Returns quanto lambda (correlation sensitivity).

qrho() float

Returns quanto rho.

qvega() float

Returns quanto vega.

Quanto vanilla option with currency adjustment. Provides quanto-specific greeks: qvega(), qrho(), qlambda().

option = ql.QuantoVanillaOption(payoff, exercise)
option.setPricingEngine(engine)
print(option.qvega(), option.qrho(), option.qlambda())

Payoffs

FloatingTypePayoff

class pyquantlib.FloatingTypePayoff

Bases: Payoff

Floating-strike payoff (for lookback options).

__init__(type: OptionType) None

Floating-strike payoff for lookback options.

payoff = ql.FloatingTypePayoff(ql.Call)

PlainVanillaPayoff

class pyquantlib.PlainVanillaPayoff

Bases: StrikedTypePayoff

Plain vanilla payoff (max(S-K,0) for call, max(K-S,0) for put).

__init__(type: OptionType, strike: SupportsFloat | SupportsIndex) None

Type

Payoff

Call

\(\max(S - K, 0)\)

Put

\(\max(K - S, 0)\)

call_payoff = ql.PlainVanillaPayoff(ql.Call, 100.0)
put_payoff = ql.PlainVanillaPayoff(ql.Put, 100.0)

CashOrNothingPayoff

class pyquantlib.CashOrNothingPayoff

Bases: StrikedTypePayoff

Binary payoff: fixed cash amount if in the money, zero otherwise.

__init__(type: OptionType, strike: SupportsFloat | SupportsIndex, cashPayoff: SupportsFloat | SupportsIndex) None
cashPayoff() float

Returns the cash payoff amount.

Binary payoff: pays a fixed cash amount if in the money, zero otherwise.

Type

Payoff

Call

\(C\) if \(S > K\), else \(0\)

Put

\(C\) if \(S < K\), else \(0\)

digital_call = ql.CashOrNothingPayoff(ql.Call, 100.0, 10.0)

AssetOrNothingPayoff

class pyquantlib.AssetOrNothingPayoff

Bases: StrikedTypePayoff

Binary payoff: asset value if in the money, zero otherwise.

__init__(type: OptionType, strike: SupportsFloat | SupportsIndex) None

Binary payoff: pays the asset value if in the money, zero otherwise.

Type

Payoff

Call

\(S\) if \(S > K\), else \(0\)

Put

\(S\) if \(S < K\), else \(0\)

digital = ql.AssetOrNothingPayoff(ql.Call, 100.0)

GapPayoff

class pyquantlib.GapPayoff

Bases: StrikedTypePayoff

Gap payoff: vanilla minus digital, with two strikes.

__init__(type: OptionType, strike: SupportsFloat | SupportsIndex, secondStrike: SupportsFloat | SupportsIndex) None
secondStrike() float

Returns the second (payoff) strike.

Gap payoff with two strikes. Equivalent to a vanilla minus a digital.

Type

Payoff

Call

\(S - K_2\) if \(S > K_1\), else \(0\)

Put

\(K_2 - S\) if \(S < K_1\), else \(0\)

gap = ql.GapPayoff(ql.Call, 100.0, 90.0)

PercentageStrikePayoff

class pyquantlib.PercentageStrikePayoff

Bases: StrikedTypePayoff

Payoff with strike expressed as moneyness percentage.

__init__(type: OptionType, moneyness: SupportsFloat | SupportsIndex) None

Payoff with strike expressed as a moneyness percentage of the asset price.

payoff = ql.PercentageStrikePayoff(ql.Call, 1.05)

SuperFundPayoff

class pyquantlib.SuperFundPayoff

Bases: StrikedTypePayoff

Binary superfund payoff between two strikes (normalized by lower strike).

__init__(strike: SupportsFloat | SupportsIndex, secondStrike: SupportsFloat | SupportsIndex) None
secondStrike() float

Returns the second strike.

Binary superfund payoff: pays \(S / K_1\) if \(K_1 < S < K_2\), zero otherwise.

payoff = ql.SuperFundPayoff(90.0, 110.0)

SuperSharePayoff

class pyquantlib.SuperSharePayoff

Bases: StrikedTypePayoff

Binary supershare payoff: fixed cash between two strikes.

__init__(strike: SupportsFloat | SupportsIndex, secondStrike: SupportsFloat | SupportsIndex, cashPayoff: SupportsFloat | SupportsIndex) None
cashPayoff() float

Returns the cash payoff amount.

secondStrike() float

Returns the second strike.

Binary supershare payoff: pays a fixed cash amount if \(K_1 < S < K_2\), zero otherwise.

payoff = ql.SuperSharePayoff(90.0, 110.0, 5.0)

MinBasketPayoff

class pyquantlib.MinBasketPayoff

Bases: BasketPayoff

Payoff based on minimum of basket prices.

__init__(basePayoff: base.Payoff) None

Constructs with base payoff.

MaxBasketPayoff

class pyquantlib.MaxBasketPayoff

Bases: BasketPayoff

Payoff based on maximum of basket prices.

__init__(basePayoff: base.Payoff) None

Constructs with base payoff.

AverageBasketPayoff

class pyquantlib.AverageBasketPayoff

Bases: BasketPayoff

Payoff based on weighted average of basket prices.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(basePayoff: base.Payoff, weights: Array) -> None

Constructs with base payoff and weights.

  1. __init__(basePayoff: base.Payoff, n: SupportsInt | SupportsIndex) -> None

Constructs with base payoff and equal weights for n assets.

weights() Array

Returns the weights.

SpreadBasketPayoff

class pyquantlib.SpreadBasketPayoff

Bases: BasketPayoff

Payoff based on spread between two assets.

__init__(basePayoff: base.Payoff) None

Constructs with base payoff.

Variance Swaps

VarianceSwap

class pyquantlib.VarianceSwap

Bases: Instrument

Variance swap instrument.

__init__(position: PositionType, strike: SupportsFloat | SupportsIndex, notional: SupportsFloat | SupportsIndex, startDate: Date, maturityDate: Date) None

Constructs a variance swap.

maturityDate() Date

Returns the maturity date.

notional() float

Returns the notional.

position() PositionType

Returns the position type.

startDate() Date

Returns the start date.

strike() float

Returns the variance strike.

variance() float

Returns the realized variance.

Exotic Swaps

NonstandardSwap

class pyquantlib.NonstandardSwap

Bases: Swap

Nonstandard swap with period-dependent nominal and strike.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(fromVanilla: FixedVsFloatingSwap) -> None

Constructs from a fixed-vs-floating swap.

  1. __init__(type: SwapType, fixedNominal: collections.abc.Sequence[SupportsFloat | SupportsIndex], floatingNominal: collections.abc.Sequence[SupportsFloat | SupportsIndex], fixedSchedule: Schedule, fixedRate: collections.abc.Sequence[SupportsFloat | SupportsIndex], fixedDayCount: DayCounter, floatingSchedule: Schedule, iborIndex: IborIndex, gearing: SupportsFloat | SupportsIndex, spread: SupportsFloat | SupportsIndex, floatingDayCount: DayCounter, intermediateCapitalExchange: bool = False, finalCapitalExchange: bool = False, paymentConvention: object = None) -> None

Constructs with scalar gearing and spread.

  1. __init__(type: SwapType, fixedNominal: collections.abc.Sequence[SupportsFloat | SupportsIndex], floatingNominal: collections.abc.Sequence[SupportsFloat | SupportsIndex], fixedSchedule: Schedule, fixedRate: collections.abc.Sequence[SupportsFloat | SupportsIndex], fixedDayCount: DayCounter, floatingSchedule: Schedule, iborIndex: IborIndex, gearings: collections.abc.Sequence[SupportsFloat | SupportsIndex], spreads: collections.abc.Sequence[SupportsFloat | SupportsIndex], floatingDayCount: DayCounter, intermediateCapitalExchange: bool = False, finalCapitalExchange: bool = False, paymentConvention: object = None) -> None

Constructs with vector gearings and spreads.

fixedDayCount() DayCounter

Returns the fixed leg day counter.

fixedLeg() list[base.CashFlow]

Returns the fixed leg cash flows.

fixedNominal() list[float]

Returns the fixed leg nominals.

fixedRate() list[float]

Returns the fixed rates.

fixedSchedule() Schedule

Returns the fixed leg schedule.

floatingDayCount() DayCounter

Returns the floating leg day counter.

floatingLeg() list[base.CashFlow]

Returns the floating leg cash flows.

floatingNominal() list[float]

Returns the floating leg nominals.

floatingSchedule() Schedule

Returns the floating leg schedule.

gearing() float

Returns the scalar gearing.

gearings() list[float]

Returns the gearing vector.

iborIndex() IborIndex

Returns the IBOR index.

paymentConvention() BusinessDayConvention

Returns the payment convention.

spread() float

Returns the scalar spread.

spreads() list[float]

Returns the spread vector.

type() SwapType

Returns the swap type.

FloatFloatSwap

class pyquantlib.FloatFloatSwap

Bases: Swap

Swap exchanging two floating legs with caps and floors.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(type: SwapType, nominal1: SupportsFloat | SupportsIndex, nominal2: SupportsFloat | SupportsIndex, schedule1: Schedule, index1: base.InterestRateIndex, dayCount1: DayCounter, schedule2: Schedule, index2: base.InterestRateIndex, dayCount2: DayCounter, intermediateCapitalExchange: bool = False, finalCapitalExchange: bool = False, gearing1: SupportsFloat | SupportsIndex = 1.0, spread1: SupportsFloat | SupportsIndex = 0.0, cappedRate1: object = None, flooredRate1: object = None, gearing2: SupportsFloat | SupportsIndex = 1.0, spread2: SupportsFloat | SupportsIndex = 0.0, cappedRate2: object = None, flooredRate2: object = None, paymentConvention1: object = None, paymentConvention2: object = None) -> None

Constructs with scalar parameters.

  1. __init__(type: SwapType, nominal1: collections.abc.Sequence[SupportsFloat | SupportsIndex], nominal2: collections.abc.Sequence[SupportsFloat | SupportsIndex], schedule1: Schedule, index1: base.InterestRateIndex, dayCount1: DayCounter, schedule2: Schedule, index2: base.InterestRateIndex, dayCount2: DayCounter, intermediateCapitalExchange: bool = False, finalCapitalExchange: bool = False, gearing1: collections.abc.Sequence[SupportsFloat | SupportsIndex] = [], spread1: collections.abc.Sequence[SupportsFloat | SupportsIndex] = [], cappedRate1: collections.abc.Sequence[SupportsFloat | SupportsIndex] = [], flooredRate1: collections.abc.Sequence[SupportsFloat | SupportsIndex] = [], gearing2: collections.abc.Sequence[SupportsFloat | SupportsIndex] = [], spread2: collections.abc.Sequence[SupportsFloat | SupportsIndex] = [], cappedRate2: collections.abc.Sequence[SupportsFloat | SupportsIndex] = [], flooredRate2: collections.abc.Sequence[SupportsFloat | SupportsIndex] = [], paymentConvention1: object = None, paymentConvention2: object = None) -> None

Constructs with vector parameters.

cappedRate1() list[float]

Returns leg 1 caps.

cappedRate2() list[float]

Returns leg 2 caps.

dayCount1() DayCounter

Returns leg 1 day counter.

dayCount2() DayCounter

Returns leg 2 day counter.

flooredRate1() list[float]

Returns leg 1 floors.

flooredRate2() list[float]

Returns leg 2 floors.

gearing1() list[float]

Returns leg 1 gearings.

gearing2() list[float]

Returns leg 2 gearings.

index1() base.InterestRateIndex

Returns leg 1 index.

index2() base.InterestRateIndex

Returns leg 2 index.

leg1() list[base.CashFlow]

Returns leg 1 cash flows.

leg2() list[base.CashFlow]

Returns leg 2 cash flows.

nominal1() list[float]

Returns leg 1 nominals.

nominal2() list[float]

Returns leg 2 nominals.

paymentConvention1() BusinessDayConvention

Returns leg 1 payment convention.

paymentConvention2() BusinessDayConvention

Returns leg 2 payment convention.

schedule1() Schedule

Returns leg 1 schedule.

schedule2() Schedule

Returns leg 2 schedule.

spread1() list[float]

Returns leg 1 spreads.

spread2() list[float]

Returns leg 2 spreads.

type() SwapType

Returns the swap type.

NonstandardSwaption

class pyquantlib.NonstandardSwaption

Bases: Option

Option to enter into a nonstandard swap.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(fromSwaption: Swaption) -> None

Constructs from a standard swaption.

  1. __init__(swap: NonstandardSwap, exercise: Exercise, delivery: SettlementType = <SettlementType.Physical: 0>, settlementMethod: SettlementMethod = <SettlementMethod.PhysicalOTC: 0>) -> None

Constructs a nonstandard swaption.

isExpired() bool

Returns True if the swaption has expired.

settlementMethod() SettlementMethod

Returns the settlement method.

settlementType() SettlementType

Returns the settlement type.

type() SwapType

Returns the underlying swap type.

underlyingSwap() NonstandardSwap

Returns the underlying nonstandard swap.

FloatFloatSwaption

class pyquantlib.FloatFloatSwaption

Bases: Option

Option to enter into a float-float swap.

__init__(swap: FloatFloatSwap, exercise: Exercise, delivery: SettlementType = <SettlementType.Physical: 0>, settlementMethod: SettlementMethod = <SettlementMethod.PhysicalOTC: 0>) None

Constructs a float-float swaption.

isExpired() bool

Returns True if the swaption has expired.

settlementMethod() SettlementMethod

Returns the settlement method.

settlementType() SettlementType

Returns the settlement type.

type() SwapType

Returns the underlying swap type.

underlyingSwap() FloatFloatSwap

Returns the underlying float-float swap.

Bond Forwards

Forward

class pyquantlib.base.Forward

Bases: Instrument

Abstract base class for forward contracts.

__init__(*args, **kwargs)
businessDayConvention() BusinessDayConvention

Returns the business day convention.

calendar() Calendar

Returns the calendar.

dayCounter() DayCounter

Returns the day counter.

discountCurve() QuantLib::Handle<QuantLib::YieldTermStructure>

Returns the discount curve handle.

forwardValue() float

Returns the forward value of the underlying.

impliedYield(underlyingSpotValue: SupportsFloat | SupportsIndex, forwardValue: SupportsFloat | SupportsIndex, settlementDate: Date, compoundingConvention: Compounding, dayCounter: DayCounter) InterestRate

Returns the implied yield from spot and forward values.

incomeDiscountCurve() QuantLib::Handle<QuantLib::YieldTermStructure>

Returns the income discount curve handle.

isExpired() bool

Returns True if the forward has expired.

settlementDate() Date

Returns the settlement date.

spotIncome(incomeDiscountCurve: QuantLib::Handle<QuantLib::YieldTermStructure>) float

Returns the NPV of income from the underlying.

spotValue() float

Returns the spot value of the underlying.

ForwardTypePayoff

class pyquantlib.ForwardTypePayoff

Bases: Payoff

Payoff for forward contracts.

__init__(type: PositionType, strike: SupportsFloat | SupportsIndex) None

Constructs a forward payoff.

forwardType() PositionType

Returns the position type.

strike() float

Returns the strike price.

BondForward

class pyquantlib.BondForward

Bases: Forward

Forward contract on a bond.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(valueDate: Date, maturityDate: Date, type: PositionType, strike: SupportsFloat | SupportsIndex, settlementDays: SupportsInt | SupportsIndex, dayCounter: DayCounter, calendar: Calendar, businessDayConvention: BusinessDayConvention, bond: Bond, discountCurve: YieldTermStructureHandle = <YieldTermStructureHandle object at 0x7f25341d0070>, incomeDiscountCurve: YieldTermStructureHandle = <YieldTermStructureHandle object at 0x7f253434bdb0>) -> None

Constructs a bond forward.

  1. __init__(valueDate: Date, maturityDate: Date, type: PositionType, strike: SupportsFloat | SupportsIndex, settlementDays: SupportsInt | SupportsIndex, dayCounter: DayCounter, calendar: Calendar, businessDayConvention: BusinessDayConvention, bond: Bond, discountCurve: base.YieldTermStructure, incomeDiscountCurve: base.YieldTermStructure) -> None

Constructs a bond forward (handles created internally).

cleanForwardPrice() float

Returns the clean forward bond price.

forwardPrice() float

Returns the dirty forward bond price.

Exercise Types

EuropeanExercise

class pyquantlib.EuropeanExercise

Bases: Exercise

European-style exercise (single date).

__init__(date: Date) None

Constructs with the exercise date.

AmericanExercise

class pyquantlib.AmericanExercise

Bases: Exercise

American-style exercise (date range).

__init__(earliestDate: Date, latestDate: Date, payoffAtExpiry: bool = False) None

Constructs with earliest and latest exercise dates.

BermudanExercise

class pyquantlib.BermudanExercise

Bases: Exercise

Bermudan-style exercise (discrete dates).

__init__(dates: collections.abc.Sequence[Date]) None

Constructs with a list of exercise dates.

european = ql.EuropeanExercise(expiry)
american = ql.AmericanExercise(today, expiry)
bermudan = ql.BermudanExercise([date1, date2, date3])