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

helper class building a sequence of overnight coupons More...

#include <qle/cashflows/averageonindexedcoupon.hpp>

+ Collaboration diagram for AverageONLeg:

Public Member Functions

 AverageONLeg (const Schedule &schedule, const QuantLib::ext::shared_ptr< OvernightIndex > &overnightIndex)
 
AverageONLegwithNotional (Real notional)
 
AverageONLegwithNotionals (const std::vector< Real > &notionals)
 
AverageONLegwithPaymentDayCounter (const DayCounter &dayCounter)
 
AverageONLegwithPaymentAdjustment (BusinessDayConvention convention)
 
AverageONLegwithGearing (Real gearing)
 
AverageONLegwithGearings (const std::vector< Real > &gearings)
 
AverageONLegwithSpread (Spread spread)
 
AverageONLegwithSpreads (const std::vector< Spread > &spreads)
 
AverageONLegwithTelescopicValueDates (bool telescopicValueDates)
 
AverageONLegwithRateCutoff (Natural rateCutoff)
 
AverageONLegwithPaymentCalendar (const Calendar &calendar)
 
AverageONLegwithPaymentLag (Natural lag)
 
AverageONLegwithLookback (const Period &lookback)
 
AverageONLegwithFixingDays (const Size fixingDays)
 
AverageONLegwithCaps (Rate cap)
 
AverageONLegwithCaps (const std::vector< Rate > &caps)
 
AverageONLegwithFloors (Rate floor)
 
AverageONLegwithFloors (const std::vector< Rate > &floors)
 
AverageONLegincludeSpreadInCapFloors (bool includeSpread)
 
AverageONLegwithNakedOption (const bool nakedOption)
 
AverageONLegwithLocalCapFloor (const bool localCapFloor)
 
AverageONLegwithInArrears (const bool inArrears)
 
AverageONLegwithLastRecentPeriod (const boost::optional< Period > &lastRecentPeriod)
 
AverageONLegwithLastRecentPeriodCalendar (const Calendar &lastRecentPeriodCalendar)
 
AverageONLegwithPaymentDates (const std::vector< QuantLib::Date > &paymentDates)
 
AverageONLegwithAverageONIndexedCouponPricer (const QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer > &couponPricer)
 
AverageONLegwithCapFlooredAverageONIndexedCouponPricer (const QuantLib::ext::shared_ptr< CapFlooredAverageONIndexedCouponPricer > &couponPricer)
 
 operator Leg () const
 

Private Attributes

Schedule schedule_
 
QuantLib::ext::shared_ptr< OvernightIndex > overnightIndex_
 
std::vector< Real > notionals_
 
DayCounter paymentDayCounter_
 
BusinessDayConvention paymentAdjustment_
 
Natural paymentLag_
 
std::vector< Real > gearings_
 
std::vector< Spread > spreads_
 
bool telescopicValueDates_
 
Calendar paymentCalendar_
 
Natural rateCutoff_
 
Period lookback_
 
Natural fixingDays_
 
std::vector< Rate > caps_
 
std::vector< Rate > floors_
 
bool includeSpread_
 
bool nakedOption_
 
bool localCapFloor_
 
bool inArrears_
 
boost::optional< Period > lastRecentPeriod_
 
Calendar lastRecentPeriodCalendar_
 
std::vector< QuantLib::Date > paymentDates_
 
QuantLib::ext::shared_ptr< AverageONIndexedCouponPricercouponPricer_
 
QuantLib::ext::shared_ptr< CapFlooredAverageONIndexedCouponPricercapFlooredCouponPricer_
 

Detailed Description

helper class building a sequence of overnight coupons

Definition at line 179 of file averageonindexedcoupon.hpp.

Constructor & Destructor Documentation

◆ AverageONLeg()

AverageONLeg ( const Schedule &  schedule,
const QuantLib::ext::shared_ptr< OvernightIndex > &  overnightIndex 
)

Definition at line 295 of file averageonindexedcoupon.cpp.

