Class DiscretizedSwap
- Namespace
- NanoQL.PricingEngines
- Assembly
- NanoQL.dll
A discretized fixed-versus-floating swap: its value on a lattice, its coupons added as the rollback reaches them.
[WorkingType]
public sealed class DiscretizedSwap : DiscretizedAsset
- Inheritance
-
DiscretizedSwap
- Inherited Members
Remarks
A working type (DiscretizedAsset). Each coupon is added at its reset time, in the pre-adjustment or, as its adjustment says, the post-adjustment: a fixed coupon as its amount times a discount bond from its payment time, a floating one as the nominal times one less that bond, plus the nominal times its accrual time and spread times the bond. A coupon whose reset time is before the reference date and whose payment isn't (or is on it, when the context's IncludeTodaysCashFlows is true) is added in the post-adjustment at its payment time instead, as its known amount; a floating one whose amount can't be computed is refused there. The coupons' times are the given day counter's year fractions from the reference date.
A floating coupon known by its fixing date: the public constructor, a swap's own value as the tree swap
engine prices it, knows a floating coupon whose fixing date is on or before the reference date, adding its amount at
its payment time, where QuantLib knows it by its accrual start (its reset date, vanillaswap.cpp:67;
discretizedswap.cpp:84-87), so between its fixing and its start the tree forecasts a coupon whose fixing the
discounting engine reads (Divergences/TreeKnownCouponTests.cs). The internal constructor, which the
discretized swaption calls, keeps QuantLib's rule, so a swaption exercised in that window takes its floating leg at
par, QuantLib's convention.
A floating coupon paid after its accrual end: QuantLib values a floating coupon as a par floater to its
payment date, the nominal times one less the bond from its payment time (discretizedswap.cpp:199-218), which
overprices one paid on a lag or an adjusted date after its accrual end. Here such a coupon takes its forward over
its own accrual period and is paid on its payment date: the nominal times the bond from its payment time over the
bond from its accrual end, less the bond from its payment time, plus its spread; its accrual end is a mandatory time
only there. With QuantLib's check, the finite-difference engine on a lagged swap
(Divergences/TreeSwaptionSnappingTests.cs); a coupon paid on its accrual end keeps QuantLib's value.
Its discount bonds. QuantLib's swap builds a discount bond for each coupon it adds, initializes it at the payment time and rolls it back to the swap's time. This swap keeps one bond, re-initialized for each coupon (a discount bond has no adjustments, so the adjustment times its memo keeps skip nothing), and a second for the accrual ends, whose buffers its Reset(int) reserves at the widest step of the swap's own rollback, from its initial step down to the grid's start: every coupon's bond starts at or before the swap's initial time and rolls back to the swap's time, so no coupon's bond allocates.
Constructors
DiscretizedSwap(FixedVsFloatingSwap, Date, DayCounter, EvaluationContext)
Initializes a new instance of the DiscretizedSwap class, every coupon added in the pre-adjustment, a floating one fixed on or before the reference date known by its amount.
public DiscretizedSwap(FixedVsFloatingSwap swap, Date referenceDate, DayCounter dayCounter, EvaluationContext context)
Parameters
swapFixedVsFloatingSwapThe swap.
referenceDateDateThe date of time 0.
dayCounterDayCounterThe day counter of the times.
contextEvaluationContextThe evaluation context: its IncludeTodaysCashFlows, and the fixings and curves the floating coupons' amounts read.
Exceptions
- ArgumentNullException
The swap, the day counter or the context is null.
- ArgumentException
referenceDateis default.
Methods
MandatoryTimes()
The swap's mandatory times: the non-negative fixed reset, fixed payment, floating reset and floating payment times, in that order, then each floating coupon's accrual end time where it isn't its payment time.
public override ImmutableArray<double> MandatoryTimes()
Returns
- ImmutableArray<double>
The times, not guaranteed to be sorted.
PostAdjustValuesImpl()
Adds the coupons adjusted after an option looks at the values, floating then fixed, whose reset is now; then the known amounts of the coupons whose reset is past and whose payment is now.
protected override void PostAdjustValuesImpl()
Exceptions
- NanoQLException
A past floating coupon's amount isn't known.
PreAdjustValuesImpl()
Adds the coupons adjusted before an option looks at the values, floating then fixed, whose reset is now.
protected override void PreAdjustValuesImpl()
Reset(int)
Sets the values to 0 and adjusts them; on a tree lattice, it first reserves its discount bonds' buffers at the widest step from the swap's time down to the grid's start.
public override void Reset(int size)
Parameters
sizeintThe number of values.
Exceptions
- ArgumentOutOfRangeException
sizeis negative.- NanoQLException
The swap isn't initialized, or a past floating coupon's amount isn't known.