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

helper class building a sequence of sub-period coupons More...

#include <qle/cashflows/subperiodscoupon.hpp>

+ Collaboration diagram for SubPeriodsLeg1:

Public Member Functions

 SubPeriodsLeg1 (const Schedule &schedule, const QuantLib::ext::shared_ptr< InterestRateIndex > &index)
 
SubPeriodsLeg1withNotional (Real notional)
 
SubPeriodsLeg1withNotionals (const std::vector< Real > &notionals)
 
SubPeriodsLeg1withPaymentDayCounter (const DayCounter &dayCounter)
 
SubPeriodsLeg1withPaymentAdjustment (BusinessDayConvention convention)
 
SubPeriodsLeg1withGearing (Real gearing)
 
SubPeriodsLeg1withGearings (const std::vector< Real > &gearings)
 
SubPeriodsLeg1withSpread (Spread spread)
 
SubPeriodsLeg1withSpreads (const std::vector< Spread > &spreads)
 
SubPeriodsLeg1withPaymentCalendar (const Calendar &calendar)
 
SubPeriodsLeg1withType (SubPeriodsCoupon1::Type type)
 
SubPeriodsLeg1includeSpread (bool includeSpread)
 
 operator Leg () const
 

Private Attributes

Schedule schedule_
 
QuantLib::ext::shared_ptr< InterestRateIndexindex_
 
std::vector< Real > notionals_
 
DayCounter paymentDayCounter_
 
BusinessDayConvention paymentAdjustment_
 
std::vector< Real > gearings_
 
std::vector< Spread > spreads_
 
Calendar paymentCalendar_
 
SubPeriodsCoupon1::Type type_
 
bool includeSpread_
 

Detailed Description

helper class building a sequence of sub-period coupons

Definition at line 93 of file subperiodscoupon.hpp.

Constructor & Destructor Documentation

◆ SubPeriodsLeg1()

SubPeriodsLeg1 ( const Schedule &  schedule,
const QuantLib::ext::shared_ptr< InterestRateIndex > &  index 
)

Definition at line 88 of file subperiodscoupon.cpp.

89 : schedule_(schedule), index_(index), notionals_(std::vector<Real>(1, 1.0)), paymentAdjustment_(Following),
BusinessDayConvention paymentAdjustment_
QuantLib::ext::shared_ptr< InterestRateIndex > index_
std::vector< Real > notionals_
SubPeriodsCoupon1::Type type_

Member Function Documentation

◆ withNotional()

SubPeriodsLeg1 & withNotional ( Real  notional)

Definition at line 92 of file subperiodscoupon.cpp.

92 {
93 notionals_ = std::vector<Real>(1, notional);
94 return *this;
95}
+ Here is the caller graph for this function:

◆ withNotionals()

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

Definition at line 97 of file subperiodscoupon.cpp.

97 {
98 notionals_ = notionals;
99 return *this;
100}
+ Here is the caller graph for this function:

◆ withPaymentDayCounter()

SubPeriodsLeg1 & withPaymentDayCounter ( const DayCounter &  dayCounter)

Definition at line 102 of file subperiodscoupon.cpp.

102 {
103 paymentDayCounter_ = dayCounter;
104 return *this;
105}
+ Here is the caller graph for this function:

◆ withPaymentAdjustment()

SubPeriodsLeg1 & withPaymentAdjustment ( BusinessDayConvention  convention)

Definition at line 107 of file subperiodscoupon.cpp.

107 {
108 paymentAdjustment_ = convention;
109 return *this;
110}
+ Here is the caller graph for this function:

◆ withGearing()

SubPeriodsLeg1 & withGearing ( Real  gearing)

Definition at line 112 of file subperiodscoupon.cpp.

112 {
113 gearings_ = std::vector<Real>(1, gearing);
114 return *this;
115}
std::vector< Real > gearings_

◆ withGearings()

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

Definition at line 117 of file subperiodscoupon.cpp.

117 {
118 gearings_ = gearings;
119 return *this;
120}

◆ withSpread()

SubPeriodsLeg1 & withSpread ( Spread  spread)

Definition at line 122 of file subperiodscoupon.cpp.

122 {
123 spreads_ = std::vector<Spread>(1, spread);
124 return *this;
125}
std::vector< Spread > spreads_
+ Here is the caller graph for this function:

