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

indexed coupon leg More...

#include <qle/cashflows/indexedcoupon.hpp>

+ Collaboration diagram for IndexedCouponLeg:

Public Member Functions

 IndexedCouponLeg (const Leg &underlyingLeg, const Real qty, const QuantLib::ext::shared_ptr< Index > &index)
 
IndexedCouponLegwithInitialFixing (const Real initialFixing)
 
IndexedCouponLegwithInitialNotionalFixing (const Real initialNotionalFixing)
 
IndexedCouponLegwithValuationSchedule (const Schedule &valuationSchedule)
 
IndexedCouponLegwithFixingDays (const Size fixingDays)
 
IndexedCouponLegwithFixingCalendar (const Calendar &fixingCalendar)
 
IndexedCouponLegwithFixingConvention (const BusinessDayConvention &fixingConvention)
 
IndexedCouponLeginArrearsFixing (const bool inArrearsFixing=true)
 
 operator Leg () const
 

Private Attributes

const Leg underlyingLeg_
 
const Real qty_
 
const QuantLib::ext::shared_ptr< Index > index_
 
Real initialFixing_
 
Real initialNotionalFixing_
 
Schedule valuationSchedule_
 
Size fixingDays_
 
Calendar fixingCalendar_
 
BusinessDayConvention fixingConvention_
 
bool inArrearsFixing_
 

Detailed Description

indexed coupon leg

Definition at line 150 of file indexedcoupon.hpp.

Constructor & Destructor Documentation

◆ IndexedCouponLeg()

IndexedCouponLeg ( const Leg &  underlyingLeg,
const Real  qty,
const QuantLib::ext::shared_ptr< Index > &  index 
)

Definition at line 120 of file indexedcoupon.cpp.

121 : underlyingLeg_(underlyingLeg), qty_(qty), index_(index), initialFixing_(Null<Real>()),
122 initialNotionalFixing_(Null<Real>()), fixingDays_(0), fixingCalendar_(NullCalendar()),
123 fixingConvention_(Preceding), inArrearsFixing_(true) {
124 QL_REQUIRE(index, "IndexedCouponLeg: index required");
125}
BusinessDayConvention fixingConvention_
const QuantLib::ext::shared_ptr< Index > index_

Member Function Documentation

◆ withInitialFixing()

IndexedCouponLeg & withInitialFixing ( const Real  initialFixing)

Definition at line 127 of file indexedcoupon.cpp.

127 {
128 initialFixing_ = initialFixing;
129 return *this;
130}

◆ withInitialNotionalFixing()

IndexedCouponLeg & withInitialNotionalFixing ( const Real  initialNotionalFixing)

Definition at line 132 of file indexedcoupon.cpp.

132 {
133 initialNotionalFixing_ = initialNotionalFixing;
134 return *this;
135}

◆ withValuationSchedule()

IndexedCouponLeg & withValuationSchedule ( const Schedule &  valuationSchedule)

Definition at line 137 of file indexedcoupon.cpp.

137 {
138 valuationSchedule_ = valuationSchedule;
139 return *this;
140}

◆ withFixingDays()

IndexedCouponLeg & withFixingDays ( const Size  fixingDays)

Definition at line 142 of file indexedcoupon.cpp.

142 {
143 fixingDays_ = fixingDays;
144 return *this;
145}

◆ withFixingCalendar()

IndexedCouponLeg & withFixingCalendar ( const Calendar &  fixingCalendar)

Definition at line 147 of file indexedcoupon.cpp.

147 {
148 fixingCalendar_ = fixingCalendar;
149 return *this;
150}

◆ withFixingConvention()

IndexedCouponLeg & withFixingConvention ( const BusinessDayConvention &  fixingConvention)

Definition at line 152 of file indexedcoupon.cpp.

152 {
153 fixingConvention_ = fixingConvention;
154 return *this;
155}

◆ inArrearsFixing()

IndexedCouponLeg & inArrearsFixing ( const bool  inArrearsFixing = true)

Definition at line 157 of file indexedcoupon.cpp.

157 {
159 return *this;
160}
IndexedCouponLeg & inArrearsFixing(const bool inArrearsFixing=true)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator Leg()

operator Leg ( ) const

Definition at line 162 of file indexedcoupon.cpp.

