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

helper class building a sequence of formula based coupons More...

#include <qle/cashflows/formulabasedcoupon.hpp>

+ Collaboration diagram for FormulaBasedLeg:

Public Member Functions

 FormulaBasedLeg (const Currency &paymentCurrency, const Schedule &schedule, const QuantLib::ext::shared_ptr< FormulaBasedIndex > &index)
 
FormulaBasedLegwithNotionals (Real notional)
 
FormulaBasedLegwithNotionals (const std::vector< Real > &notionals)
 
FormulaBasedLegwithPaymentDayCounter (const DayCounter &)
 
FormulaBasedLegwithPaymentAdjustment (BusinessDayConvention)
 
FormulaBasedLegwithPaymentLag (Natural lag)
 
FormulaBasedLegwithPaymentCalendar (const Calendar &)
 
FormulaBasedLegwithFixingDays (Natural fixingDays)
 
FormulaBasedLegwithFixingDays (const std::vector< Natural > &fixingDays)
 
FormulaBasedLeginArrears (bool flag=true)
 
FormulaBasedLegwithZeroPayments (bool flag=true)
 
 operator Leg () const
 

Private Attributes

Currency paymentCurrency_
 
Schedule schedule_
 
QuantLib::ext::shared_ptr< FormulaBasedIndexindex_
 
std::vector< Real > notionals_
 
DayCounter paymentDayCounter_
 
BusinessDayConvention paymentAdjustment_
 
Natural paymentLag_
 
Calendar paymentCalendar_
 
std::vector< Natural > fixingDays_
 
bool inArrears_
 
bool zeroPayments_
 

Detailed Description

helper class building a sequence of formula based coupons

Definition at line 60 of file formulabasedcoupon.hpp.

Constructor & Destructor Documentation

◆ FormulaBasedLeg()

FormulaBasedLeg ( const Currency &  paymentCurrency,
const Schedule &  schedule,
const QuantLib::ext::shared_ptr< FormulaBasedIndex > &  index 
)

Definition at line 43 of file formulabasedcoupon.cpp.

45 : paymentCurrency_(paymentCurrency), schedule_(schedule), index_(index), paymentAdjustment_(Following),
46 paymentLag_(0), inArrears_(false), zeroPayments_(false) {}
BusinessDayConvention paymentAdjustment_
QuantLib::ext::shared_ptr< FormulaBasedIndex > index_

Member Function Documentation

◆ withNotionals() [1/2]

FormulaBasedLeg & withNotionals ( Real  notional)

Definition at line 48 of file formulabasedcoupon.cpp.

48 {
49 notionals_ = std::vector<Real>(1, notional);
50 return *this;
51}
std::vector< Real > notionals_

◆ withNotionals() [2/2]

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

Definition at line 53 of file formulabasedcoupon.cpp.

53 {
54 notionals_ = notionals;
55 return *this;
56}

◆ withPaymentDayCounter()

FormulaBasedLeg & withPaymentDayCounter ( const DayCounter &  )

Definition at line 58 of file formulabasedcoupon.cpp.

58 {
59 paymentDayCounter_ = dayCounter;
60 return *this;
61}

◆ withPaymentAdjustment()

FormulaBasedLeg & withPaymentAdjustment ( BusinessDayConvention  convention)

Definition at line 63 of file formulabasedcoupon.cpp.

63 {
64 paymentAdjustment_ = convention;
65 return *this;
66}

◆ withPaymentLag()

FormulaBasedLeg & withPaymentLag ( Natural  lag)

Definition at line 68 of file formulabasedcoupon.cpp.

68 {
69 paymentLag_ = lag;
70 return *this;
71}

◆ withPaymentCalendar()

FormulaBasedLeg & withPaymentCalendar ( const Calendar &  )

Definition at line 73 of file formulabasedcoupon.cpp.

73 {
74 paymentCalendar_ = cal;
75 return *this;
76}

◆ withFixingDays() [1/2]

FormulaBasedLeg & withFixingDays ( Natural  fixingDays)

Definition at line 78 of file formulabasedcoupon.cpp.

78 {
79 fixingDays_ = std::vector<Natural>(1, fixingDays);
80 return *this;
81}
std::vector< Natural > fixingDays_

◆ withFixingDays() [2/2]

