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

OvernightIndexedCoupon pricer. More...

#include <qle/cashflows/overnightindexedcoupon.hpp>

+ Inheritance diagram for OvernightIndexedCouponPricer:
+ Collaboration diagram for OvernightIndexedCouponPricer:

Public Member Functions

void initialize (const FloatingRateCoupon &coupon) override
 
void compute () const
 
Rate swapletRate () const override
 
Rate effectiveSpread () const
 
Rate effectiveIndexFixing () const
 
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

const OvernightIndexedCouponcoupon_
 
Real swapletRate_
 
Real effectiveSpread_
 
Real effectiveIndexFixing_
 

Detailed Description

OvernightIndexedCoupon pricer.

Definition at line 133 of file overnightindexedcoupon.hpp.

Member Function Documentation

◆ initialize()

void initialize ( const FloatingRateCoupon coupon)
override

Definition at line 190 of file overnightindexedcoupon.cpp.

190 {
191 coupon_ = dynamic_cast<const OvernightIndexedCoupon*>(&coupon);
192 QL_ENSURE(coupon_, "wrong coupon type");
193}

◆ compute()

void compute ( ) const

Definition at line 195 of file overnightindexedcoupon.cpp.

195 {
196 ext::shared_ptr<OvernightIndex> index = ext::dynamic_pointer_cast<OvernightIndex>(coupon_->index());
197
198 const vector<Date>& fixingDates = coupon_->fixingDates();
199 const vector<Time>& dt = coupon_->dt();
200
201 Size n = dt.size();
202 Size i = 0;
203 QL_REQUIRE(coupon_->rateCutoff() < n, "rate cutoff (" << coupon_->rateCutoff()
204 << ") must be less than number of fixings in period (" << n
205 << ")");
206 Size nCutoff = n - coupon_->rateCutoff();
207
208 Real compoundFactor = 1.0, compoundFactorWithoutSpread = 1.0;
209
210 // already fixed part
211 Date today = Settings::instance().evaluationDate();
212 while (i < n && fixingDates[std::min(i, nCutoff)] < today) {
213 // rate must have been fixed
214 Rate pastFixing = index->pastFixing(fixingDates[std::min(i, nCutoff)]);
215 QL_REQUIRE(pastFixing != Null<Real>(),
216 "Missing " << index->name() << " fixing for " << fixingDates[std::min(i, nCutoff)]);
217 if (coupon_->includeSpread()) {
218 compoundFactorWithoutSpread *= (1.0 + pastFixing * dt[i]);
219 pastFixing += coupon_->spread();
220 }
221 compoundFactor *= (1.0 + pastFixing * dt[i]);
222 ++i;
223 }
224
225 // today is a border case
226 if (i < n && fixingDates[std::min(i, nCutoff)] == today) {
227 // might have been fixed
228 try {
229 Rate pastFixing = index->pastFixing(fixingDates[std::min(i, nCutoff)]);
230 if (pastFixing != Null<Real>()) {
231 if (coupon_->includeSpread()) {
232 compoundFactorWithoutSpread *= (1.0 + pastFixing * dt[i]);
233 pastFixing += coupon_->spread();
234 }
235 compoundFactor *= (1.0 + pastFixing * dt[i]);
236 ++i;
237 } else {
238 ; // fall through and forecast
239 }
240 } catch (Error&) {
241 ; // fall through and forecast
242 }
243 }
244
245 // forward part using telescopic property in order
246 // to avoid the evaluation of multiple forward fixings
247 const vector<Date>& dates = coupon_->valueDates();
248 if (i < n) {
249 Handle<YieldTermStructure> curve = index->forwardingTermStructure();
250 QL_REQUIRE(!curve.empty(), "null term structure set to this instance of " << index->name());
251
252 // handle the part until the rate cutoff (might be empty, i.e. startDiscount = endDiscount)
253 DiscountFactor startDiscount = curve->discount(dates[i]);
254 DiscountFactor endDiscount = curve->discount(dates[std::max(nCutoff, i)]);
255
256 // handle the rate cutoff period (if there is any, i.e. if nCutoff < n)
257 if (nCutoff < n) {
258 // forward discount factor for one calendar day on the cutoff date
259 DiscountFactor discountCutoffDate = curve->discount(dates[nCutoff] + 1) / curve->discount(dates[nCutoff]);
260 // keep the above forward discount factor constant during the cutoff period
261 endDiscount *= std::pow(discountCutoffDate, dates[n] - dates[nCutoff]);
262 }
263
264 compoundFactor *= startDiscount / endDiscount;
265
266 if (coupon_->includeSpread()) {
267 compoundFactorWithoutSpread *= startDiscount / endDiscount;
268 // this is an approximation, see "Ester / Daily Spread Curve Setup in ORE":
269 // set tau to an average value
270 Real tau = index->dayCounter().yearFraction(dates[i], dates.back()) / (dates.back() - dates[i]);
271 // now use formula (4) from the paper
272 compoundFactor *= std::pow(1.0 + tau * coupon_->spread(), static_cast<int>(dates.back() - dates[i]));
273 }
274 }
275
276 Rate tau = index->dayCounter().yearFraction(dates.front(), dates.back());
277 Rate rate = (compoundFactor - 1.0) / tau;
278 swapletRate_ = coupon_->gearing() * rate;
279 if (!coupon_->includeSpread()) {
280 swapletRate_ += coupon_->spread();
281 effectiveSpread_ = coupon_->spread();
283 } else {
284 effectiveSpread_ = rate - (compoundFactorWithoutSpread - 1.0) / tau;
286 }
287}
bool includeSpread() const
include spread in compounding?
const std::vector< Date > & valueDates() const
value dates for the rates to be compounded
const std::vector< Time > & dt() const
accrual (compounding) periods
const std::vector< Date > & fixingDates() const
fixing dates for the rates to be compounded
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ swapletRate()

