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

Cash flow dependent on a single commodity spot price or futures settlement price on a given pricing date. More...

#include <qle/cashflows/commodityindexedcashflow.hpp>

+ Inheritance diagram for CommodityIndexedCashFlow:
+ Collaboration diagram for CommodityIndexedCashFlow:

Public Types

enum class  PaymentTiming { InAdvance , InArrears , RelativeToExpiry }
 

Public Member Functions

 CommodityIndexedCashFlow (QuantLib::Real quantity, const QuantLib::Date &pricingDate, const QuantLib::Date &paymentDate, const ext::shared_ptr< CommodityIndex > &index, QuantLib::Real spread=0.0, QuantLib::Real gearing=1.0, bool useFuturePrice=false, const Date &contractDate=Date(), const ext::shared_ptr< FutureExpiryCalculator > &calc=nullptr, QuantLib::Natural dailyExpiryOffset=QuantLib::Null< QuantLib::Natural >(), const ext::shared_ptr< FxIndex > &fxIndex=nullptr)
 Constructor taking an explicit pricingDate and paymentDate. More...
 
 CommodityIndexedCashFlow (QuantLib::Real quantity, const QuantLib::Date &startDate, const QuantLib::Date &endDate, const ext::shared_ptr< CommodityIndex > &index, QuantLib::Natural paymentLag, const QuantLib::Calendar &paymentCalendar, QuantLib::BusinessDayConvention paymentConvention, QuantLib::Natural pricingLag, const QuantLib::Calendar &pricingLagCalendar, QuantLib::Real spread=0.0, QuantLib::Real gearing=1.0, PaymentTiming paymentTiming=PaymentTiming::InArrears, bool isInArrears=true, bool useFuturePrice=false, bool useFutureExpiryDate=true, QuantLib::Natural futureMonthOffset=0, const ext::shared_ptr< FutureExpiryCalculator > &calc=nullptr, const QuantLib::Date &paymentDateOverride=Date(), const QuantLib::Date &pricingDateOverride=Date(), QuantLib::Natural dailyExpiryOffset=QuantLib::Null< QuantLib::Natural >(), const ext::shared_ptr< FxIndex > &fxIndex=nullptr, const bool spotAveragingFrontCoupon=false, const QuantLib::Calendar &pricingCalendar=QuantLib::Calendar(), bool includeEndDate=true, bool excludeStartDate=true)
 
Inspectors
const QuantLib::Date & pricingDate () const
 
bool useFutureExpiryDate () const
 
QuantLib::Natural futureMonthOffset () const
 
QuantLib::Real periodQuantity () const override
 
QuantLib::Natural dailyExpiryOffset () const
 
CommodityCashFlow interface
const std::vector< std::pair< QuantLib::Date, ext::shared_ptr< CommodityIndex > > > & indices () const override
 Return a map of pricing date and corresponding commodity index. More...
 
const ext::shared_ptr< CommodityIndex > & spotIndex () const
 
const std::set< QuantLib::Date > & spotAveragingPricingDates () const
 
bool isAveragingFrontMonthCashflow (const QuantLib::Date &asof) const
 
QuantLib::Date lastPricingDate () const override
 
QuantLib::Real fixing () const override
 
Event interface
QuantLib::Date date () const override
 
CashFlow interface
QuantLib::Real amount () const override
 
- Public Member Functions inherited from CommodityCashFlow
 CommodityCashFlow (QuantLib::Real quantity, QuantLib::Real spread, QuantLib::Real gearing, bool useFuturePrice, const ext::shared_ptr< CommodityIndex > &index, const ext::shared_ptr< FxIndex > &fxIndex)
 
QuantLib::Real quantity () const
 
QuantLib::Real spread () const
 
QuantLib::Real gearing () const
 
bool useFuturePrice () const
 
ext::shared_ptr< CommodityIndexindex () const
 
ext::shared_ptr< FxIndexfxIndex () const
 
virtual const std::vector< std::pair< QuantLib::Date, ext::shared_ptr< CommodityIndex > > > & indices () const =0
 Return a map of pricing date and corresponding commodity index. More...
 
virtual QuantLib::Date lastPricingDate () const =0
 
virtual QuantLib::Real periodQuantity () const =0
 
virtual QuantLib::Real fixing () const =0
 
void accept (QuantLib::AcyclicVisitor &v) override
 

Visitability

QuantLib::Date pricingDate_
 
QuantLib::Date paymentDate_
 
bool useFutureExpiryDate_
 
QuantLib::Natural futureMonthOffset_
 
QuantLib::Real periodQuantity_
 
QuantLib::Natural dailyExpiryOffset_
 
std::vector< std::pair< QuantLib::Date, ext::shared_ptr< CommodityIndex > > > indices_
 
