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

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

#include <qle/cashflows/overnightindexedcoupon.hpp>

+ Collaboration diagram for OvernightLeg:

Public Member Functions

 OvernightLeg (const Schedule &schedule, const ext::shared_ptr< OvernightIndex > &overnightIndex)
 
OvernightLegwithNotionals (Real notional)
 
OvernightLegwithNotionals (const std::vector< Real > &notionals)
 
OvernightLegwithPaymentDayCounter (const DayCounter &)
 
OvernightLegwithPaymentAdjustment (BusinessDayConvention)
 
OvernightLegwithPaymentCalendar (const Calendar &)
 
OvernightLegwithPaymentLag (Natural lag)
 
OvernightLegwithGearings (Real gearing)
 
OvernightLegwithGearings (const std::vector< Real > &gearings)
 
OvernightLegwithSpreads (Spread spread)
 
OvernightLegwithSpreads (const std::vector< Spread > &spreads)
 
OvernightLegwithTelescopicValueDates (bool telescopicValueDates)
 
OvernightLegincludeSpread (bool includeSpread)
 
OvernightLegwithLookback (const Period &lookback)
 
OvernightLegwithRateCutoff (const Natural rateCutoff)
 
OvernightLegwithFixingDays (const Natural fixingDays)
 
OvernightLegwithCaps (Rate cap)
 
OvernightLegwithCaps (const std::vector< Rate > &caps)
 
OvernightLegwithFloors (Rate floor)
 
OvernightLegwithFloors (const std::vector< Rate > &floors)
 
OvernightLegwithNakedOption (const bool nakedOption)
 
OvernightLegwithLocalCapFloor (const bool localCapFloor)
 
OvernightLegwithInArrears (const bool inArrears)
 
OvernightLegwithLastRecentPeriod (const boost::optional< Period > &lastRecentPeriod)
 
OvernightLegwithLastRecentPeriodCalendar (const Calendar &lastRecentPeriodCalendar)
 
OvernightLegwithOvernightIndexedCouponPricer (const QuantLib::ext::shared_ptr< OvernightIndexedCouponPricer > &couponPricer)
 
OvernightLegwithPaymentDates (const std::vector< Date > &paymentDates)
 
OvernightLegwithCapFlooredOvernightIndexedCouponPricer (const QuantLib::ext::shared_ptr< CappedFlooredOvernightIndexedCouponPricer > &couponPricer)
 
 operator Leg () const
 

Private Attributes

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

Detailed Description

helper class building a sequence of overnight coupons

Definition at line 229 of file overnightindexedcoupon.hpp.

Constructor & Destructor Documentation

◆ OvernightLeg()

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

Definition at line 469 of file overnightindexedcoupon.cpp.

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

Member Function Documentation

◆ withNotionals() [1/2]

OvernightLeg & withNotionals ( Real  notional)

Definition at line 474 of file overnightindexedcoupon.cpp.

474 {
475 notionals_ = vector<Real>(1, notional);
476 return *this;
477}
+ Here is the caller graph for this function:

◆ withNotionals() [2/2]

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

Definition at line 479 of file overnightindexedcoupon.cpp.

479 {
480 notionals_ = notionals;
481 return *this;
482}

◆ withPaymentDayCounter()

OvernightLeg & withPaymentDayCounter ( const DayCounter &  dc)

Definition at line 484 of file overnightindexedcoupon.cpp.

484 {
486 return *this;
487}
+ Here is the caller graph for this function:

◆ withPaymentAdjustment()

OvernightLeg & withPaymentAdjustment ( BusinessDayConvention  convention)

Definition at line 489 of file overnightindexedcoupon.cpp.

489 {
490 paymentAdjustment_ = convention;
491 return *this;
492}
+ Here is the caller graph for this function:

◆ withPaymentCalendar()

OvernightLeg & withPaymentCalendar ( const Calendar &  cal)

Definition at line 494 of file overnightindexedcoupon.cpp.

494 {
495 paymentCalendar_ = cal;
496 return *this;
497}

◆ withPaymentLag()

OvernightLeg & withPaymentLag ( Natural  lag)

Definition at line 499 of file overnightindexedcoupon.cpp.

499 {
500 paymentLag_ = lag;
501 return *this;
502}
+ Here is the caller graph for this function:

◆ withGearings() [1/2]

OvernightLeg & withGearings ( Real  gearing)

Definition at line 504 of file overnightindexedcoupon.cpp.

