Module legs
Expand description
The leg and coupon layer, crossed.
A leg is the finest thing this library values. Below an instrument and above
a cashflow, it is what a desk actually reasons about — the fixed side is
worth this, the floating side that — and until now a Python caller could
read one after the fact through Instrument.cashflow_records and compose
none.
Two rules shape everything here.
- The leg a caller composes is the leg the instrument prices. Not a
parallel implementation that agrees to a tolerance: the same
Leg::npv, over the same resolved view, through the same record writer. A second valuation path that nearly agrees is worse than no leg surface, because it invites risk to be built on it. - The closed coupon set stays closed.
AnyCouponholds four kinds and this module carries one constructor for each, no more and no fewer. A caller cannot introduce a fifth, and a fifth added to the core fails the census inevery_variant_of_the_closed_set_reaches_pythonrather than being silently absent here.
A leg carries no discount curve of its own — an instrument’s collateral is the instrument’s — so the class takes the discount key at construction and declares it the way every product does. The projection index is read off the coupons, because they are the things that name one.
Structs§
- PyAny
Coupon 🔒 - One coupon of the closed set.
- PyLeg 🔒
- A compiled leg: coupons in payment order, the side they are on, and the discount key they are valued under.
- Spread
Correlation 🔒Arg - Where a CMS spread’s correlation comes from, as a Python caller names it:
a number, the contract’s correlation, or
"Market", the market’s mark for the coupon’s pair of swap indices — Rust’sCmsSpreadCorrelation.
Enums§
- PyAccrual
Compounding 🔒 - How an overnight leg accumulates its prints over a period:
Simple(averaged),Compounded, orContinuous. - PyDirection 🔒
- Which side of a leg the holder is on:
ReceiveorPay. - PyReset
Compounding 🔒 - How a multi-reset coupon combines its resets into one payment: the ISDA
2006 methods
Straight,FlatandSpreadExclusive, orAveraged. - Strip
Notional 🔒 - A strip’s notional: one for every period, or one per period in schedule order — an amortising leg.
- StubArg 🔒
- How a multi-reset coupon’s final short sub-period reads the index: a name
(
"index_tenor","own_accrual") or the(shorter, longer)pair of registered term indices an ISDA 2006 §8.3 interpolated stub blends. - Window
Arg 🔒 - The window an IBOR coupon’s rate spans: explicit dates, or a name the
registered index resolves (
"value_dates").
Functions§
- __
pyfunction_ 🔒 ⚠accumulated_ fixed_ leg - __
pyfunction_ 🔒 ⚠accumulated_ float_ leg - __
pyfunction_ 🔒 ⚠cms_ coupon - __
pyfunction_ 🔒 ⚠cms_ leg - __
pyfunction_ 🔒 ⚠cms_ spread_ coupon - __
pyfunction_ 🔒 ⚠cms_ spread_ leg - __
pyfunction_ 🔒 ⚠cpi_ coupon - __
pyfunction_ 🔒 ⚠cpi_ leg - __
pyfunction_ 🔒 ⚠cpi_ redemption - __
pyfunction_ 🔒 ⚠fixed_ rate_ coupon - __
pyfunction_ 🔒 ⚠fixed_ rate_ leg - __
pyfunction_ 🔒 ⚠ibor_ coupon - __
pyfunction_ 🔒 ⚠ibor_ leg - __
pyfunction_ 🔒 ⚠multi_ reset_ coupon - __
pyfunction_ 🔒 ⚠multi_ reset_ leg - __
pyfunction_ 🔒 ⚠overnight_ coupon - __
pyfunction_ 🔒 ⚠overnight_ leg - __
pyfunction_ 🔒 ⚠range_ accrual_ coupon - __
pyfunction_ 🔒 ⚠range_ accrual_ leg - __
pyfunction_ 🔒 ⚠redemption - __
pyfunction_ 🔒 ⚠yoy_ inflation_ coupon - __
pyfunction_ 🔒 ⚠yoy_ inflation_ leg - accumulated_
fixed_ 🔒leg - The fixed side of a zero-coupon swap: one coupon carrying
fixed_rateover[effective, maturity], accruing underaccrual_compoundinginto a single payment at maturity. - accumulated_
float_ 🔒leg - The floating side of a zero-coupon swap:
coupons’ rates compounding period by period into a single payment atpays. - cms_
coupon 🔒 - A CMS coupon:
notional · τ · (gearing · CMS + spread), the CMS rate of the swap indextemplateattenorfixing in advance ofaccrual_startby the index’s fixing lag, convexity-adjusted by linear TSR atmean_reversionand paid onpayment_date. A leg holding it declares the currency’s swaption vols; a published print under the swap index’s key settles it. - cms_leg 🔒
- A CMS coupon strip over
schedule, one coupon per calculation period:cms_couponper period, as Rust’scms_legbuilds it. - cms_
spread_ 🔒coupon - A CMS spread coupon:
notional · τ · (gearing · (CMS(tenor) − CMS(minus_tenor)) + spread)on the swap indextemplate, both rates fixing in advance and joined bycorrelation— a number, the contract’s, with no risk row, or"Market", the market’s mark for the pair of swap indices, with one. - cms_
spread_ 🔒leg - A CMS spread coupon strip over
schedule, one coupon per calculation period, as Rust’scms_spread_legbuilds it;correlationascms_spread_coupontakes it. - cpi_
coupon 🔒 - One CPI coupon:
notional × fixed_rate × accrual fraction × I(end)/base_index, accruing fromaccrual_starttoaccrual_endunderday_countand paid onpayment_dateincurrency. - cpi_leg 🔒
- A CPI coupon strip over
schedule, one coupon per calculation period:cpi_couponper period, computing nothing it does not. - cpi_
redemption 🔒 - A CPI leg’s indexed notional paid on
payment_date:notional × (I/base_index − 1)where only the growth is paid (the default) ornotional × I/base_index,Ithe index observed forobservation(the payment date whenNone)lag_monthsback (the index’s own lag whenNone) under its own interpolation.base_dateis the date the base level stands for: a collar on the notional (Leg.with_collar) is struck in annualised zero-coupon rates from it, so a floor at 0 is a linker’s deflation floor. - fixed_
rate_ 🔒coupon - One fixed-rate coupon:
notional × fixed_rate × accrual fraction, accruing fromaccrual_starttoaccrual_endunderday_countand paid onpayment_dateincurrency. - fixed_
rate_ 🔒leg - A fixed-rate coupon strip over
schedule, one coupon per calculation period. - ibor_
coupon 🔒 - An IBOR-style coupon: one fixing of
indexper period, geared and spread. - ibor_
leg 🔒 - An IBOR coupon strip over
schedule, one coupon per calculation period. - kind_of 🔒
- The variant’s name — the same string the cashflow table’s
kindcolumn carries, read off the core rather than spelled again here. - multi_
reset_ 🔒coupon - A multi-reset coupon:
indexresets everyreset_tenorover the accrual and the resets combine into one payment undercompounding—"straight","flat","spread_exclusive"(the ISDA 2006 methods) or"averaged". - multi_
reset_ 🔒leg - A multi-reset coupon strip over
schedule, one coupon per calculation period, each resetting everyreset_tenorand each final short sub-period reading the index asstubsays (seemulti_reset_coupon). - overnight_
coupon 🔒 - A compounded overnight coupon on
index, observed overcalendar. - overnight_
leg 🔒 - An overnight coupon strip over
schedule, one coupon per calculation period. - payment_
dates 🔒 - A fixed-rate coupon:
notional · rate · tau, paid onpayment_date. - projections_
of 🔒 - The distinct indices a leg’s floating coupons name, in first-seen order: the core’s reading.
- range_
accrual_ 🔒coupon - One range accrual:
notional × fixed_rate × accrual fraction × (days in range) / (days), every calendar day fromaccrual_starttoaccrual_endobserving the fixing ofindex(a registered term index) on the latest business day on or before it, in range when it lies in[lower, upper](a bound leftNoneis open). - range_
accrual_ 🔒leg - A range accrual strip over
schedule, one coupon per calculation period:range_accrual_couponper period, computing nothing it does not. - redemption 🔒
- A dated payment of a known amount — a redemption, a fee, a notional exchange. It accrues over nothing and pays no rate.
- register 🔒
- registered_
ibor 🔒 - A registered term index by code, or a
ValueErrornaming it. - registered_
price 🔒 - The registered price index
codenames, refused by name otherwise. - wrap 🔒
- wrap_
unvalued 🔒 wrapfor a leg handed out for its schedule alone, refusing to be valued forreason.- yoy_
inflation_ 🔒coupon - One year-on-year inflation coupon:
notional × accrual fraction × (gearing × (I(end)/I(start) − 1) + spread), accruing fromaccrual_starttoaccrual_endunderday_countand paid onpayment_dateincurrency, on a ratio of index levels. - yoy_
inflation_ 🔒leg - A year-on-year inflation coupon strip over
schedule, one coupon per calculation period:yoy_inflation_couponper period, as Rust’syoy_inflation_legbuilds it.