Instruments Module¶
Bonds¶
Bond¶
- class pyquantlib.Bond¶
Bases:
InstrumentBase class for bonds.
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__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.
- bondYield(*args, **kwargs)¶
Overloaded function.
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.
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.
- cleanPrice(*args, **kwargs)¶
Overloaded function.
cleanPrice() -> float
Returns the clean price (requires pricing engine).
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.
dirtyPrice() -> float
Returns the dirty price (requires pricing engine).
dirtyPrice(yield: SupportsFloat | SupportsIndex, dayCounter: DayCounter, compounding: Compounding, frequency: Frequency, settlement: Date = <Date: null date>) -> float
Returns the dirty price given a yield.
- redemption() base.CashFlow¶
Returns the single redemption cash flow.
- settlementValue(*args, **kwargs)¶
Overloaded function.
settlementValue() -> float
Returns the settlement value (requires pricing engine).
settlementValue(cleanPrice: SupportsFloat | SupportsIndex) -> float
Returns the settlement value for a given clean price.
ZeroCouponBond¶
- class pyquantlib.ZeroCouponBond¶
Bases:
BondZero 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:
BondFixed 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.
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:
BondFloating 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:
BondAmortizing 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.
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¶
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:
BondAmortizing 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:
BondCMS-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:
BondCPI 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.
- cpiIndex() ZeroInflationIndex¶
Returns the CPI index.
- dayCounter() DayCounter¶
Returns the accrual day counter.
- observationInterpolation() CPI.InterpolationType¶
Returns the observation interpolation type.
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:
EventInstrument callability (call or put) at a given date.
- __init__(price: BondPrice, type: CallabilityType, date: Date) None¶
Constructs a callability.
- price() BondPrice¶
Returns the call/put price.
- type() CallabilityType¶
Returns the callability type (Call or Put).
- class pyquantlib.CallabilityType¶
Bases:
pybind11_objectCallability 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 |
|---|---|
|
Issuer can call (redeem early) |
|
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:
CallableBondCallable/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:
CallableBondCallable/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:
CallabilityCallability 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.
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:
BondBase class for convertible bonds.
- __init__(*args, **kwargs)¶
- callability() list[Callability]¶
Returns the callability schedule.
Base class for convertible bonds (not directly constructible).
ConvertibleZeroCouponBond¶
- class pyquantlib.ConvertibleZeroCouponBond¶
Bases:
ConvertibleBondConvertible 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:
ConvertibleBondConvertible 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:
ConvertibleBondConvertible 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:
SwapEquity total return swap.
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__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.
- interestRateIndex() base.InterestRateIndex¶
Returns the interest rate index.
- paymentConvention() BusinessDayConvention¶
Returns the payment business day convention.
- 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:
FixedVsFloatingSwapPlain 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.
Nonefor par rate.forwardStart (Period, optional) – Forward start period.
**kwargs – Builder options mapped to
with*methods (e.g.nominal,pricingEngine,fixedLegDayCount,floatingLegSpread, …).
- Return type:
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:
FixedVsFloatingSwapOvernight indexed swap: fixed vs overnight floating leg.
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__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.
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:
SwapZero-coupon interest rate swap.
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__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.
- fairFixedRate(dayCounter: DayCounter) float¶
Fair fixed rate for a given day counter.
- 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:
SwapBullet 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.
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:
InstrumentInterest rate cap, floor, or collar.
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__init__(type: CapFloorType, floatingLeg: collections.abc.Sequence[base.CashFlow], strikes: collections.abc.Sequence[SupportsFloat | SupportsIndex]) -> None
Constructs a cap or floor with uniform strikes.
- 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.
- type() CapFloorType¶
Returns the cap/floor type.
Cap¶
- class pyquantlib.Cap¶
Bases:
CapFloorInterest rate cap.
- __init__(floatingLeg: collections.abc.Sequence[base.CashFlow], exerciseRates: collections.abc.Sequence[SupportsFloat | SupportsIndex]) None¶
Constructs a cap.
Floor¶
- class pyquantlib.Floor¶
Bases:
CapFloorInterest rate floor.
- __init__(floatingLeg: collections.abc.Sequence[base.CashFlow], exerciseRates: collections.abc.Sequence[SupportsFloat | SupportsIndex]) None¶
Constructs a floor.
Collar¶
- class pyquantlib.Collar¶
Bases:
CapFloorInterest 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:
InstrumentForward rate agreement (FRA).
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__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).
__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.
- businessDayConvention() BusinessDayConvention¶
Returns the business day convention.
- dayCounter() DayCounter¶
Returns the day counter.
- forwardRate() InterestRate¶
Returns the market forward rate.
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:
OptionOption to enter into an interest rate swap.
- class engine¶
Bases:
SwaptionGenericEngineBase class for swaption pricing engines.
- __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.
- 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:
- Return type:
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:
InstrumentAggregate of instruments with weighted NPVs.
- add(instrument: base.Instrument, multiplier: SupportsFloat | SupportsIndex = 1.0) None¶
Adds an instrument with a multiplier.
- 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:
ClaimClaim on a notional.
- class pyquantlib.FaceValueAccrualClaim¶
Bases:
ClaimClaim on the notional of a reference security, including accrual.
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:
InstrumentCredit default swap.
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__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.
- conventionalSpread(conventionalRecovery: SupportsFloat | SupportsIndex, discountCurve: YieldTermStructureHandle, dayCounter: DayCounter, model: CdsPricingModel = <CdsPricingModel.Midpoint: 0>) float¶
Conventional spread.
- 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.
- side() ProtectionSide¶
Protection side.
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:
SwapZero-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.
- dayCounter() DayCounter¶
Returns the day counter.
- fixedConvention() BusinessDayConvention¶
Returns the fixed-leg business day convention.
- inflationConvention() BusinessDayConvention¶
Returns the inflation business day convention.
- inflationIndex() ZeroInflationIndex¶
Returns the inflation index.
- observationInterpolation() CPI.InterpolationType¶
Returns the observation interpolation type.
- type() SwapType¶
Returns the swap type.
Zero-coupon inflation swap: fixed rate vs zero-coupon inflation leg.
YearOnYearInflationSwap¶
- class pyquantlib.YearOnYearInflationSwap¶
Bases:
SwapYear-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.
- fixedDayCount() DayCounter¶
Returns the fixed-leg day counter.
- paymentConvention() BusinessDayConvention¶
Returns the payment convention.
- type() SwapType¶
Returns the swap type.
- yoyDayCount() DayCounter¶
Returns the YoY-leg day counter.
- yoyInflationIndex() YoYInflationIndex¶
Returns the YoY inflation index.
Year-on-year inflation swap: fixed rate vs YoY inflation leg.
YoY Inflation Caps, Floors, and Collars¶
YoYInflationCapFloor¶
- class pyquantlib.YoYInflationCapFloor¶
Bases:
InstrumentYoY inflation cap, floor, or collar.
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__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.
- 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.
- lastYoYInflationCoupon() YoYInflationCoupon¶
Returns the last YoY inflation coupon.
- optionlet(n: SupportsInt | SupportsIndex) YoYInflationCapFloor¶
Returns the n-th optionlet as a single-cashflow cap/floor.
- type() YoYInflationCapFloorType¶
Returns the type.
YoYInflationCapFloorType¶
- class pyquantlib.YoYInflationCapFloorType¶
Bases:
pybind11_objectYoY 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 |
|---|---|
|
YoY inflation cap |
|
YoY inflation floor |
|
YoY inflation collar |
YoYInflationCap¶
- class pyquantlib.YoYInflationCap¶
Bases:
YoYInflationCapFloorYoY 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:
YoYInflationCapFloorYoY 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:
YoYInflationCapFloorYoY 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:
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:
OneAssetOptionPlain vanilla option on a single asset.
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¶
Barrier Options¶
BarrierOption¶
- class pyquantlib.BarrierOption¶
Bases:
OneAssetOptionBarrier 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 |
|---|---|
|
Activated when spot falls below barrier |
|
Activated when spot rises above barrier |
|
Knocked out when spot falls below barrier |
|
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:
OneAssetOptionDouble 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 |
|---|---|
|
Knocked out if either barrier is hit |
|
Activated if either barrier is hit |
|
Lower KI, upper KO |
|
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:
OneAssetOptionPartial-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:
OneAssetOptionSoft 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:
OptionBarrier option on two assets.
- __init__(barrierType: BarrierType, barrier: SupportsFloat | SupportsIndex, payoff: base.StrikedTypePayoff, exercise: Exercise) None¶
Constructs a two-asset barrier option.
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:
OneAssetOptionContinuous-averaging Asian option.
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(averageType: AverageType, payoff: base.StrikedTypePayoff, exercise: Exercise) -> None
Constructs an unseasoned ContinuousAveragingAsianOption.
__init__(averageType: AverageType, startDate: Date, payoff: base.StrikedTypePayoff, exercise: Exercise) -> None
Constructs a seasoned ContinuousAveragingAsianOption with start date.
DiscreteAveragingAsianOption¶
- class pyquantlib.DiscreteAveragingAsianOption¶
Bases:
OneAssetOptionDiscrete-averaging Asian option.
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__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:
OneAssetOptionContinuous 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:
OneAssetOptionContinuous 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:
ContinuousFloatingLookbackOptionContinuous 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:
ContinuousFixedLookbackOptionContinuous partial fixed-strike lookback option.
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:
OneAssetOptionCliquet (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:
OneAssetOptionOption on an option (compound option).
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:
OneAssetOptionSimple 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:
OneAssetOptionComplex 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:
MultiAssetOptionExchange option (Margrabe): option to exchange one asset for another.
- __init__(Q1: SupportsInt | SupportsIndex, Q2: SupportsInt | SupportsIndex, exercise: Exercise) None¶
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:
OneAssetOptionForward-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:
OneAssetOptionQuanto vanilla option (currency-adjusted).
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:
PayoffFloating-strike payoff (for lookback options).
Floating-strike payoff for lookback options.
payoff = ql.FloatingTypePayoff(ql.Call)
PlainVanillaPayoff¶
- class pyquantlib.PlainVanillaPayoff¶
Bases:
StrikedTypePayoffPlain vanilla payoff (max(S-K,0) for call, max(K-S,0) for put).
- __init__(type: OptionType, strike: SupportsFloat | SupportsIndex) None¶
Type |
Payoff |
|---|---|
|
\(\max(S - K, 0)\) |
|
\(\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:
StrikedTypePayoffBinary payoff: fixed cash amount if in the money, zero otherwise.
- __init__(type: OptionType, strike: SupportsFloat | SupportsIndex, cashPayoff: SupportsFloat | SupportsIndex) None¶
Binary payoff: pays a fixed cash amount if in the money, zero otherwise.
Type |
Payoff |
|---|---|
|
\(C\) if \(S > K\), else \(0\) |
|
\(C\) if \(S < K\), else \(0\) |
digital_call = ql.CashOrNothingPayoff(ql.Call, 100.0, 10.0)
AssetOrNothingPayoff¶
- class pyquantlib.AssetOrNothingPayoff¶
Bases:
StrikedTypePayoffBinary 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 |
|---|---|
|
\(S\) if \(S > K\), else \(0\) |
|
\(S\) if \(S < K\), else \(0\) |
digital = ql.AssetOrNothingPayoff(ql.Call, 100.0)
GapPayoff¶
- class pyquantlib.GapPayoff¶
Bases:
StrikedTypePayoffGap payoff: vanilla minus digital, with two strikes.
- __init__(type: OptionType, strike: SupportsFloat | SupportsIndex, secondStrike: SupportsFloat | SupportsIndex) None¶
Gap payoff with two strikes. Equivalent to a vanilla minus a digital.
Type |
Payoff |
|---|---|
|
\(S - K_2\) if \(S > K_1\), else \(0\) |
|
\(K_2 - S\) if \(S < K_1\), else \(0\) |
gap = ql.GapPayoff(ql.Call, 100.0, 90.0)
PercentageStrikePayoff¶
- class pyquantlib.PercentageStrikePayoff¶
Bases:
StrikedTypePayoffPayoff 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:
StrikedTypePayoffBinary superfund payoff between two strikes (normalized by lower strike).
- __init__(strike: SupportsFloat | SupportsIndex, secondStrike: SupportsFloat | SupportsIndex) None¶
Binary superfund payoff: pays \(S / K_1\) if \(K_1 < S < K_2\), zero otherwise.
payoff = ql.SuperFundPayoff(90.0, 110.0)
MinBasketPayoff¶
MaxBasketPayoff¶
AverageBasketPayoff¶
- class pyquantlib.AverageBasketPayoff¶
Bases:
BasketPayoffPayoff based on weighted average of basket prices.
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(basePayoff: base.Payoff, weights: Array) -> None
Constructs with base payoff and weights.
__init__(basePayoff: base.Payoff, n: SupportsInt | SupportsIndex) -> None
Constructs with base payoff and equal weights for n assets.
SpreadBasketPayoff¶
Variance Swaps¶
VarianceSwap¶
- class pyquantlib.VarianceSwap¶
Bases:
InstrumentVariance swap instrument.
- __init__(position: PositionType, strike: SupportsFloat | SupportsIndex, notional: SupportsFloat | SupportsIndex, startDate: Date, maturityDate: Date) None¶
Constructs a variance swap.
- position() PositionType¶
Returns the position type.
Exotic Swaps¶
NonstandardSwap¶
- class pyquantlib.NonstandardSwap¶
Bases:
SwapNonstandard swap with period-dependent nominal and strike.
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(fromVanilla: FixedVsFloatingSwap) -> None
Constructs from a fixed-vs-floating swap.
__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.
__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.
- floatingDayCount() DayCounter¶
Returns the floating leg day counter.
- paymentConvention() BusinessDayConvention¶
Returns the payment convention.
- type() SwapType¶
Returns the swap type.
FloatFloatSwap¶
- class pyquantlib.FloatFloatSwap¶
Bases:
SwapSwap exchanging two floating legs with caps and floors.
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__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.
- dayCount1() DayCounter¶
Returns leg 1 day counter.
- dayCount2() DayCounter¶
Returns leg 2 day counter.
- index1() base.InterestRateIndex¶
Returns leg 1 index.
- index2() base.InterestRateIndex¶
Returns leg 2 index.
- paymentConvention1() BusinessDayConvention¶
Returns leg 1 payment convention.
- paymentConvention2() BusinessDayConvention¶
Returns leg 2 payment convention.
- type() SwapType¶
Returns the swap type.
NonstandardSwaption¶
- class pyquantlib.NonstandardSwaption¶
Bases:
OptionOption to enter into a nonstandard swap.
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(fromSwaption: Swaption) -> None
Constructs from a standard swaption.
__init__(swap: NonstandardSwap, exercise: Exercise, delivery: SettlementType = <SettlementType.Physical: 0>, settlementMethod: SettlementMethod = <SettlementMethod.PhysicalOTC: 0>) -> None
Constructs a nonstandard swaption.
- 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:
OptionOption 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.
- 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:
InstrumentAbstract base class for forward contracts.
- __init__(*args, **kwargs)¶
- businessDayConvention() BusinessDayConvention¶
Returns the business day convention.
- dayCounter() DayCounter¶
Returns the day counter.
- discountCurve() QuantLib::Handle<QuantLib::YieldTermStructure>¶
Returns the discount curve handle.
- 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.
ForwardTypePayoff¶
- class pyquantlib.ForwardTypePayoff¶
Bases:
PayoffPayoff for forward contracts.
- __init__(type: PositionType, strike: SupportsFloat | SupportsIndex) None¶
Constructs a forward payoff.
- forwardType() PositionType¶
Returns the position type.
BondForward¶
- class pyquantlib.BondForward¶
Bases:
ForwardForward contract on a bond.
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__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).
Exercise Types¶
EuropeanExercise¶
AmericanExercise¶
BermudanExercise¶
- class pyquantlib.BermudanExercise¶
Bases:
ExerciseBermudan-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])