bool isAveraging_
 
std::set< QuantLib::Date > spotAveragingPricingDates_
 
ext::shared_ptr< CommodityIndexspotIndex_
 
QuantLib::Real price_
 
void accept (QuantLib::AcyclicVisitor &v) override
 
void setPeriodQuantity (QuantLib::Real periodQuantity)
 Allow the full calculation period quantity to be updated. More...
 
void performCalculations () const override
 
void init (const ext::shared_ptr< FutureExpiryCalculator > &calc, const QuantLib::Date &contractDate=QuantLib::Date(), const PaymentTiming paymentTiming=PaymentTiming::InArrears, const QuantLib::Date &startDate=QuantLib::Date(), const QuantLib::Date &endDate=QuantLib::Date(), const QuantLib::Natural paymentLag=0, const QuantLib::BusinessDayConvention paymentConvention=QuantLib::Unadjusted, const QuantLib::Calendar &paymentCalendar=QuantLib::NullCalendar(), const QuantLib::Calendar &pricingCalendar=QuantLib::Calendar(), bool includeEndDate=true, bool excludeStartDate=true)
 Shared initialisation. More...
 

Additional Inherited Members

- Protected Attributes inherited from CommodityCashFlow
QuantLib::Real quantity_
 
QuantLib::Real spread_
 
QuantLib::Real gearing_
 
bool useFuturePrice_
 
ext::shared_ptr< CommodityIndexindex_
 
ext::shared_ptr< FxIndexfxIndex_
 
QuantLib::Real amount_
 

Detailed Description

Cash flow dependent on a single commodity spot price or futures settlement price on a given pricing date.

Definition at line 37 of file commodityindexedcashflow.hpp.

Member Enumeration Documentation

◆ PaymentTiming

enum class PaymentTiming
strong

Constructor & Destructor Documentation

◆ CommodityIndexedCashFlow() [1/2]

CommodityIndexedCashFlow ( QuantLib::Real  quantity,
const QuantLib::Date &  pricingDate,
const QuantLib::Date &  paymentDate,
const ext::shared_ptr< CommodityIndex > &  index,
QuantLib::Real  spread = 0.0,
QuantLib::Real  gearing = 1.0,
bool  useFuturePrice = false,
const Date &  contractDate = Date(),
const ext::shared_ptr< FutureExpiryCalculator > &  calc = nullptr,
QuantLib::Natural  dailyExpiryOffset = QuantLib::Null< QuantLib::Natural >(),
const ext::shared_ptr< FxIndex > &  fxIndex = nullptr 
)

Constructor taking an explicit pricingDate and paymentDate.

◆ CommodityIndexedCashFlow() [2/2]

CommodityIndexedCashFlow ( QuantLib::Real  quantity,
const QuantLib::Date &  startDate,
const QuantLib::Date &  endDate,
const ext::shared_ptr< CommodityIndex > &  index,
QuantLib::Natural  paymentLag,
const QuantLib::Calendar &  paymentCalendar,
QuantLib::BusinessDayConvention  paymentConvention,
QuantLib::Natural  pricingLag,
const QuantLib::Calendar &  pricingLagCalendar,
QuantLib::Real  spread = 0.0,
QuantLib::Real  gearing = 1.0,
PaymentTiming  paymentTiming = PaymentTiming::InArrears,
bool  isInArrears = true,
bool  useFuturePrice = false,
bool  useFutureExpiryDate = true,
QuantLib::Natural  futureMonthOffset = 0,
const ext::shared_ptr< FutureExpiryCalculator > &  calc = nullptr,
const QuantLib::Date &  paymentDateOverride = Date(),
const QuantLib::Date &  pricingDateOverride = Date(),
QuantLib::Natural  dailyExpiryOffset = QuantLib::Null< QuantLib::Natural >(),
const ext::shared_ptr< FxIndex > &  fxIndex = nullptr,
const bool  spotAveragingFrontCoupon = false,
const QuantLib::Calendar &  pricingCalendar = QuantLib::Calendar(),
bool  includeEndDate = true,
bool  excludeStartDate = true 
)

Constructor taking a period startDate, endDate and some conventions. The pricing date and payment date are derived from the start date and end date using the conventions.

Member Function Documentation

◆ pricingDate()

const QuantLib::Date & pricingDate ( ) const

Definition at line 75 of file commodityindexedcashflow.hpp.

+ Here is the caller graph for this function:

◆ useFutureExpiryDate()

bool useFutureExpiryDate ( ) const

◆ futureMonthOffset()

QuantLib::Natural futureMonthOffset ( ) const

Definition at line 77 of file commodityindexedcashflow.hpp.

◆ periodQuantity()