FormulaBasedLeg & withFixingDays ( const std::vector< Natural > &  fixingDays)

Definition at line 83 of file formulabasedcoupon.cpp.

83 {
84 fixingDays_ = fixingDays;
85 return *this;
86}

◆ inArrears()

FormulaBasedLeg & inArrears ( bool  flag = true)

Definition at line 88 of file formulabasedcoupon.cpp.

88 {
89 inArrears_ = flag;
90 return *this;
91}

◆ withZeroPayments()

FormulaBasedLeg & withZeroPayments ( bool  flag = true)

Definition at line 93 of file formulabasedcoupon.cpp.

93 {
94 zeroPayments_ = flag;
95 return *this;
96}

◆ operator Leg()

operator Leg ( ) const

Definition at line 98 of file formulabasedcoupon.cpp.

98 {
99
100 // unfortunately we have to copy this from ql/cashflows/cashflowvectors and modify it to
101 // match the formula based coupon ctor, which is a bit different from other flr coupons
102
103 Size n = schedule_.size() - 1;
104 QL_REQUIRE(!notionals_.empty(), "no notional given");
105 QL_REQUIRE(notionals_.size() <= n, "too many nominals (" << notionals_.size() << "), only " << n << " required");
106 QL_REQUIRE(!zeroPayments_ || !inArrears_, "in-arrears and zero features are not compatible");
107
108 Leg leg;
109 leg.reserve(n);
110
111 Calendar calendar = schedule_.calendar().empty() ? NullCalendar() : schedule_.calendar();
112 Calendar paymentCalendar = paymentCalendar_.empty() ? calendar : paymentCalendar_;
113
114 Date refStart, start, refEnd, end;
115 Date lastPaymentDate = paymentCalendar.advance(schedule_.date(n), paymentLag_, Days, paymentAdjustment_);
116
117 for (Size i = 0; i < n; ++i) {
118 refStart = start = schedule_.date(i);
119 refEnd = end = schedule_.date(i + 1);
120 Date paymentDate =
121 zeroPayments_ ? lastPaymentDate : paymentCalendar.advance(end, paymentLag_, Days, paymentAdjustment_);
122 if (i == 0 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1)) {
123 BusinessDayConvention bdc = schedule_.businessDayConvention();
124 refStart = calendar.adjust(end - schedule_.tenor(), bdc);
125 }
126 if (i == n - 1 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1)) {
127 BusinessDayConvention bdc = schedule_.businessDayConvention();
128 refEnd = calendar.adjust(start + schedule_.tenor(), bdc);
129 }
130 leg.push_back(QuantLib::ext::shared_ptr<CashFlow>(
131 new FormulaBasedCoupon(paymentCurrency_, paymentDate, detail::get(notionals_, i, 1.0), start, end,
132 detail::get(fixingDays_, i, index_->fixingDays()), index_, refStart, refEnd,
134 }
135 return leg;
136}

Member Data Documentation

◆ paymentCurrency_

Currency paymentCurrency_
private

Definition at line 77 of file formulabasedcoupon.hpp.

◆ schedule_

Schedule schedule_
private

Definition at line 78 of file formulabasedcoupon.hpp.

◆ index_

QuantLib::ext::shared_ptr<FormulaBasedIndex> index_
private

Definition at line 79 of file formulabasedcoupon.hpp.

◆ notionals_

std::vector<Real> notionals_
private

Definition at line 80 of file formulabasedcoupon.hpp.

◆ paymentDayCounter_

DayCounter paymentDayCounter_
private

Definition at line 81 of file formulabasedcoupon.hpp.

◆ paymentAdjustment_

BusinessDayConvention paymentAdjustment_
private

Definition at line 82 of file formulabasedcoupon.hpp.

◆ paymentLag_

Natural paymentLag_
private

Definition at line 83 of file formulabasedcoupon.hpp.

◆ paymentCalendar_

Calendar paymentCalendar_
private

Definition at line 84 of file formulabasedcoupon.hpp.

◆ fixingDays_

std::vector<Natural> fixingDays_
private

Definition at line 85 of file formulabasedcoupon.hpp.

◆ inArrears_

bool inArrears_
private

Definition at line 86 of file formulabasedcoupon.hpp.

◆ zeroPayments_

bool zeroPayments_
private

Definition at line 86 of file formulabasedcoupon.hpp.