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

Helper class building a sequence of commodity indexed cashflows. More...

#include <qle/cashflows/commodityindexedcashflow.hpp>

+ Collaboration diagram for CommodityIndexedLeg:

Public Member Functions

 CommodityIndexedLeg (const QuantLib::Schedule &schedule, const ext::shared_ptr< CommodityIndex > &index)
 
CommodityIndexedLegwithQuantities (QuantLib::Real quantity)
 
CommodityIndexedLegwithQuantities (const std::vector< QuantLib::Real > &quantities)
 
CommodityIndexedLegwithPaymentLag (QuantLib::Natural paymentLag)
 
CommodityIndexedLegwithPaymentCalendar (const QuantLib::Calendar &paymentCalendar)
 
CommodityIndexedLegwithPaymentConvention (QuantLib::BusinessDayConvention paymentConvention)
 
CommodityIndexedLegwithPricingLag (QuantLib::Natural pricingLag)
 
CommodityIndexedLegwithPricingLagCalendar (const QuantLib::Calendar &pricingLagCalendar)
 
CommodityIndexedLegwithSpreads (QuantLib::Real spread)
 
CommodityIndexedLegwithSpreads (const std::vector< QuantLib::Real > &spreads)
 
CommodityIndexedLegwithGearings (QuantLib::Real gearing)
 
CommodityIndexedLegwithGearings (const std::vector< QuantLib::Real > &gearings)
 
CommodityIndexedLegpaymentTiming (CommodityIndexedCashFlow::PaymentTiming paymentTiming)
 
CommodityIndexedLeginArrears (bool flag=true)
 
CommodityIndexedLeguseFuturePrice (bool flag=false)
 
CommodityIndexedLeguseFutureExpiryDate (bool flag=true)
 
CommodityIndexedLegwithFutureMonthOffset (QuantLib::Natural futureMonthOffset)
 
CommodityIndexedLegwithFutureExpiryCalculator (const ext::shared_ptr< FutureExpiryCalculator > &calc=nullptr)
 
CommodityIndexedLegpayAtMaturity (bool flag=false)
 
CommodityIndexedLegwithPricingDates (const std::vector< QuantLib::Date > &pricingDates)
 
CommodityIndexedLegwithPaymentDates (const std::vector< QuantLib::Date > &paymentDates)
 
CommodityIndexedLegwithDailyExpiryOffset (QuantLib::Natural dailyExpiryOffset)
 
CommodityIndexedLegwithFxIndex (const ext::shared_ptr< FxIndex > &fxIndex)
 
CommodityIndexedLegwithIsAveraging (const bool isAveraging)
 
CommodityIndexedLegwithPricingCalendar (const QuantLib::Calendar &pricingCalendar)
 
CommodityIndexedLegincludeEndDate (bool flag=true)
 
CommodityIndexedLegexcludeStartDate (bool flag=true)
 
 operator Leg () const
 

Private Attributes

Schedule schedule_
 
ext::shared_ptr< CommodityIndexindex_
 
std::vector< QuantLib::Real > quantities_
 
QuantLib::Natural paymentLag_
 
QuantLib::Calendar paymentCalendar_
 
QuantLib::BusinessDayConvention paymentConvention_
 
QuantLib::Natural pricingLag_
 
QuantLib::Calendar pricingLagCalendar_
 
std::vector< QuantLib::Real > spreads_
 
std::vector< QuantLib::Real > gearings_
 
CommodityIndexedCashFlow::PaymentTiming paymentTiming_
 
bool inArrears_
 
bool useFuturePrice_
 
bool useFutureExpiryDate_
 
QuantLib::Natural futureMonthOffset_
 
ext::shared_ptr< FutureExpiryCalculatorcalc_
 
bool payAtMaturity_
 
std::vector< QuantLib::Date > pricingDates_
 
std::vector< QuantLib::Date > paymentDates_
 
QuantLib::Natural dailyExpiryOffset_
 
ext::shared_ptr< FxIndexfxIndex_
 
bool isAveraging_
 
QuantLib::Calendar pricingCalendar_
 
bool includeEndDate_
 
bool excludeStartDate_
 

Detailed Description

Helper class building a sequence of commodity indexed cashflows.

Definition at line 146 of file commodityindexedcashflow.hpp.

Constructor & Destructor Documentation

◆ CommodityIndexedLeg()