504 {
505 gearings_ = vector<Real>(1, gearing);
506 return *this;
507}
+ Here is the caller graph for this function:

◆ withGearings() [2/2]

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

Definition at line 509 of file overnightindexedcoupon.cpp.

509 {
510 gearings_ = gearings;
511 return *this;
512}

◆ withSpreads() [1/2]

OvernightLeg & withSpreads ( Spread  spread)

Definition at line 514 of file overnightindexedcoupon.cpp.

514 {
515 spreads_ = vector<Spread>(1, spread);
516 return *this;
517}
std::vector< Spread > spreads_
+ Here is the caller graph for this function:

◆ withSpreads() [2/2]

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

Definition at line 519 of file overnightindexedcoupon.cpp.

519 {
520 spreads_ = spreads;
521 return *this;
522}

◆ withTelescopicValueDates()

OvernightLeg & withTelescopicValueDates ( bool  telescopicValueDates)

Definition at line 524 of file overnightindexedcoupon.cpp.

524 {
525 telescopicValueDates_ = telescopicValueDates;
526 return *this;
527}
+ Here is the caller graph for this function:

◆ includeSpread()

OvernightLeg & includeSpread ( bool  includeSpread)

Definition at line 529 of file overnightindexedcoupon.cpp.

529 {
531 return *this;
532}
OvernightLeg & includeSpread(bool includeSpread)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withLookback()

OvernightLeg & withLookback ( const Period &  lookback)

Definition at line 534 of file overnightindexedcoupon.cpp.

534 {
535 lookback_ = lookback;
536 return *this;
537}
+ Here is the caller graph for this function:

◆ withRateCutoff()

OvernightLeg & withRateCutoff ( const Natural  rateCutoff)

Definition at line 539 of file overnightindexedcoupon.cpp.

539 {
540 rateCutoff_ = rateCutoff;
541 return *this;
542}
+ Here is the caller graph for this function:

◆ withFixingDays()

OvernightLeg & withFixingDays ( const Natural  fixingDays)

Definition at line 544 of file overnightindexedcoupon.cpp.

544 {
545 fixingDays_ = fixingDays;
546 return *this;
547}
+ Here is the caller graph for this function:

◆ withCaps() [1/2]

OvernightLeg & withCaps ( Rate  cap)

Definition at line 549 of file overnightindexedcoupon.cpp.

549 {
550 caps_ = std::vector<Rate>(1, cap);
551 return *this;
552}
+ Here is the caller graph for this function:

◆ withCaps() [2/2]

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

Definition at line 554 of file overnightindexedcoupon.cpp.

554 {
555 caps_ = caps;
556 return *this;
557}

◆ withFloors() [1/2]

OvernightLeg & withFloors ( Rate  floor)

Definition at line 559 of file overnightindexedcoupon.cpp.

559 {
560 floors_ = std::vector<Rate>(1, floor);
561 return *this;
562}
+ Here is the caller graph for this function:

◆ withFloors() [2/2]

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

Definition at line 564 of file overnightindexedcoupon.cpp.

564 {
565 floors_ = floors;
566 return *this;
567}

◆ withNakedOption()

OvernightLeg & withNakedOption ( const bool  nakedOption)

Definition at line 569 of file overnightindexedcoupon.cpp.

569 {
570 nakedOption_ = nakedOption;
571 return *this;
572}
+ Here is the caller graph for this function:

◆ withLocalCapFloor()

OvernightLeg & withLocalCapFloor ( const bool  localCapFloor)

Definition at line 574 of file overnightindexedcoupon.cpp.

574 {
575 localCapFloor_ = localCapFloor;
576 return *this;
577}

◆ withInArrears()

OvernightLeg & withInArrears ( const bool  inArrears)

Definition at line 579 of file overnightindexedcoupon.cpp.

579 {
580 inArrears_ = inArrears;
581 return *this;
582}

◆ withLastRecentPeriod()

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

Definition at line 584 of file overnightindexedcoupon.cpp.

584 {
585 lastRecentPeriod_ = lastRecentPeriod;
586 return *this;
587}
boost::optional< Period > lastRecentPeriod_

◆ withLastRecentPeriodCalendar()

OvernightLeg & withLastRecentPeriodCalendar ( const Calendar &  lastRecentPeriodCalendar)

Definition at line 589 of file overnightindexedcoupon.cpp.

589 {
590 lastRecentPeriodCalendar_ = lastRecentPeriodCalendar;
591 return *this;
592}

