Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
AverageONIndexedCouponPricer Class Reference

Pricer for average overnight indexed coupons. More...

#include <qle/cashflows/averageonindexedcouponpricer.hpp>

+ Inheritance diagram for AverageONIndexedCouponPricer:
+ Collaboration diagram for AverageONIndexedCouponPricer:

Public Types

enum  Approximation { Takada , None }
 

Public Member Functions

 AverageONIndexedCouponPricer (Approximation approxType=Takada)
 
void initialize (const FloatingRateCoupon &coupon) override
 
Rate swapletRate () const override
 
Real swapletPrice () const override
 
Real capletPrice (Rate) const override
 
Rate capletRate (Rate) const override
 
Real floorletPrice (Rate) const override
 
Rate floorletRate (Rate) const override
 

Protected Attributes

Approximation approximationType_
 
Real gearing_
 
Spread spread_
 
Time accrualPeriod_
 
QuantLib::ext::shared_ptr< OvernightIndex > overnightIndex_
 
const AverageONIndexedCouponcoupon_
 

Detailed Description

Pricer for average overnight indexed coupons.

Definition at line 38 of file averageonindexedcouponpricer.hpp.

Member Enumeration Documentation

◆ Approximation

Constructor & Destructor Documentation

◆ AverageONIndexedCouponPricer()

Member Function Documentation

◆ initialize()

void initialize ( const FloatingRateCoupon coupon)
override

Definition at line 23 of file averageonindexedcouponpricer.cpp.

23 {
24
25 coupon_ = dynamic_cast<const AverageONIndexedCoupon*>(&coupon);
26 QL_REQUIRE(coupon_, "AverageONIndexedCoupon required");
27
28 overnightIndex_ = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(coupon_->index());
29 QL_REQUIRE(overnightIndex_, "OvernightIndex required");
30
31 gearing_ = coupon_->gearing();
32 spread_ = coupon_->spread();
33 accrualPeriod_ = coupon_->accrualPeriod();
34}
QuantLib::ext::shared_ptr< OvernightIndex > overnightIndex_

◆ swapletRate()

Rate swapletRate ( ) const
override

Definition at line 36 of file averageonindexedcouponpricer.cpp.