CommodityIndexedLeg ( const QuantLib::Schedule &  schedule,
const ext::shared_ptr< CommodityIndex > &  index 
)

Definition at line 191 of file commodityindexedcashflow.cpp.

192 : schedule_(schedule), index_(index), paymentLag_(0), paymentCalendar_(NullCalendar()),
193 paymentConvention_(Unadjusted), pricingLag_(0), pricingLagCalendar_(NullCalendar()),
196 isAveraging_(false), pricingCalendar_(NullCalendar()), includeEndDate_(true), excludeStartDate_(true) {}
QuantLib::BusinessDayConvention paymentConvention_
CommodityIndexedCashFlow::PaymentTiming paymentTiming_
ext::shared_ptr< CommodityIndex > index_

Member Function Documentation

◆ withQuantities() [1/2]

CommodityIndexedLeg & withQuantities ( QuantLib::Real  quantity)

◆ withQuantities() [2/2]

CommodityIndexedLeg & withQuantities ( const std::vector< QuantLib::Real > &  quantities)

◆ withPaymentLag()

CommodityIndexedLeg & withPaymentLag ( QuantLib::Natural  paymentLag)

Definition at line 208 of file commodityindexedcashflow.cpp.

208 {
209 paymentLag_ = paymentLag;
210 return *this;
211}

◆ withPaymentCalendar()

CommodityIndexedLeg & withPaymentCalendar ( const QuantLib::Calendar &  paymentCalendar)

Definition at line 213 of file commodityindexedcashflow.cpp.

213 {
214 paymentCalendar_ = paymentCalendar;
215 return *this;
216}

◆ withPaymentConvention()

CommodityIndexedLeg & withPaymentConvention ( QuantLib::BusinessDayConvention  paymentConvention)

Definition at line 218 of file commodityindexedcashflow.cpp.

218 {
219 paymentConvention_ = paymentConvention;
220 return *this;
221}

◆ withPricingLag()

CommodityIndexedLeg & withPricingLag ( QuantLib::Natural  pricingLag)

Definition at line 223 of file commodityindexedcashflow.cpp.

223 {
224 pricingLag_ = pricingLag;
225 return *this;
226}

◆ withPricingLagCalendar()

CommodityIndexedLeg & withPricingLagCalendar ( const QuantLib::Calendar &  pricingLagCalendar)

Definition at line 228 of file commodityindexedcashflow.cpp.

228 {
229 pricingLagCalendar_ = pricingLagCalendar;
230 return *this;
231}

◆ withSpreads() [1/2]

CommodityIndexedLeg & withSpreads ( QuantLib::Real  spread)

◆ withSpreads() [2/2]

CommodityIndexedLeg & withSpreads ( const std::vector< QuantLib::Real > &  spreads)

◆ withGearings() [1/2]

CommodityIndexedLeg & withGearings ( QuantLib::Real  gearing)

◆ withGearings() [2/2]

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

◆ paymentTiming()

Definition at line 253 of file commodityindexedcashflow.cpp.

253 {
255 return *this;
256}
CommodityIndexedLeg & paymentTiming(CommodityIndexedCashFlow::PaymentTiming paymentTiming)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inArrears()

CommodityIndexedLeg & inArrears ( bool  flag = true)

Definition at line 258 of file commodityindexedcashflow.cpp.

258 {
259 inArrears_ = flag;
260 return *this;
261}

◆ useFuturePrice()

CommodityIndexedLeg & useFuturePrice ( bool  flag = false)

Definition at line 263 of file commodityindexedcashflow.cpp.

263 {
264 useFuturePrice_ = flag;
265 return *this;
266}

◆ useFutureExpiryDate()

CommodityIndexedLeg & useFutureExpiryDate ( bool  flag = true)

Definition at line 268 of file commodityindexedcashflow.cpp.

268 {
270 return *this;
271}

◆ withFutureMonthOffset()

CommodityIndexedLeg & withFutureMonthOffset ( QuantLib::Natural  futureMonthOffset)

Definition at line 273 of file commodityindexedcashflow.cpp.

273 {
274 futureMonthOffset_ = futureMonthOffset;
275 return *this;
276}

◆ withFutureExpiryCalculator()

CommodityIndexedLeg & withFutureExpiryCalculator ( const ext::shared_ptr< FutureExpiryCalculator > &  calc = nullptr)

Definition at line 279 of file commodityindexedcashflow.cpp.