◆ withOvernightIndexedCouponPricer()

OvernightLeg & withOvernightIndexedCouponPricer ( const QuantLib::ext::shared_ptr< OvernightIndexedCouponPricer > &  couponPricer)

Definition at line 600 of file overnightindexedcoupon.cpp.

600 {
601 couponPricer_ = couponPricer;
602 return *this;
603}
QuantLib::ext::shared_ptr< OvernightIndexedCouponPricer > couponPricer_

◆ withPaymentDates()

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

Definition at line 594 of file overnightindexedcoupon.cpp.

594 {
595 paymentDates_ = paymentDates;
596 return *this;
597}
std::vector< QuantLib::Date > paymentDates_

◆ withCapFlooredOvernightIndexedCouponPricer()

OvernightLeg & withCapFlooredOvernightIndexedCouponPricer ( const QuantLib::ext::shared_ptr< CappedFlooredOvernightIndexedCouponPricer > &  couponPricer)

Definition at line 605 of file overnightindexedcoupon.cpp.

606 {
607 capFlooredCouponPricer_ = couponPricer;
608 return *this;
609}
QuantLib::ext::shared_ptr< CappedFlooredOvernightIndexedCouponPricer > capFlooredCouponPricer_

◆ operator Leg()

operator Leg ( ) const

Definition at line 611 of file overnightindexedcoupon.cpp.

611 {
612
613 QL_REQUIRE(!notionals_.empty(), "no notional given for compounding overnight leg");
614
615 Leg cashflows;
616
617 Calendar calendar = schedule_.calendar();
618 Calendar paymentCalendar = paymentCalendar_;
619
620 if (calendar.empty())
621 calendar = paymentCalendar;
622 if (calendar.empty())
623 calendar = WeekendsOnly();
624 if (paymentCalendar.empty())
625 paymentCalendar = calendar;
626
627 Date refStart, start, refEnd, end;
628 Date paymentDate;
629
630 Size n = schedule_.size() - 1;
631
632 // Initial consistency checks
633 if (!paymentDates_.empty()) {
634 QL_REQUIRE(paymentDates_.size() == n, "Expected the number of explicit payment dates ("
635 << paymentDates_.size()
636 << ") to equal the number of calculation periods ("
637 << n << ")");
638 }
639
640 for (Size i = 0; i < n; ++i) {
641 refStart = start = schedule_.date(i);
642 refEnd = end = schedule_.date(i + 1);
643
644 // If explicit payment dates provided, use them.
645 if (!paymentDates_.empty()) {
646 paymentDate = paymentDates_[i];
647 } else {
648 paymentDate = paymentCalendar.advance(end, paymentLag_, Days, paymentAdjustment_);
649 }
650
651 // determine refStart and refEnd
652
653 if (i == 0 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1))
654 refStart = calendar.adjust(end - schedule_.tenor(), paymentAdjustment_);
655 if (i == n - 1 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1))
656 refEnd = calendar.adjust(start + schedule_.tenor(), paymentAdjustment_);
657
658 // Determine the rate computation start and end date as
659 // - the coupon start and end date, if in arrears, and
660 // - the previous coupon start and end date, if in advance.
661 // In addition, adjust the start date, if a last recent period is given.
662
663 Date rateComputationStartDate, rateComputationEndDate;
664 if (inArrears_) {
665 // in arrears fixing (i.e. the "classic" case)
666 rateComputationStartDate = start;
667 rateComputationEndDate = end;
668 } else {
669 // handle in advance fixing
670 if (i > 0) {
671 // if there is a previous period, we take that
672 rateComputationStartDate = schedule_.date(i - 1);
673 rateComputationEndDate = schedule_.date(i);
674 } else {
675 // otherwise we construct the previous period
676 rateComputationEndDate = start;
677 if (schedule_.hasTenor() && schedule_.tenor() != 0 * Days)
678 rateComputationStartDate = calendar.adjust(start - schedule_.tenor(), Preceding);
679 else
680 rateComputationStartDate = calendar.adjust(start - (end - start), Preceding);
681 }
682 }
683
684 if (lastRecentPeriod_) {
685 rateComputationStartDate = (lastRecentPeriodCalendar_.empty() ? calendar : lastRecentPeriodCalendar_)
686 .advance(rateComputationEndDate, -*lastRecentPeriod_);
687 }
688
689 // build coupon
690
691 if (close_enough(detail::get(gearings_, i, 1.0), 0.0)) {
692 // fixed coupon
693 cashflows.push_back(QuantLib::ext::make_shared<FixedRateCoupon>(
694 paymentDate, detail::get(notionals_, i, 1.0), detail::effectiveFixedRate(spreads_, caps_, floors_, i),
695 paymentDayCounter_, start, end, refStart, refEnd));
696 } else {
697 // floating coupon
698 auto cpn = ext::make_shared<OvernightIndexedCoupon>(
699 paymentDate, detail::get(notionals_, i, 1.0), start, end, overnightIndex_,
700 detail::get(gearings_, i, 1.0), detail::get(spreads_, i, 0.0), refStart, refEnd, paymentDayCounter_,
702 rateComputationEndDate);
703 if (couponPricer_) {
704 cpn->setPricer(couponPricer_);
705 }
706 Real cap = detail::get(caps_, i, Null<Real>());
707 Real floor = detail::get(floors_, i, Null<Real>());
708 if (cap == Null<Real>() && floor == Null<Real>()) {
709 cashflows.push_back(cpn);
710 } else {
711 auto cfCpn = ext::make_shared<CappedFlooredOvernightIndexedCoupon>(cpn, cap, floor, nakedOption_,
714 cfCpn->setPricer(capFlooredCouponPricer_);
715 }
716 cashflows.push_back(cfCpn);
717 }
718 }
719 }
720 return cashflows;
721}
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 263 of file overnightindexedcoupon.hpp.

