Class DiscretizedCapFloor
- Namespace
- NanoQL.PricingEngines
- Assembly
- NanoQL.dll
A discretized cap, floor or collar: its value on a lattice, each optionlet added as the rollback reaches it.
[WorkingType]
public sealed class DiscretizedCapFloor : DiscretizedAsset
- Inheritance
-
DiscretizedCapFloor
- Inherited Members
Remarks
A working type (DiscretizedAsset). A caplet still to be fixed is added in the pre-adjustment at its fixing time, as the option to pay (1 + Kτ) at its payment time for 1 at its start, the two discount bonds rolled back there: (1 + Kτ)·max(P(start)/(1 + Kτ) − P(end), 0) times its nominal and gearing, a floorlet likewise; one fixed after its start, in arrears, at its fixing time too, on its index's own period from the fixing date, three bonds rolled back there: τ·P(pay)·max(L − K, 0), L = (P(s)/P(e) − 1)/τᵢ over the period (s, e) and its index's year fraction τᵢ, times its nominal and gearing; one fixed on its start at its start time, as QuantLib adds every caplet, (1 + Kτ)·max(1/(1 + Kτ) − P, 0). A caplet fixed on or before the reference date, as the analytic engine knows it (its fixing time at most 0), is added in the post-adjustment at its payment time, as its known amount, max(F − K, 0)·τ times its nominal and gearing; one paid on the reference date counts only when the context includes today's cash flows, as the discretized swap's known coupon does. The times are the given day counter's year fractions from the reference date.
The fixing time: QuantLib exercises every caplet still to be fixed at its start
(discretizedcapfloor.cpp:53-55), where the instrument fixes its rate and QuantLib's Monte Carlo engine reads
it at the fixing date, so a caplet with a fixing lag is priced on the variance to its start; a divergence
(Divergences/CapletFixingExpiryTests.cs). On a caplet fixed on its start, the fixing time is the start time
and the value QuantLib's, bit for bit. A rollback must reach the earliest fixing time a caplet is valued at, which
precedes the first start QuantLib's engine rolls back to (NanoQL.PricingEngines.DiscretizedCapFloor.EarliestFixingTime).
An in-arrears caplet: QuantLib values it as the caplet in advance, at its start on its accrual period,
reading neither its later fixing nor its index's period; a divergence (Divergences/CapletInArrearsTests.cs)
with no QuantLib check, checked on Hull-White against each caplet's Gaussian integral at its fixing. Its fixing time
and its index period's start and end are mandatory times, the end past the cap's last payment.
A seasoned cap (widened): its mandatory times are its non-negative start and payment times, as the
discretized swap's are, then the fixing times of the caplets valued there, and a caplet is known by its fixing date:
a divergence, QuantLib's keeping the started caplets' negative times, so its engine refuses "negative times not
allowed", and knowing a caplet by its start, so between its fixing and its start it values the caplet as an option,
ignoring its fixing (discretizedcapfloor.cpp:55, :91; Divergences/TreeCapFloorSeasonedTests.cs,
Divergences/TreeKnownCouponTests.cs). A caplet still to be fixed whose start is before the reference date can
only be in arrears, and is valued at its fixing as any other, its start unread, where QuantLib's grid refuses its
negative start time ("negative times not allowed").
Its discount bonds. As DiscretizedSwap's: one bond to the payment, one to the start (or the index period's start) and one to the index period's end, re-initialized for each optionlet, their buffers reserved by Reset(int) at the widest step of the grid, so no optionlet's bonds allocate.
Constructors
DiscretizedCapFloor(CapFloor, Date, DayCounter, EvaluationContext)
Initializes a new instance of the DiscretizedCapFloor class.
public DiscretizedCapFloor(CapFloor capFloor, Date referenceDate, DayCounter dayCounter, EvaluationContext context)
Parameters
capFloorCapFloorThe cap, floor or collar.
referenceDateDateThe date of time 0.
dayCounterDayCounterThe day counter of the times.
contextEvaluationContextThe evaluation context, whose coupons' fixings and forecasts the known amounts read, and whose IncludeTodaysCashFlows decides a caplet paid on the reference date.
Exceptions
- ArgumentNullException
The cap, the day counter or the context is null.
- ArgumentException
referenceDateis default.- NanoQLException
A cash flow isn't a floating-rate coupon, or a forward can't be computed.
Methods
MandatoryTimes()
The asset's mandatory times: its non-negative start times, then its non-negative payment times, then the fixing times of the caplets valued there, then each in-arrears caplet's index period's start and end.
public override ImmutableArray<double> MandatoryTimes()
Returns
- ImmutableArray<double>
The times, not guaranteed to be sorted.
PostAdjustValuesImpl()
Adds the known optionlets whose payment is now, each its amount.
protected override void PostAdjustValuesImpl()
Exceptions
- NanoQLException
A known optionlet's forward isn't available.
PreAdjustValuesImpl()
Adds the optionlets still to be fixed whose fixing is now, or whose start is now for one fixed on its start, each an option on its discount bonds.
protected override void PreAdjustValuesImpl()
Reset(int)
Sets the values to 0 and adjusts them; on a tree lattice, it first reserves its discount bond's buffers at the widest step from the asset'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 asset isn't initialized, or a known caplet's forward isn't available.