◆ withSpreads()

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

Definition at line 127 of file subperiodscoupon.cpp.

127 {
128 spreads_ = spreads;
129 return *this;
130}

◆ withPaymentCalendar()

SubPeriodsLeg1 & withPaymentCalendar ( const Calendar &  calendar)

Definition at line 132 of file subperiodscoupon.cpp.

132 {
133 paymentCalendar_ = calendar;
134 return *this;
135}
+ Here is the caller graph for this function:

◆ withType()

Definition at line 137 of file subperiodscoupon.cpp.

137 {
138 type_ = type;
139 return *this;
140}
+ Here is the caller graph for this function:

◆ includeSpread()

SubPeriodsLeg1 & includeSpread ( bool  includeSpread)

Definition at line 142 of file subperiodscoupon.cpp.

142 {
144 return *this;
145}
SubPeriodsLeg1 & includeSpread(bool includeSpread)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator Leg()

operator Leg ( ) const

Definition at line 147 of file subperiodscoupon.cpp.

147 {
148
149 Leg cashflows;
150 Date startDate;
151 Date endDate;
152 Date paymentDate;
153
154 Calendar calendar;
155 if (!paymentCalendar_.empty()) {
156 calendar = paymentCalendar_;
157 } else {
158 calendar = schedule_.calendar();
159 }
160
161 Size numPeriods = schedule_.size() - 1;
162 if (numPeriods == 0)
163 return cashflows;
164
165 startDate = schedule_.date(0);
166 for (Size i = 0; i < numPeriods; ++i) {
167 endDate = schedule_.date(i + 1);
168 paymentDate = calendar.adjust(endDate, paymentAdjustment_);
169 // the sub periods coupon might produce degenerated schedules, in this
170 // case we just join the current period with the next one
171 // we catch all QL exceptions here, although we should only pick the one
172 // that is thrown in case of a degenerated schedule, but there is no way
173 // of identifying it except parsing the exception text, which isn't a
174 // clean solution either
175 try {
176 QuantLib::ext::shared_ptr<SubPeriodsCoupon1> cashflow(
177 new SubPeriodsCoupon1(paymentDate, detail::get(notionals_, i, notionals_.back()), startDate, endDate,
178 index_, type_, paymentAdjustment_, detail::get(spreads_, i, 0.0),
179 paymentDayCounter_, includeSpread_, detail::get(gearings_, i, 1.0)));
180
181 cashflows.push_back(cashflow);
182 startDate = endDate;
183 } catch (const QuantLib::Error&) {
184 }
185 }
186
187 QuantLib::ext::shared_ptr<SubPeriodsCouponPricer1> pricer(new SubPeriodsCouponPricer1);
188 QuantExt::setCouponPricer(cashflows, pricer);
189
190 return cashflows;
191}
void setCouponPricer(const Leg &leg, const QuantLib::ext::shared_ptr< FloatingRateCouponPricer > &pricer)
Set Coupon Pricer.
+ Here is the call graph for this function:

Member Data Documentation

◆ schedule_

Schedule schedule_
private

Definition at line 110 of file subperiodscoupon.hpp.

◆ index_

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

Definition at line 111 of file subperiodscoupon.hpp.

◆ notionals_

std::vector<Real> notionals_
private

Definition at line 112 of file subperiodscoupon.hpp.

◆ paymentDayCounter_

DayCounter paymentDayCounter_
private

Definition at line 113 of file subperiodscoupon.hpp.

◆ paymentAdjustment_

BusinessDayConvention paymentAdjustment_
private

Definition at line 114 of file subperiodscoupon.hpp.

◆ gearings_

std::vector<Real> gearings_
private

Definition at line 115 of file subperiodscoupon.hpp.

◆ spreads_

std::vector<Spread> spreads_
private

Definition at line 116 of file subperiodscoupon.hpp.

◆ paymentCalendar_

Calendar paymentCalendar_
private

Definition at line 117 of file subperiodscoupon.hpp.

◆ type_

SubPeriodsCoupon1::Type type_
private

Definition at line 118 of file subperiodscoupon.hpp.

◆ includeSpread_

bool includeSpread_
private

Definition at line 119 of file subperiodscoupon.hpp.