QuantLib::Real periodQuantity ( ) const
overridevirtual

Implements CommodityCashFlow.

Definition at line 78 of file commodityindexedcashflow.hpp.

◆ dailyExpiryOffset()

QuantLib::Natural dailyExpiryOffset ( ) const

Definition at line 79 of file commodityindexedcashflow.hpp.

◆ indices()

const std::vector< std::pair< QuantLib::Date, ext::shared_ptr< CommodityIndex > > > & indices ( ) const
overridevirtual

Return a map of pricing date and corresponding commodity index.

Implements CommodityCashFlow.

Definition at line 84 of file commodityindexedcashflow.hpp.

84{ return indices_; }
std::vector< std::pair< QuantLib::Date, ext::shared_ptr< CommodityIndex > > > indices_

◆ spotIndex()

const ext::shared_ptr< CommodityIndex > & spotIndex ( ) const

Definition at line 87 of file commodityindexedcashflow.hpp.

87{ return spotIndex_;}
ext::shared_ptr< CommodityIndex > spotIndex_

◆ spotAveragingPricingDates()

const std::set< QuantLib::Date > & spotAveragingPricingDates ( ) const

Definition at line 89 of file commodityindexedcashflow.hpp.

std::set< QuantLib::Date > spotAveragingPricingDates_

◆ isAveragingFrontMonthCashflow()

bool isAveragingFrontMonthCashflow ( const QuantLib::Date &  asof) const

◆ lastPricingDate()

QuantLib::Date lastPricingDate ( ) const
overridevirtual

Implements CommodityCashFlow.

Definition at line 94 of file commodityindexedcashflow.hpp.

94{ return pricingDate(); }
const QuantLib::Date & pricingDate() const
+ Here is the call graph for this function:

◆ fixing()

Real fixing ( ) const
overridevirtual

Implements CommodityCashFlow.

Definition at line 105 of file commodityindexedcashflow.cpp.

105 {
106 calculate();
107 return price_;
108}

◆ date()

QuantLib::Date date ( ) const
override

Definition at line 101 of file commodityindexedcashflow.hpp.

◆ amount()

Real amount ( ) const
override

Definition at line 100 of file commodityindexedcashflow.cpp.

100 {
101 calculate();
102 return amount_;
103}

◆ accept()

void accept ( QuantLib::AcyclicVisitor &  v)
override

Definition at line 115 of file commodityindexedcashflow.cpp.

115 {
116 if (Visitor<CommodityIndexedCashFlow>* v1 = dynamic_cast<Visitor<CommodityIndexedCashFlow>*>(&v))
117 v1->visit(*this);
118 else
120}
void accept(QuantLib::AcyclicVisitor &v) override

◆ setPeriodQuantity()

void setPeriodQuantity ( QuantLib::Real  periodQuantity)

Allow the full calculation period quantity to be updated.

Definition at line 122 of file commodityindexedcashflow.cpp.

◆ performCalculations()

void performCalculations ( ) const
overrideprivate

Definition at line 80 of file commodityindexedcashflow.cpp.

80 {
81 Date today = Settings::instance().evaluationDate();
82 price_ = 0.0;
84 for (const auto& pd : spotAveragingPricingDates_) {
85 double fxRate = (fxIndex_) ? this->fxIndex()->fixing(pricingDate_) : 1.0;
86 if (pd <= today) {
87 price_ += fxRate * spotIndex_->fixing(pd);
88 } else {
89 price_ += fxRate * index_->fixing(pricingDate_);
90 }
91 }
92 price_ /= static_cast<double>(spotAveragingPricingDates_.size());
93 } else {
94 double fxRate = (fxIndex_) ? this->fxIndex()->fixing(pricingDate_) : 1.0;
95 price_ = fxRate * index_->fixing(pricingDate_);
96 }
98}
ext::shared_ptr< FxIndex > fxIndex() const
ext::shared_ptr< FxIndex > fxIndex_
ext::shared_ptr< CommodityIndex > index_
bool isAveragingFrontMonthCashflow(const QuantLib::Date &asof) const

◆ init()

void init ( const ext::shared_ptr< FutureExpiryCalculator > &  calc,
const QuantLib::Date &  contractDate = QuantLib::Date(),
const PaymentTiming  paymentTiming = PaymentTiming::InArrears,
const QuantLib::Date &  startDate = QuantLib::Date(),
const QuantLib::Date &  endDate = QuantLib::Date(),
const QuantLib::Natural  paymentLag = 0,
const QuantLib::BusinessDayConvention  paymentConvention = QuantLib::Unadjusted,
const QuantLib::Calendar &  paymentCalendar = QuantLib::NullCalendar(),
const QuantLib::Calendar &  pricingCalendar = QuantLib::Calendar(),
bool  includeEndDate = true,
bool  excludeStartDate = true 
)
private