279 {
280 calc_ = calc;
281 return *this;
282}
ext::shared_ptr< FutureExpiryCalculator > calc_

◆ payAtMaturity()

CommodityIndexedLeg & payAtMaturity ( bool  flag = false)

Definition at line 284 of file commodityindexedcashflow.cpp.

284 {
285 payAtMaturity_ = flag;
286 return *this;
287}

◆ withPricingDates()

CommodityIndexedLeg & withPricingDates ( const std::vector< QuantLib::Date > &  pricingDates)

Definition at line 289 of file commodityindexedcashflow.cpp.

289 {
291 return *this;
292}
std::vector< QuantLib::Date > pricingDates_
set< Date > pricingDates(const Date &s, const Date &e, const Calendar &pricingCalendar, bool excludeStart, bool includeEnd, bool useBusinessDays)
+ Here is the call graph for this function:

◆ withPaymentDates()

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

Definition at line 294 of file commodityindexedcashflow.cpp.

294 {
295 paymentDates_ = paymentDates;
296 return *this;
297}
std::vector< QuantLib::Date > paymentDates_

◆ withDailyExpiryOffset()

CommodityIndexedLeg & withDailyExpiryOffset ( QuantLib::Natural  dailyExpiryOffset)

Definition at line 299 of file commodityindexedcashflow.cpp.

299 {
300 dailyExpiryOffset_ = dailyExpiryOffset;
301 return *this;
302}

◆ withFxIndex()

CommodityIndexedLeg & withFxIndex ( const ext::shared_ptr< FxIndex > &  fxIndex)

Definition at line 304 of file commodityindexedcashflow.cpp.

304 {
305 fxIndex_ = fxIndex;
306 return *this;
307}

◆ withIsAveraging()

CommodityIndexedLeg & withIsAveraging ( const bool  isAveraging)

Definition at line 309 of file commodityindexedcashflow.cpp.

309 {
310 isAveraging_ = isAveraging;
311 return *this;
312}

◆ withPricingCalendar()

CommodityIndexedLeg & withPricingCalendar ( const QuantLib::Calendar &  pricingCalendar)

Definition at line 314 of file commodityindexedcashflow.cpp.

314 {
315 pricingCalendar_ = pricingCalendar;
316 return *this;
317}

◆ includeEndDate()

CommodityIndexedLeg & includeEndDate ( bool  flag = true)

Definition at line 319 of file commodityindexedcashflow.cpp.

319 {
321 return *this;
322}
CommodityIndexedLeg & includeEndDate(bool flag=true)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ excludeStartDate()

CommodityIndexedLeg & excludeStartDate ( bool  flag = true)

Definition at line 324 of file commodityindexedcashflow.cpp.