296 : schedule_(schedule), overnightIndex_(i), paymentAdjustment_(Following), paymentLag_(0),
297 telescopicValueDates_(false), paymentCalendar_(schedule.calendar()), rateCutoff_(0), lookback_(0 * Days),
298 fixingDays_(Null<Size>()), includeSpread_(false), nakedOption_(false), localCapFloor_(false), inArrears_(true) {}
BusinessDayConvention paymentAdjustment_
QuantLib::ext::shared_ptr< OvernightIndex > overnightIndex_

Member Function Documentation

◆ withNotional()

AverageONLeg & withNotional ( Real  notional)

Definition at line 300 of file averageonindexedcoupon.cpp.

300 {
301 notionals_ = std::vector<Real>(1, notional);
302 return *this;
303}
+ Here is the caller graph for this function:

◆ withNotionals()

AverageONLeg & withNotionals ( const std::vector< Real > &  notionals)

Definition at line 305 of file averageonindexedcoupon.cpp.

305 {
306 notionals_ = notionals;
307 return *this;
308}
+ Here is the caller graph for this function:

◆ withPaymentDayCounter()

AverageONLeg & withPaymentDayCounter ( const DayCounter &  dayCounter)

Definition at line 310 of file averageonindexedcoupon.cpp.

310 {
311 paymentDayCounter_ = dayCounter;
312 return *this;
313}
+ Here is the caller graph for this function:

◆ withPaymentAdjustment()

AverageONLeg & withPaymentAdjustment ( BusinessDayConvention  convention)

Definition at line 315 of file averageonindexedcoupon.cpp.

315 {
316 paymentAdjustment_ = convention;
317 return *this;
318}
+ Here is the caller graph for this function:

◆ withGearing()

AverageONLeg & withGearing ( Real  gearing)

Definition at line 320 of file averageonindexedcoupon.cpp.

320 {
321 gearings_ = std::vector<Real>(1, gearing);
322 return *this;
323}
+ Here is the caller graph for this function:

◆ withGearings()

AverageONLeg & withGearings ( const std::vector< Real > &  gearings)

Definition at line 325 of file averageonindexedcoupon.cpp.

325 {
326 gearings_ = gearings;
327 return *this;
328}
+ Here is the caller graph for this function:

◆ withSpread()

AverageONLeg & withSpread ( Spread  spread)

Definition at line 330 of file averageonindexedcoupon.cpp.

330 {
331 spreads_ = std::vector<Spread>(1, spread);
332 return *this;
333}
std::vector< Spread > spreads_
+ Here is the caller graph for this function:

◆ withSpreads()

AverageONLeg & withSpreads ( const std::vector< Spread > &  spreads)

Definition at line 335 of file averageonindexedcoupon.cpp.

335 {
336 spreads_ = spreads;
337 return *this;
338}
+ Here is the caller graph for this function:

◆ withTelescopicValueDates()

AverageONLeg & withTelescopicValueDates ( bool  telescopicValueDates)

Definition at line 340 of file averageonindexedcoupon.cpp.

340 {
341 telescopicValueDates_ = telescopicValueDates;
342 return *this;
343}
+ Here is the caller graph for this function:

◆ withRateCutoff()

AverageONLeg & withRateCutoff ( Natural  rateCutoff)

Definition at line 345 of file averageonindexedcoupon.cpp.

345 {
346 rateCutoff_ = rateCutoff;
347 return *this;
348}
+ Here is the caller graph for this function:

◆ withPaymentCalendar()

AverageONLeg & withPaymentCalendar ( const Calendar &  calendar)

Definition at line 350 of file averageonindexedcoupon.cpp.

350 {
351 paymentCalendar_ = calendar;
352 return *this;
353}
+ Here is the caller graph for this function:

◆ withPaymentLag()

AverageONLeg & withPaymentLag ( Natural  lag)

Definition at line 355 of file averageonindexedcoupon.cpp.

355 {
356 paymentLag_ = lag;
357 return *this;
358}
+ Here is the caller graph for this function:

◆ withLookback()

AverageONLeg & withLookback ( const Period &  lookback)

Definition at line 360 of file averageonindexedcoupon.cpp.

