Function swap_from_legs
pub fn swap_from_legs(
fixed: Leg,
floating: Leg,
collateral: CollateralSpec,
) -> Result<AnyInstrument, SwapLegsError>Expand description
A fixed-versus-floating swap from two compiled legs.
The constructor for a swap no template generates — an amortising or accreting notional, a stepped fixed rate, a spread or gearing that changes by period — built coupon by coupon and then booked as one trade: a fixed leg and an IBOR leg with a nominal, rate, gearing and spread per period.
The currency and the projection index are read off the coupons, never
restated, so a leg cannot be labelled with an index it does not reset on.
Floating coupons on a term index make a VanillaSwap; overnight coupons
make an OvernightIndexedSwap. Either leg may carry
Redemption coupons —
notional exchanges, which name no index.
The result’s par rate is the one flat fixed rate that values it at zero over the fixed coupons’ own notionals and accruals — for a stepped leg, the level rate, not a shift — the rate an amortising swap is quoted at.
§Errors
SwapLegsError for an empty or accumulating leg, a coupon on the wrong
leg, a floating leg with no index or two, legs in two currencies, or legs
on the same side.