Shared initialisation.

Definition at line 124 of file commodityindexedcashflow.cpp.

129 {
130
131 pricingDate_ = index_->fixingCalendar().adjust(pricingDate_, Preceding);
132
133 // If we are using the future settlement price as the reference price, then we need to create the
134 // relevant "future index" here and update the cashflow's index with it.
135 Date expiry;
136 if (useFuturePrice_) {
137 QL_REQUIRE(calc, "CommodityIndexedCashFlow needs a valid future expiry calculator when using "
138 << "the future settlement price as reference price");
139 expiry = calc->expiryDate(contractDate, futureMonthOffset_);
140 if (dailyExpiryOffset_ != Null<Natural>()) {
141 expiry = index_->fixingCalendar().advance(expiry, dailyExpiryOffset_ * Days);
142 }
143 index_ = index_->clone(expiry);
144 isAveraging_ = isAveraging_ && startDate != Date() && endDate != Date();
145 if (isAveraging_) {
146 // If pricing calendar is not set, use the index fixing calendar
147 Calendar cal = pricingCalendar;
148 if (pricingCalendar == Calendar()) {
149 cal = index_->fixingCalendar();
150 }
151
152 // Create Spot Index
153 spotIndex_ = ext::make_shared<CommoditySpotIndex>(index_->underlyingName(), cal,
154 index_->priceCurve());
155 if (spotIndex_) {
156 registerWith(spotIndex_);
158 pricingDates(startDate, endDate, cal, excludeStartDate, includeEndDate);
159 for (const auto& d : spotAveragingPricingDates_) {
160 indices_.push_back({d, spotIndex_});
161 }
162 }
163 }
164 }
165
166 // Derive the payment date if an explicit override has not been provided
167 if (paymentDate_ == Date()) {
168 if (paymentTiming == PaymentTiming::InAdvance) {
169 QL_REQUIRE(startDate != Date(), "CommodityIndexedCashFlow: startDate is null, can not derive paymentDate.");
170 paymentDate_ = startDate;
171 } else if (paymentTiming == PaymentTiming::InArrears) {
172 QL_REQUIRE(endDate != Date(), "CommodityIndexedCashFlow: endDate is null, can not derive paymentDate.");
173 paymentDate_ = endDate;
174 } else if (paymentTiming == PaymentTiming::RelativeToExpiry) {
175 QL_REQUIRE(
176 expiry != Date(),
177 "CommodityIndexedCashFlow: payment relative to expiry date only possibly when future price is used.");
178 paymentDate_ = expiry;
179 }
180 paymentDate_ = paymentCalendar.advance(paymentDate_, paymentLag, Days, paymentConvention);
181 }
182
183 // the pricing date has to lie on or before the payment date
184 pricingDate_ = index_->fixingCalendar().adjust(std::min(paymentDate_, pricingDate_), Preceding);
185
186 indices_.push_back({pricingDate_, index_});
187
188 registerWith(index_);
189}
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:

Member Data Documentation

◆ pricingDate_

QuantLib::Date pricingDate_
private

Definition at line 120 of file commodityindexedcashflow.hpp.

◆ paymentDate_

QuantLib::Date paymentDate_
private

Definition at line 121 of file commodityindexedcashflow.hpp.

◆ useFutureExpiryDate_

bool useFutureExpiryDate_
private

Definition at line 122 of file commodityindexedcashflow.hpp.

◆ futureMonthOffset_

QuantLib::Natural futureMonthOffset_
private

Definition at line 123 of file commodityindexedcashflow.hpp.

◆ periodQuantity_

QuantLib::Real periodQuantity_
private

Definition at line 124 of file commodityindexedcashflow.hpp.

◆ dailyExpiryOffset_

QuantLib::Natural dailyExpiryOffset_
private

Definition at line 125 of file commodityindexedcashflow.hpp.

◆ indices_

std::vector<std::pair<QuantLib::Date, ext::shared_ptr<CommodityIndex> > > indices_
private

Definition at line 126 of file commodityindexedcashflow.hpp.

◆ isAveraging_

bool isAveraging_
private

Definition at line 129 of file commodityindexedcashflow.hpp.

◆ spotAveragingPricingDates_

std::set<QuantLib::Date> spotAveragingPricingDates_
private

Definition at line 130 of file commodityindexedcashflow.hpp.

◆ spotIndex_

ext::shared_ptr<CommodityIndex> spotIndex_
private

Definition at line 131 of file commodityindexedcashflow.hpp.

◆ price_

QuantLib::Real price_
mutableprivate

Definition at line 132 of file commodityindexedcashflow.hpp.