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

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

#include <qle/cashflows/commodityindexedaveragecashflow.hpp>

+ Collaboration diagram for CommodityIndexedAverageLeg:

Public Member Functions

 CommodityIndexedAverageLeg (const QuantLib::Schedule &schedule, const ext::shared_ptr< CommodityIndex > &index)
 
CommodityIndexedAverageLegwithQuantities (QuantLib::Real quantity)
 
CommodityIndexedAverageLegwithQuantities (const std::vector< QuantLib::Real > &quantities)
 
CommodityIndexedAverageLegwithPaymentLag (QuantLib::Natural paymentLag)
 
CommodityIndexedAverageLegwithPaymentCalendar (const QuantLib::Calendar &paymentCalendar)
 
CommodityIndexedAverageLegwithPaymentConvention (QuantLib::BusinessDayConvention paymentConvention)
 
CommodityIndexedAverageLegwithPricingCalendar (const QuantLib::Calendar &pricingCalendar)
 
CommodityIndexedAverageLegwithSpreads (QuantLib::Real spread)
 
CommodityIndexedAverageLegwithSpreads (const std::vector< QuantLib::Real > &spreads)
 
CommodityIndexedAverageLegwithGearings (QuantLib::Real gearing)
 
CommodityIndexedAverageLegwithGearings (const std::vector< QuantLib::Real > &gearings)
 
CommodityIndexedAverageLegpaymentTiming (CommodityIndexedAverageCashFlow::PaymentTiming paymentTiming)
 
CommodityIndexedAverageLeguseFuturePrice (bool flag=false)
 
CommodityIndexedAverageLegwithDeliveryDateRoll (QuantLib::Natural deliveryDateRoll)
 
CommodityIndexedAverageLegwithFutureMonthOffset (QuantLib::Natural futureMonthOffset)
 
CommodityIndexedAverageLegwithFutureExpiryCalculator (const ext::shared_ptr< FutureExpiryCalculator > &calc=nullptr)
 
CommodityIndexedAverageLegpayAtMaturity (bool flag=false)
 
CommodityIndexedAverageLegincludeEndDate (bool flag=true)
 
CommodityIndexedAverageLegexcludeStartDate (bool flag=true)
 
CommodityIndexedAverageLegwithPaymentDates (const std::vector< QuantLib::Date > &paymentDates)
 
CommodityIndexedAverageLeguseBusinessDays (bool flag=true)
 
CommodityIndexedAverageLegwithQuantityFrequency (CommodityQuantityFrequency quantityFrequency)
 
CommodityIndexedAverageLegwithHoursPerDay (QuantLib::Natural hoursPerDay)
 
CommodityIndexedAverageLegwithDailyExpiryOffset (QuantLib::Natural dailyExpiryOffset)
 
CommodityIndexedAverageLegunrealisedQuantity (bool flag=false)
 
CommodityIndexedAverageLegwithOffPeakPowerData (const boost::optional< std::pair< QuantLib::Calendar, QuantLib::Real > > &offPeakPowerData)
 
CommodityIndexedAverageLegwithFxIndex (const ext::shared_ptr< FxIndex > &fxIndex)
 
 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::Calendar pricingCalendar_
 
std::vector< QuantLib::Real > spreads_
 
std::vector< QuantLib::Real > gearings_
 
CommodityIndexedAverageCashFlow::PaymentTiming paymentTiming_
 
bool useFuturePrice_
 
QuantLib::Natural deliveryDateRoll_
 
QuantLib::Natural futureMonthOffset_
 
ext::shared_ptr< FutureExpiryCalculatorcalc_
 
bool payAtMaturity_
 
bool includeEndDate_
 
bool excludeStartDate_
 
std::vector< QuantLib::Date > paymentDates_
 
bool useBusinessDays_
 
CommodityQuantityFrequency quantityFrequency_
 
QuantLib::Natural hoursPerDay_
 
QuantLib::Natural dailyExpiryOffset_
 
bool unrealisedQuantity_
 
boost::optional< std::pair< QuantLib::Calendar, QuantLib::Real > > offPeakPowerData_
 
ext::shared_ptr< FxIndexfxIndex_
 

Detailed Description

Helper class building a sequence of commodity indexed average cashflows.