Rate swapletRate ( ) const
override

Definition at line 289 of file overnightindexedcoupon.cpp.

289 {
290 compute();
291 return swapletRate_;
292}
+ Here is the call graph for this function:

◆ effectiveSpread()

Rate effectiveSpread ( ) const

Definition at line 294 of file overnightindexedcoupon.cpp.

294 {
295 compute();
296 return effectiveSpread_;
297}
+ Here is the call graph for this function:

◆ effectiveIndexFixing()

Rate effectiveIndexFixing ( ) const

Definition at line 299 of file overnightindexedcoupon.cpp.

299 {
300 compute();
302}
+ Here is the call graph for this function:

◆ swapletPrice()

Real swapletPrice ( ) const
override

Definition at line 140 of file overnightindexedcoupon.hpp.

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

◆ capletPrice()

Real capletPrice ( Rate  ) const
override

Definition at line 141 of file overnightindexedcoupon.hpp.

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

◆ capletRate()

Rate capletRate ( Rate  ) const
override

Definition at line 142 of file overnightindexedcoupon.hpp.

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

◆ floorletPrice()

Real floorletPrice ( Rate  ) const
override

Definition at line 143 of file overnightindexedcoupon.hpp.

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

◆ floorletRate()

Rate floorletRate ( Rate  ) const
override

Definition at line 144 of file overnightindexedcoupon.hpp.

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

Member Data Documentation

◆ coupon_

const OvernightIndexedCoupon* coupon_
protected

Definition at line 147 of file overnightindexedcoupon.hpp.

◆ swapletRate_

Real swapletRate_
mutableprotected

Definition at line 148 of file overnightindexedcoupon.hpp.

◆ effectiveSpread_

Real effectiveSpread_
protected

Definition at line 148 of file overnightindexedcoupon.hpp.

◆ effectiveIndexFixing_

Real effectiveIndexFixing_
protected

Definition at line 148 of file overnightindexedcoupon.hpp.