360 {
361 lookback_ = lookback;
362 return *this;
363}
+ Here is the caller graph for this function:

◆ withFixingDays()

AverageONLeg & withFixingDays ( const Size  fixingDays)

Definition at line 365 of file averageonindexedcoupon.cpp.

365 {
366 fixingDays_ = fixingDays;
367 return *this;
368}
+ Here is the caller graph for this function:

◆ withCaps() [1/2]

AverageONLeg & withCaps ( Rate  cap)

Definition at line 370 of file averageonindexedcoupon.cpp.

370 {
371 caps_ = std::vector<Rate>(1, cap);
372 return *this;
373}

◆ withCaps() [2/2]

AverageONLeg & withCaps ( const std::vector< Rate > &  caps)

Definition at line 375 of file averageonindexedcoupon.cpp.

375 {
376 caps_ = caps;
377 return *this;
378}

◆ withFloors() [1/2]

AverageONLeg & withFloors ( Rate  floor)

Definition at line 380 of file averageonindexedcoupon.cpp.

380 {
381 floors_ = std::vector<Rate>(1, floor);
382 return *this;
383}

◆ withFloors() [2/2]

AverageONLeg & withFloors ( const std::vector< Rate > &  floors)

Definition at line 385 of file averageonindexedcoupon.cpp.

385 {
386 floors_ = floors;
387 return *this;
388}

◆ includeSpreadInCapFloors()

AverageONLeg & includeSpreadInCapFloors ( bool  includeSpread)

Definition at line 390 of file averageonindexedcoupon.cpp.

390 {
391 includeSpread_ = includeSpread;
392 return *this;
393}

◆ withNakedOption()

AverageONLeg & withNakedOption ( const bool  nakedOption)

Definition at line 395 of file averageonindexedcoupon.cpp.

395 {
396 nakedOption_ = nakedOption;
397 return *this;
398}

◆ withLocalCapFloor()

AverageONLeg & withLocalCapFloor ( const bool  localCapFloor)

Definition at line 400 of file averageonindexedcoupon.cpp.

400 {
401 localCapFloor_ = localCapFloor;
402 return *this;
403}

◆ withInArrears()

AverageONLeg & withInArrears ( const bool  inArrears)

Definition at line 405 of file averageonindexedcoupon.cpp.

405 {
406 inArrears_ = inArrears;
407 return *this;
408}

◆ withLastRecentPeriod()

AverageONLeg & withLastRecentPeriod ( const boost::optional< Period > &  lastRecentPeriod)

Definition at line 410 of file averageonindexedcoupon.cpp.

410 {
411 lastRecentPeriod_ = lastRecentPeriod;
412 return *this;
413}
boost::optional< Period > lastRecentPeriod_

◆ withLastRecentPeriodCalendar()

AverageONLeg & withLastRecentPeriodCalendar ( const Calendar &  lastRecentPeriodCalendar)

Definition at line 415 of file averageonindexedcoupon.cpp.

415 {
416 lastRecentPeriodCalendar_ = lastRecentPeriodCalendar;
417 return *this;
418}

◆ withPaymentDates()

AverageONLeg & withPaymentDates ( const std::vector< QuantLib::Date > &  paymentDates)

Definition at line 420 of file averageonindexedcoupon.cpp.

420 {
421 paymentDates_ = paymentDates;
422 return *this;
423}
std::vector< QuantLib::Date > paymentDates_

◆ withAverageONIndexedCouponPricer()

AverageONLeg & withAverageONIndexedCouponPricer ( const QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer > &  couponPricer)

Definition at line 426 of file averageonindexedcoupon.cpp.

426 {
427 couponPricer_ = couponPricer;
428 return *this;
429}
QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer > couponPricer_
+ Here is the caller graph for this function:

◆ withCapFlooredAverageONIndexedCouponPricer()

AverageONLeg & withCapFlooredAverageONIndexedCouponPricer ( const QuantLib::ext::shared_ptr< CapFlooredAverageONIndexedCouponPricer > &  couponPricer)

Definition at line 431 of file averageonindexedcoupon.cpp.