36 {
37
38 std::vector<Date> fixingDates = coupon_->fixingDates();
39 std::vector<Time> accrualFractions = coupon_->dt();
40 Size numPeriods = accrualFractions.size();
41 Real accumulatedRate = 0;
42 QL_REQUIRE(coupon_->rateCutoff() < numPeriods,
43 "rate cutoff (" << coupon_->rateCutoff() << ") must be less than number of fixings in period ("
44 << numPeriods << ")");
45 Size nCutoff = numPeriods - coupon_->rateCutoff();
46
48 Size i = 0;
49 Date valuationDate = Settings::instance().evaluationDate();
50 // Deal with past fixings.
51 while (i < numPeriods && fixingDates[std::min(i, nCutoff)] < valuationDate) {
52 Rate pastFixing = overnightIndex_->pastFixing(fixingDates[std::min(i, nCutoff)]);
53 QL_REQUIRE(pastFixing != Null<Real>(),
54 "Missing " << overnightIndex_->name() << " fixing for " << fixingDates[std::min(i, nCutoff)]);
55 accumulatedRate += pastFixing * accrualFractions[i];
56 ++i;
57 }
58 // Use valuation date's fixing also if available.
59 if (i < numPeriods && fixingDates[std::min(i, nCutoff)] == valuationDate) {
60 Rate valuationDateFixing = overnightIndex_->pastFixing(valuationDate);
61 if (valuationDateFixing != Null<Real>()) {
62 accumulatedRate += valuationDateFixing * accrualFractions[i];
63 ++i;
64 }
65 }
66 // Use Takada approximation (2011) for forecasting.
67 if (i < numPeriods) {
68 Handle<YieldTermStructure> projectionCurve = overnightIndex_->forwardingTermStructure();
69 QL_REQUIRE(!projectionCurve.empty(),
70 "Null term structure set to this instance of " << overnightIndex_->name());
71
72 // handle the part until the rate cutoff (might be empty, i.e. startForecast = endForecast)
73 Date startForecast = coupon_->valueDates()[i];
74 Date endForecast = coupon_->valueDates()[std::max(nCutoff, i)];
75 DiscountFactor startDiscount = projectionCurve->discount(startForecast);
76 DiscountFactor endDiscount = projectionCurve->discount(endForecast);
77
78 // handle the rate cutoff period (if there is any, i.e. if nCutoff < n)
79 if (nCutoff < numPeriods) {
80 // forward discount factor for one calendar day on the cutoff date
81 DiscountFactor discountCutoffDate = projectionCurve->discount(coupon_->valueDates()[nCutoff] + 1) /
82 projectionCurve->discount(coupon_->valueDates()[nCutoff]);
83 // keep the above forward discount factor constant during the cutoff period
84 endDiscount *=
85 std::pow(discountCutoffDate, coupon_->valueDates()[numPeriods] - coupon_->valueDates()[nCutoff]);
86 }
87
88 accumulatedRate += log(startDiscount / endDiscount);
89 }
90 } else if (approximationType_ == None) {
91 std::vector<Rate> fixings = coupon_->indexFixings();
92 for (Size i = 0; i < numPeriods; ++i) {
93 accumulatedRate += fixings[i] * accrualFractions[i];
94 }
95 } else {
96 QL_FAIL("Invalid Approximation for AverageONIndexedCouponPricer");
97 }
98 // Return factor * rate + spread
99 Rate tau = overnightIndex_->dayCounter().yearFraction(coupon_->valueDates().front(), coupon_->valueDates().back());
100 Rate rate = gearing_ * accumulatedRate / tau + spread_;
101 return rate;
102}
Natural rateCutoff() const
rate cutoff associated with the coupon
const std::vector< Date > & valueDates() const
value dates for the rates to be averaged
const std::vector< Time > & dt() const
accrual periods for the averaging
const std::vector< Rate > & indexFixings() const
fixings to be averaged
const std::vector< Date > & fixingDates() const
fixing dates for the rates to be averaged
CompiledFormula log(CompiledFormula x)
+ Here is the call graph for this function:

◆ swapletPrice()

Real swapletPrice ( ) const
override

Definition at line 47 of file averageonindexedcouponpricer.hpp.

47{ QL_FAIL("swapletPrice not available"); }

◆ capletPrice()

Real capletPrice ( Rate  ) const
override

Definition at line 48 of file averageonindexedcouponpricer.hpp.

48{ QL_FAIL("capletPrice not available"); }

◆ capletRate()

Rate capletRate ( Rate  ) const
override

Definition at line 49 of file averageonindexedcouponpricer.hpp.

49{ QL_FAIL("capletRate not available"); }

◆ floorletPrice()

Real floorletPrice ( Rate  ) const
override

Definition at line 50 of file averageonindexedcouponpricer.hpp.

50{ QL_FAIL("floorletPrice not available"); }

◆ floorletRate()

Rate floorletRate ( Rate  ) const
override

Definition at line 51 of file averageonindexedcouponpricer.hpp.

51{ QL_FAIL("floorletRate not available"); }

Member Data Documentation

◆ approximationType_

Approximation approximationType_
protected

Definition at line 54 of file averageonindexedcouponpricer.hpp.

◆ gearing_

Real gearing_
protected

Definition at line 55 of file averageonindexedcouponpricer.hpp.

◆ spread_

Spread spread_
protected

Definition at line 56 of file averageonindexedcouponpricer.hpp.

◆ accrualPeriod_

Time accrualPeriod_
protected

Definition at line 57 of file averageonindexedcouponpricer.hpp.

◆ overnightIndex_

QuantLib::ext::shared_ptr<OvernightIndex> overnightIndex_
protected

Definition at line 58 of file averageonindexedcouponpricer.hpp.

◆ coupon_

const AverageONIndexedCoupon* coupon_
protected

Definition at line 60 of file averageonindexedcouponpricer.hpp.