Definition at line 174 of file commodityindexedaveragecashflow.hpp.

Constructor & Destructor Documentation

◆ CommodityIndexedAverageLeg()

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

Definition at line 279 of file commodityindexedaveragecashflow.cpp.

281 : schedule_(schedule), index_(index), paymentLag_(0), paymentCalendar_(NullCalendar()),
282 paymentConvention_(Unadjusted), pricingCalendar_(Calendar()),
287 dailyExpiryOffset_(Null<Natural>()), unrealisedQuantity_(false) {}
CommodityIndexedAverageCashFlow::PaymentTiming paymentTiming_

Member Function Documentation

◆ withQuantities() [1/2]

CommodityIndexedAverageLeg & withQuantities ( QuantLib::Real  quantity)
+ Here is the caller graph for this function:

◆ withQuantities() [2/2]

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

◆ withPaymentLag()

CommodityIndexedAverageLeg & withPaymentLag ( QuantLib::Natural  paymentLag)

Definition at line 299 of file commodityindexedaveragecashflow.cpp.

299 {
300 paymentLag_ = paymentLag;
301 return *this;
302}

◆ withPaymentCalendar()

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

Definition at line 304 of file commodityindexedaveragecashflow.cpp.

304 {
305 paymentCalendar_ = paymentCalendar;
306 return *this;
307}

◆ withPaymentConvention()

CommodityIndexedAverageLeg & withPaymentConvention ( QuantLib::BusinessDayConvention  paymentConvention)

Definition at line 309 of file commodityindexedaveragecashflow.cpp.

309 {
310 paymentConvention_ = paymentConvention;
311 return *this;
312}

◆ withPricingCalendar()

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

Definition at line 314 of file commodityindexedaveragecashflow.cpp.

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

◆ withSpreads() [1/2]

CommodityIndexedAverageLeg & withSpreads ( QuantLib::Real  spread)

◆ withSpreads() [2/2]

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

◆ withGearings() [1/2]

CommodityIndexedAverageLeg & withGearings ( QuantLib::Real  gearing)

◆ withGearings() [2/2]

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

◆ paymentTiming()

Definition at line 340 of file commodityindexedaveragecashflow.cpp.

340 {
342 return *this;
343}
CommodityIndexedAverageLeg & paymentTiming(CommodityIndexedAverageCashFlow::PaymentTiming paymentTiming)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ useFuturePrice()

CommodityIndexedAverageLeg & useFuturePrice ( bool  flag = false)

Definition at line 345 of file commodityindexedaveragecashflow.cpp.

345 {
346 useFuturePrice_ = flag;
347 return *this;
348}
+ Here is the caller graph for this function:

◆ withDeliveryDateRoll()

CommodityIndexedAverageLeg & withDeliveryDateRoll ( QuantLib::Natural  deliveryDateRoll)

Definition at line 350 of file commodityindexedaveragecashflow.cpp.

350 {
351 deliveryDateRoll_ = deliveryDateRoll;
352 return *this;
353}

◆ withFutureMonthOffset()

CommodityIndexedAverageLeg & withFutureMonthOffset ( QuantLib::Natural  futureMonthOffset)

Definition at line 355 of file commodityindexedaveragecashflow.cpp.

355 {
356 futureMonthOffset_ = futureMonthOffset;
357 return *this;
358}

◆ withFutureExpiryCalculator()

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

Definition at line 361 of file commodityindexedaveragecashflow.cpp.

361 {
362 calc_ = calc;
363 return *this;
364}
ext::shared_ptr< FutureExpiryCalculator > calc_
+ Here is the caller graph for this function:

◆ payAtMaturity()

CommodityIndexedAverageLeg & payAtMaturity ( bool  flag = false)

Definition at line 366 of file commodityindexedaveragecashflow.cpp.

366 {
367 payAtMaturity_ = flag;
368 return *this;
369}

◆ includeEndDate()

CommodityIndexedAverageLeg & includeEndDate ( bool  flag = true)

Definition at line 371 of file commodityindexedaveragecashflow.cpp.

371 {
372 includeEndDate_ = flag;
373 return *this;
374}

◆ excludeStartDate()

CommodityIndexedAverageLeg & excludeStartDate ( bool  flag = true)