324 {
326 return *this;
327}
CommodityIndexedLeg & excludeStartDate(bool flag=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 329 of file commodityindexedcashflow.cpp.

329 {
330
331 // Number of commodity indexed cashflows
332 Size numberCashflows = schedule_.size() - 1;
333
334 // Initial consistency checks
335 QL_REQUIRE(!quantities_.empty(), "No quantities given");
336 QL_REQUIRE(quantities_.size() <= numberCashflows,
337 "Too many quantities (" << quantities_.size() << "), only " << numberCashflows << " required");
338 if (useFuturePrice_) {
339 QL_REQUIRE(calc_, "CommodityIndexedCashFlow needs a valid future expiry calculator when using first future");
340 }
341 if (!pricingDates_.empty()) {
342 QL_REQUIRE(pricingDates_.size() == numberCashflows, "Expected the number of explicit pricing dates ("
343 << pricingDates_.size()
344 << ") to equal the number of calculation periods ("
345 << numberCashflows << ")");
346 }
347 if (!paymentDates_.empty()) {
348 QL_REQUIRE(paymentDates_.size() == numberCashflows, "Expected the number of explicit payment dates ("
349 << paymentDates_.size()
350 << ") to equal the number of calculation periods ("
351 << numberCashflows << ")");
352 }
353
354 // If pay at maturity, populate payment date.
355 Date paymentDate;
356 if (payAtMaturity_) {
357 paymentDate = paymentCalendar_.advance(schedule_.dates().back(), paymentLag_ * Days, paymentConvention_);
358 }
359
360 // Leg to hold the result
361 Leg leg;
362 leg.reserve(numberCashflows);
363 for (Size i = 0; i < numberCashflows; ++i) {
364
365 Date start = schedule_.date(i);
366 Date end = schedule_.date(i + 1);
367 Real quantity = detail::get(quantities_, i, 1.0);
368 Real spread = detail::get(spreads_, i, 0.0);
369 Real gearing = detail::get(gearings_, i, 1.0);
370 Date pricingDate = detail::get(pricingDates_, i, Date());
371 bool excludeStart = i == 0 ? false : excludeStartDate_;
372 bool includeEnd = i == numberCashflows - 1 ? true : includeEndDate_;
373
374 // If explicit payment dates provided, use them.
375 if (!paymentDates_.empty()) {
376 paymentDate = paymentDates_[i];
377 }
378
379 leg.push_back(ext::make_shared<CommodityIndexedCashFlow>(
383 pricingCalendar_, includeEnd, excludeStart));
384 }
385
386 return leg;
387}
std::vector< QuantLib::Real > quantities_
std::vector< QuantLib::Real > spreads_
std::vector< QuantLib::Real > gearings_

Member Data Documentation

◆ schedule_

Schedule schedule_
private

Definition at line 180 of file commodityindexedcashflow.hpp.

◆ index_

ext::shared_ptr<CommodityIndex> index_
private

Definition at line 181 of file commodityindexedcashflow.hpp.

◆ quantities_

std::vector<QuantLib::Real> quantities_
private

Definition at line 182 of file commodityindexedcashflow.hpp.

◆ paymentLag_

QuantLib::Natural paymentLag_
private

Definition at line 183 of file commodityindexedcashflow.hpp.

◆ paymentCalendar_

QuantLib::Calendar paymentCalendar_
private

Definition at line 184 of file commodityindexedcashflow.hpp.

◆ paymentConvention_

QuantLib::BusinessDayConvention paymentConvention_
private

Definition at line 185 of file commodityindexedcashflow.hpp.

◆ pricingLag_

QuantLib::Natural pricingLag_
private

Definition at line 186 of file commodityindexedcashflow.hpp.

◆ pricingLagCalendar_

QuantLib::Calendar pricingLagCalendar_
private

Definition at line 187 of file commodityindexedcashflow.hpp.

◆ spreads_

std::vector<QuantLib::Real> spreads_
private

Definition at line 188 of file commodityindexedcashflow.hpp.

◆ gearings_

std::vector<QuantLib::Real> gearings_
private

Definition at line 189 of file commodityindexedcashflow.hpp.

◆ paymentTiming_

Definition at line 190 of file commodityindexedcashflow.hpp.

◆ inArrears_

bool inArrears_
private

Definition at line 191 of file commodityindexedcashflow.hpp.

◆ useFuturePrice_

bool useFuturePrice_
private

Definition at line 192 of file commodityindexedcashflow.hpp.

◆ useFutureExpiryDate_

bool useFutureExpiryDate_
private

Definition at line 193 of file commodityindexedcashflow.hpp.

◆ futureMonthOffset_

QuantLib::Natural futureMonthOffset_
private

Definition at line 194 of file commodityindexedcashflow.hpp.

◆ calc_

ext::shared_ptr<FutureExpiryCalculator> calc_
private

Definition at line 195 of file commodityindexedcashflow.hpp.

◆ payAtMaturity_

bool payAtMaturity_
private

Definition at line 196 of file commodityindexedcashflow.hpp.

◆ pricingDates_

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

Definition at line 197 of file commodityindexedcashflow.hpp.

◆ paymentDates_

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

Definition at line 198 of file commodityindexedcashflow.hpp.

◆ dailyExpiryOffset_

QuantLib::Natural dailyExpiryOffset_
private

Definition at line 199 of file commodityindexedcashflow.hpp.

◆ fxIndex_

ext::shared_ptr<FxIndex> fxIndex_
private

Definition at line 200 of file commodityindexedcashflow.hpp.

◆ isAveraging_

bool isAveraging_
private

Definition at line 201 of file commodityindexedcashflow.hpp.

◆ pricingCalendar_

QuantLib::Calendar pricingCalendar_
private

Definition at line 202 of file commodityindexedcashflow.hpp.

◆ includeEndDate_

bool includeEndDate_
private

Definition at line 203 of file commodityindexedcashflow.hpp.

◆ excludeStartDate_

bool excludeStartDate_
private

Definition at line 204 of file commodityindexedcashflow.hpp.