432 {
433 capFlooredCouponPricer_ = couponPricer;
434 return *this;
435}
QuantLib::ext::shared_ptr< CapFlooredAverageONIndexedCouponPricer > capFlooredCouponPricer_

◆ operator Leg()

operator Leg ( ) const

Definition at line 437 of file averageonindexedcoupon.cpp.

437 {
438
439 QL_REQUIRE(!notionals_.empty(), "No notional given for average overnight leg.");
440
441 Leg cashflows;
442
443 Calendar calendar = schedule_.calendar();
444 Calendar paymentCalendar = paymentCalendar_;
445
446 if (calendar.empty())
447 calendar = paymentCalendar;
448 if (calendar.empty())
449 calendar = WeekendsOnly();
450 if (paymentCalendar.empty())
451 paymentCalendar = calendar;
452
453 Date refStart, start, refEnd, end;
454 Date paymentDate;
455
456 Size n = schedule_.size() - 1;
457
458 // Initial consistency checks
459 if (!paymentDates_.empty()) {
460 QL_REQUIRE(paymentDates_.size() == n, "Expected the number of explicit payment dates ("
461 << paymentDates_.size()
462 << ") to equal the number of calculation periods ("
463 << n << ")");
464 }
465
466 for (Size i = 0; i < n; ++i) {
467 refStart = start = schedule_.date(i);
468 refEnd = end = schedule_.date(i + 1);
469
470 // If explicit payment dates provided, use them.
471 if (!paymentDates_.empty()) {
472 paymentDate = paymentDates_[i];
473 } else {
474 paymentDate = paymentCalendar.advance(end, paymentLag_, Days, paymentAdjustment_);
475 }
476
477 // determine refStart and refEnd
478
479 if (i == 0 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1))
480 refStart = calendar.adjust(end - schedule_.tenor(), paymentAdjustment_);
481 if (i == n - 1 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1))
482 refEnd = calendar.adjust(start + schedule_.tenor(), paymentAdjustment_);
483
484 // Determine the rate computation start and end date as
485 // - the coupon start and end date, if in arrears, and
486 // - the previous coupon start and end date, if in advance.
487 // In addition, adjust the start date, if a last recent period is given.
488
489 Date rateComputationStartDate, rateComputationEndDate;
490 if (inArrears_) {
491 // in arrears fixing (i.e. the "classic" case)
492 rateComputationStartDate = start;
493 rateComputationEndDate = end;
494 } else {
495 // handle in advance fixing
496 if (i > 0) {
497 // if there is a previous period, we take that
498 rateComputationStartDate = schedule_.date(i - 1);
499 rateComputationEndDate = schedule_.date(i);
500 } else {
501 // otherwise we construct the previous period
502 rateComputationEndDate = start;
503 if (schedule_.hasTenor() && schedule_.tenor() != 0 * Days)
504 rateComputationStartDate = calendar.adjust(start - schedule_.tenor(), Preceding);
505 else
506 rateComputationStartDate = calendar.adjust(start - (end - start), Preceding);
507 }
508 }
509
510 if (lastRecentPeriod_) {
511 rateComputationStartDate = (lastRecentPeriodCalendar_.empty() ? calendar : lastRecentPeriodCalendar_)
512 .advance(rateComputationEndDate, -*lastRecentPeriod_);
513 }
514
515 // build coupon
516
517 if (close_enough(detail::get(gearings_, i, 1.0), 0.0)) {
518 // fixed coupon
519 cashflows.push_back(QuantLib::ext::make_shared<FixedRateCoupon>(paymentDate, detail::get(notionals_, i, 1.0),
520 detail::get(spreads_, i, 0.0), paymentDayCounter_,
521 start, end, refStart, refEnd));
522 } else {
523 // floating coupon
524 auto cpn = QuantLib::ext::make_shared<AverageONIndexedCoupon>(
525 paymentDate, detail::get(notionals_, i, notionals_.back()), start, end, overnightIndex_,
526 detail::get(gearings_, i, 1.0), detail::get(spreads_, i, 0.0), rateCutoff_, paymentDayCounter_,
527 lookback_, fixingDays_, rateComputationStartDate, rateComputationEndDate, telescopicValueDates_);
528 if (couponPricer_) {
529 cpn->setPricer(couponPricer_);
530 }
531 Real cap = detail::get(caps_, i, Null<Real>());
532 Real floor = detail::get(floors_, i, Null<Real>());
533 if (cap == Null<Real>() && floor == Null<Real>()) {
534 cashflows.push_back(cpn);
535 } else {
536 auto cfCpn = ext::make_shared<CappedFlooredAverageONIndexedCoupon>(cpn, cap, floor, nakedOption_,
539 cfCpn->setPricer(capFlooredCouponPricer_);
540 }
541 cashflows.push_back(cfCpn);
542 }
543 }
544 }
545 return cashflows;
546}
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
+ Here is the call graph for this function:

Member Data Documentation

◆ schedule_

Schedule schedule_
private

Definition at line 213 of file averageonindexedcoupon.hpp.

◆ overnightIndex_

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

Definition at line 214 of file averageonindexedcoupon.hpp.

◆ notionals_

std::vector<Real> notionals_
private

Definition at line 215 of file averageonindexedcoupon.hpp.

◆ paymentDayCounter_

DayCounter paymentDayCounter_
private

Definition at line 216 of file averageonindexedcoupon.hpp.

◆ paymentAdjustment_

BusinessDayConvention paymentAdjustment_
private

Definition at line 217 of file averageonindexedcoupon.hpp.

◆ paymentLag_

Natural paymentLag_
private

Definition at line 218 of file averageonindexedcoupon.hpp.

◆ gearings_

std::vector<Real> gearings_
private

Definition at line 219 of file averageonindexedcoupon.hpp.

◆ spreads_

std::vector<Spread> spreads_
private

Definition at line 220 of file averageonindexedcoupon.hpp.

◆ telescopicValueDates_

bool telescopicValueDates_
private

Definition at line 221 of file averageonindexedcoupon.hpp.

◆ paymentCalendar_

Calendar paymentCalendar_
private

Definition at line 222 of file averageonindexedcoupon.hpp.

◆ rateCutoff_

Natural rateCutoff_
private

Definition at line 223 of file averageonindexedcoupon.hpp.

◆ lookback_

Period lookback_
private

Definition at line 224 of file averageonindexedcoupon.hpp.

◆ fixingDays_

Natural fixingDays_
private

Definition at line 225 of file averageonindexedcoupon.hpp.

◆ caps_

std::vector<Rate> caps_
private

Definition at line 226 of file averageonindexedcoupon.hpp.

◆ floors_

std::vector<Rate> floors_
private

Definition at line 226 of file averageonindexedcoupon.hpp.

◆ includeSpread_

bool includeSpread_
private

Definition at line 227 of file averageonindexedcoupon.hpp.

◆ nakedOption_

bool nakedOption_
private

Definition at line 228 of file averageonindexedcoupon.hpp.

◆ localCapFloor_

bool localCapFloor_
private

Definition at line 229 of file averageonindexedcoupon.hpp.

◆ inArrears_

bool inArrears_
private

Definition at line 230 of file averageonindexedcoupon.hpp.

◆ lastRecentPeriod_

boost::optional<Period> lastRecentPeriod_
private

Definition at line 231 of file averageonindexedcoupon.hpp.

◆ lastRecentPeriodCalendar_

Calendar lastRecentPeriodCalendar_
private

Definition at line 232 of file averageonindexedcoupon.hpp.

◆ paymentDates_

std::vector<QuantLib::Date> paymentDates_
private

Definition at line 233 of file averageonindexedcoupon.hpp.

◆ couponPricer_

QuantLib::ext::shared_ptr<AverageONIndexedCouponPricer> couponPricer_
private

Definition at line 234 of file averageonindexedcoupon.hpp.

◆ capFlooredCouponPricer_

QuantLib::ext::shared_ptr<CapFlooredAverageONIndexedCouponPricer> capFlooredCouponPricer_
private

Definition at line 235 of file averageonindexedcoupon.hpp.