Definition at line 376 of file commodityindexedaveragecashflow.cpp.

376 {
377 excludeStartDate_ = flag;
378 return *this;
379}

◆ withPaymentDates()

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

Definition at line 381 of file commodityindexedaveragecashflow.cpp.

381 {
382 paymentDates_ = paymentDates;
383 return *this;
384}

◆ useBusinessDays()

CommodityIndexedAverageLeg & useBusinessDays ( bool  flag = true)

Definition at line 386 of file commodityindexedaveragecashflow.cpp.

386 {
387 useBusinessDays_ = flag;
388 return *this;
389}

◆ withQuantityFrequency()

CommodityIndexedAverageLeg & withQuantityFrequency ( CommodityQuantityFrequency  quantityFrequency)

Definition at line 391 of file commodityindexedaveragecashflow.cpp.

392 {
393 quantityFrequency_ = quantityFrequency;
394 return *this;
395}

◆ withHoursPerDay()

CommodityIndexedAverageLeg & withHoursPerDay ( QuantLib::Natural  hoursPerDay)

Definition at line 397 of file commodityindexedaveragecashflow.cpp.

397 {
398 hoursPerDay_ = hoursPerDay;
399 return *this;
400}

◆ withDailyExpiryOffset()

CommodityIndexedAverageLeg & withDailyExpiryOffset ( QuantLib::Natural  dailyExpiryOffset)

Definition at line 402 of file commodityindexedaveragecashflow.cpp.

402 {
403 dailyExpiryOffset_ = dailyExpiryOffset;
404 return *this;
405}

◆ unrealisedQuantity()

CommodityIndexedAverageLeg & unrealisedQuantity ( bool  flag = false)

Definition at line 407 of file commodityindexedaveragecashflow.cpp.

407 {
408 unrealisedQuantity_ = flag;
409 return *this;
410}

◆ withOffPeakPowerData()

CommodityIndexedAverageLeg & withOffPeakPowerData ( const boost::optional< std::pair< QuantLib::Calendar, QuantLib::Real > > &  offPeakPowerData)

Definition at line 417 of file commodityindexedaveragecashflow.cpp.

417 {
418 offPeakPowerData_ = offPeakPowerData;
419 return *this;
420}
boost::optional< std::pair< QuantLib::Calendar, QuantLib::Real > > offPeakPowerData_

◆ withFxIndex()

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

Definition at line 412 of file commodityindexedaveragecashflow.cpp.

412 {
413 fxIndex_ = fxIndex;
414 return *this;
415}

◆ operator Leg()

operator Leg ( ) const

Definition at line 422 of file commodityindexedaveragecashflow.cpp.