◆ overnightIndex_

ext::shared_ptr<OvernightIndex> overnightIndex_
private

Definition at line 264 of file overnightindexedcoupon.hpp.

◆ notionals_

std::vector<Real> notionals_
private

Definition at line 265 of file overnightindexedcoupon.hpp.

◆ paymentDayCounter_

DayCounter paymentDayCounter_
private

Definition at line 266 of file overnightindexedcoupon.hpp.

◆ paymentCalendar_

Calendar paymentCalendar_
private

Definition at line 267 of file overnightindexedcoupon.hpp.

◆ paymentAdjustment_

BusinessDayConvention paymentAdjustment_
private

Definition at line 268 of file overnightindexedcoupon.hpp.

◆ paymentLag_

Natural paymentLag_
private

Definition at line 269 of file overnightindexedcoupon.hpp.

◆ gearings_

std::vector<Real> gearings_
private

Definition at line 270 of file overnightindexedcoupon.hpp.

◆ spreads_

std::vector<Spread> spreads_
private

Definition at line 271 of file overnightindexedcoupon.hpp.

◆ telescopicValueDates_

bool telescopicValueDates_
private

Definition at line 272 of file overnightindexedcoupon.hpp.

◆ includeSpread_

bool includeSpread_
private

Definition at line 273 of file overnightindexedcoupon.hpp.

◆ lookback_

Period lookback_
private

Definition at line 274 of file overnightindexedcoupon.hpp.

◆ rateCutoff_

Natural rateCutoff_
private

Definition at line 275 of file overnightindexedcoupon.hpp.

◆ fixingDays_

Natural fixingDays_
private

Definition at line 276 of file overnightindexedcoupon.hpp.

◆ caps_

std::vector<Rate> caps_
private

Definition at line 277 of file overnightindexedcoupon.hpp.

◆ floors_

std::vector<Rate> floors_
private

Definition at line 277 of file overnightindexedcoupon.hpp.

◆ nakedOption_

bool nakedOption_
private

Definition at line 278 of file overnightindexedcoupon.hpp.

◆ localCapFloor_

bool localCapFloor_
private

Definition at line 279 of file overnightindexedcoupon.hpp.

◆ inArrears_

bool inArrears_
private

Definition at line 280 of file overnightindexedcoupon.hpp.

◆ lastRecentPeriod_

boost::optional<Period> lastRecentPeriod_
private

Definition at line 281 of file overnightindexedcoupon.hpp.

◆ lastRecentPeriodCalendar_

Calendar lastRecentPeriodCalendar_
private

Definition at line 282 of file overnightindexedcoupon.hpp.

◆ paymentDates_

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

Definition at line 283 of file overnightindexedcoupon.hpp.

◆ couponPricer_

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

Definition at line 284 of file overnightindexedcoupon.hpp.

◆ capFlooredCouponPricer_

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

Definition at line 285 of file overnightindexedcoupon.hpp.