162 {
163 Leg resultLeg;
164 resultLeg.reserve(underlyingLeg_.size());
165
166 for (Size i = 0; i < underlyingLeg_.size(); ++i) {
167 bool firstValuationDate = (i == 0);
168 Date fixingDate;
169
170 if (auto cpn = QuantLib::ext::dynamic_pointer_cast<Coupon>(underlyingLeg_[i])) {
171 if (valuationSchedule_.empty()) {
172 fixingDate = inArrearsFixing_ ? cpn->accrualEndDate() : cpn->accrualStartDate();
173 } else {
174 if (valuationSchedule_.size() == underlyingLeg_.size() + 1) {
175 // valuation schedule corresponds one to one to underlying schedule
177 } else {
178 // look for the latest valuation date less or equal to the underlying accrual start date (if
179 // the indexing is using in advance fixing) resp. accrual end date (for in arrears fixing)
180 auto valDates = valuationSchedule_.dates();
181 Date refDate = inArrearsFixing_ ? cpn->accrualEndDate() : cpn->accrualStartDate();
182 Size index =
183 std::distance(valDates.begin(), std::upper_bound(valDates.begin(), valDates.end(), refDate));
184 QL_REQUIRE(index > 0, "IndexedCouponLeg: First valuation date ("
185 << valDates.front() << ") must be leq accrual "
186 << (inArrearsFixing_ ? "end" : "start") << " date ("
187 << cpn->accrualStartDate() << ") of the " << (i + 1)
188 << "th coupon in the underlying leg");
189 fixingDate = valuationSchedule_.date(index - 1);
190 firstValuationDate = (index == 1);
191 }
192 }
193
194 fixingDate = fixingCalendar_.advance(fixingDate, -static_cast<int>(fixingDays_), Days, fixingConvention_);
195 if (index_ != nullptr)
196 fixingDate = index_->fixingCalendar().adjust(fixingDate, Preceding);
197
198 if (firstValuationDate && initialFixing_ != Null<Real>()) {
199 resultLeg.push_back(QuantLib::ext::make_shared<IndexedCoupon>(cpn, qty_, initialFixing_));
200 } else {
201 resultLeg.push_back(QuantLib::ext::make_shared<IndexedCoupon>(cpn, qty_, index_, fixingDate));
202 }
203 } else if (auto csf = QuantLib::ext::dynamic_pointer_cast<CashFlow>(underlyingLeg_[i])) {
204 fixingDate = fixingCalendar_.advance(csf->date(), -static_cast<int>(fixingDays_), Days, fixingConvention_);
205 if (firstValuationDate && initialNotionalFixing_ != Null<Real>()) {
206 // use firstNotionalFixing if the first flow is a cashflow (not a coupon)
207 resultLeg.push_back(QuantLib::ext::make_shared<IndexWrappedCashFlow>(csf, qty_, initialNotionalFixing_));
208 } else if (!valuationSchedule_.empty() && valuationSchedule_.dates().size() > 0 &&
209 valuationSchedule_.date(0) == csf->date() && initialFixing_ != Null<Real>()) {
210 // use the initial fixing if the cashflow date equals the first date in the val schedule
211 resultLeg.push_back(QuantLib::ext::make_shared<IndexWrappedCashFlow>(csf, qty_, initialFixing_));
212 } else {
213 // use a flow with free fixing otherwise
214 resultLeg.push_back(QuantLib::ext::make_shared<IndexWrappedCashFlow>(csf, qty_, index_, fixingDate));
215 }
216 } else {
217 QL_FAIL("IndexedCouponLeg: coupon or cashflow required");
218 }
219 }
220
221 return resultLeg;
222}
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
Definition: inflation.cpp:183

Member Data Documentation

◆ underlyingLeg_

const Leg underlyingLeg_
private

Definition at line 164 of file indexedcoupon.hpp.

◆ qty_

const Real qty_
private

Definition at line 165 of file indexedcoupon.hpp.

◆ index_

const QuantLib::ext::shared_ptr<Index> index_
private

Definition at line 166 of file indexedcoupon.hpp.

◆ initialFixing_

Real initialFixing_
private

Definition at line 167 of file indexedcoupon.hpp.

◆ initialNotionalFixing_

Real initialNotionalFixing_
private

Definition at line 168 of file indexedcoupon.hpp.

◆ valuationSchedule_

Schedule valuationSchedule_
private

Definition at line 169 of file indexedcoupon.hpp.

◆ fixingDays_

Size fixingDays_
private

Definition at line 170 of file indexedcoupon.hpp.

◆ fixingCalendar_

Calendar fixingCalendar_
private

Definition at line 171 of file indexedcoupon.hpp.

◆ fixingConvention_

BusinessDayConvention fixingConvention_
private

Definition at line 172 of file indexedcoupon.hpp.

◆ inArrearsFixing_

bool inArrearsFixing_
private

Definition at line 173 of file indexedcoupon.hpp.