422 {
423
424 // Number of commodity indexed average cashflows
425 Size numberCashflows = schedule_.size() - 1;
426
427 // Initial consistency checks
428 QL_REQUIRE(!quantities_.empty(), "No quantities given");
429 QL_REQUIRE(quantities_.size() <= numberCashflows,
430 "Too many quantities (" << quantities_.size() << "), only " << numberCashflows << " required");
431 if (useFuturePrice_) {
432 QL_REQUIRE(calc_, "CommodityIndexedCashFlow needs a valid future expiry calculator when using first future");
433 }
434
435 if (!paymentDates_.empty()) {
436 QL_REQUIRE(paymentDates_.size() == numberCashflows, "Expected the number of explicit payment dates ("
437 << paymentDates_.size()
438 << ") to equal the number of calculation periods ("
439 << numberCashflows << ")");
440 }
441
442 // If pay at maturity, populate payment date.
443 Date paymentDate;
444 if (payAtMaturity_) {
445 paymentDate = paymentCalendar_.advance(schedule_.dates().back(), paymentLag_ * Days, paymentConvention_);
446 }
447
448 // Leg to hold the result
449 // We always include the schedule start and schedule termination date in the averaging so the first and last
450 // coupon have special treatment here that overrides the includeEndDate_ and excludeStartDate_ flags
451 Leg leg;
452 leg.reserve(numberCashflows);
453 for (Size i = 0; i < numberCashflows; ++i) {
454
455 Date start = schedule_.date(i);
456 Date end = schedule_.date(i + 1);
457 bool excludeStart = i == 0 ? false : excludeStartDate_;
458 bool includeEnd = i == numberCashflows - 1 ? true : includeEndDate_;
459 Real quantity = detail::get(quantities_, i, 1.0);
460 Real spread = detail::get(spreads_, i, 0.0);
461 Real gearing = detail::get(gearings_, i, 1.0);
462
463 // If explicit payment dates provided, use them.
464 if (!paymentDates_.empty()) {
465 paymentDate = paymentDates_[i];
466 }
467
468 leg.push_back(ext::make_shared<CommodityIndexedAverageCashFlow>(
473 }
474
475 return leg;
476}

Member Data Documentation

◆ schedule_

Schedule schedule_
private

Definition at line 210 of file commodityindexedaveragecashflow.hpp.

◆ index_

ext::shared_ptr<CommodityIndex> index_
private

Definition at line 211 of file commodityindexedaveragecashflow.hpp.

◆ quantities_

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

Definition at line 212 of file commodityindexedaveragecashflow.hpp.

◆ paymentLag_

QuantLib::Natural paymentLag_
private

Definition at line 213 of file commodityindexedaveragecashflow.hpp.

◆ paymentCalendar_

QuantLib::Calendar paymentCalendar_
private

Definition at line 214 of file commodityindexedaveragecashflow.hpp.

◆ paymentConvention_

QuantLib::BusinessDayConvention paymentConvention_
private

Definition at line 215 of file commodityindexedaveragecashflow.hpp.

◆ pricingCalendar_

QuantLib::Calendar pricingCalendar_
private

Definition at line 216 of file commodityindexedaveragecashflow.hpp.

◆ spreads_

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

Definition at line 217 of file commodityindexedaveragecashflow.hpp.

◆ gearings_

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

Definition at line 218 of file commodityindexedaveragecashflow.hpp.

◆ paymentTiming_

Definition at line 219 of file commodityindexedaveragecashflow.hpp.

◆ useFuturePrice_

bool useFuturePrice_
private

Definition at line 220 of file commodityindexedaveragecashflow.hpp.

◆ deliveryDateRoll_

QuantLib::Natural deliveryDateRoll_
private

Definition at line 221 of file commodityindexedaveragecashflow.hpp.

◆ futureMonthOffset_

QuantLib::Natural futureMonthOffset_
private

Definition at line 222 of file commodityindexedaveragecashflow.hpp.

◆ calc_

ext::shared_ptr<FutureExpiryCalculator> calc_
private

Definition at line 223 of file commodityindexedaveragecashflow.hpp.

◆ payAtMaturity_

bool payAtMaturity_
private

Definition at line 224 of file commodityindexedaveragecashflow.hpp.

◆ includeEndDate_

bool includeEndDate_
private

Definition at line 225 of file commodityindexedaveragecashflow.hpp.

◆ excludeStartDate_

bool excludeStartDate_
private

Definition at line 226 of file commodityindexedaveragecashflow.hpp.

◆ paymentDates_

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

Definition at line 227 of file commodityindexedaveragecashflow.hpp.

◆ useBusinessDays_

bool useBusinessDays_
private

Definition at line 228 of file commodityindexedaveragecashflow.hpp.

◆ quantityFrequency_

CommodityQuantityFrequency quantityFrequency_
private

Definition at line 229 of file commodityindexedaveragecashflow.hpp.

◆ hoursPerDay_

QuantLib::Natural hoursPerDay_
private

Definition at line 230 of file commodityindexedaveragecashflow.hpp.

◆ dailyExpiryOffset_

QuantLib::Natural dailyExpiryOffset_
private

Definition at line 231 of file commodityindexedaveragecashflow.hpp.

◆ unrealisedQuantity_

bool unrealisedQuantity_
private

Definition at line 232 of file commodityindexedaveragecashflow.hpp.

◆ offPeakPowerData_

boost::optional<std::pair<QuantLib::Calendar, QuantLib::Real> > offPeakPowerData_
private

Definition at line 233 of file commodityindexedaveragecashflow.hpp.

◆ fxIndex_

ext::shared_ptr<FxIndex> fxIndex_
private

Definition at line 234 of file commodityindexedaveragecashflow.hpp.