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

Commodity Basis Future Index. More...

#include <qle/indexes/commoditybasisfutureindex.hpp>

+ Inheritance diagram for CommodityBasisFutureIndex:
+ Collaboration diagram for CommodityBasisFutureIndex:

Public Member Functions

 CommodityBasisFutureIndex (const std::string &underlyingName, const QuantLib::Date &expiryDate, const QuantLib::Calendar &fixingCalendar, const QuantLib::ext::shared_ptr< FutureExpiryCalculator > &basisFec, const QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > &baseIndex, const QuantLib::ext::shared_ptr< FutureExpiryCalculator > &baseFec, const QuantLib::Handle< QuantExt::PriceTermStructure > &priceCurve=QuantLib::Handle< QuantExt::PriceTermStructure >(), const bool addBasis=true, const QuantLib::Size monthOffset=0, const bool baseIsAveraging=false, const bool priceAsHistoricalFixing=true)
 
 CommodityBasisFutureIndex (const std::string &underlyingName, const QuantLib::Date &expiryDate, const QuantLib::Calendar &fixingCalendar, const QuantLib::ext::shared_ptr< CommodityBasisPriceTermStructure > &priceCurve)
 
QuantLib::ext::shared_ptr< CommodityIndexclone (const QuantLib::Date &expiryDate=QuantLib::Date(), const boost::optional< QuantLib::Handle< PriceTermStructure > > &ts=boost::none) const override
 Implement the base clone. Ajust the base future to match the same contract month. More...
 
QuantLib::Real pastFixing (const QuantLib::Date &fixingDate) const override
 
const QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > & baseIndex ()
 
QuantLib::ext::shared_ptr< QuantLib::CashFlow > baseCashflow (const QuantLib::Date &paymentDate=QuantLib::Date()) const
 
- Public Member Functions inherited from CommodityFuturesIndex
 CommodityFuturesIndex (const std::string &underlyingName, const Date &expiryDate, const Calendar &fixingCalendar, const Handle< QuantExt::PriceTermStructure > &priceCurve=Handle< QuantExt::PriceTermStructure >())
 
 CommodityFuturesIndex (const std::string &underlyingName, const Date &expiryDate, const Calendar &fixingCalendar, bool keepDays, const Handle< QuantExt::PriceTermStructure > &priceCurve=Handle< QuantExt::PriceTermStructure >())
 
QuantLib::ext::shared_ptr< CommodityIndexclone (const QuantLib::Date &expiryDate=QuantLib::Date(), const boost::optional< QuantLib::Handle< PriceTermStructure > > &ts=boost::none) const override
 Implement the base clone. More...
 
- Public Member Functions inherited from CommodityIndex
 CommodityIndex (const std::string &underlyingName, const QuantLib::Date &expiryDate, const Calendar &fixingCalendar, const Handle< QuantExt::PriceTermStructure > &priceCurve=Handle< QuantExt::PriceTermStructure >())
 
 CommodityIndex (const std::string &underlyingName, const QuantLib::Date &expiryDate, const Calendar &fixingCalendar, bool keepDays, const Handle< QuantExt::PriceTermStructure > &priceCurve=Handle< QuantExt::PriceTermStructure >())
 
std::string name () const override
 
Calendar fixingCalendar () const override
 
bool isValidFixingDate (const Date &fixingDate) const override
 
Real fixing (const Date &fixingDate, bool forecastTodaysFixing=false) const override
 
void update () override
 
std::string underlyingName () const
 
const Handle< QuantExt::PriceTermStructure > & priceCurve () const
 
bool isFuturesIndex () const
 
const QuantLib::Date & expiryDate () const
 
bool keepDays () const
 
virtual Real forecastFixing (const Date &fixingDate) const
 
virtual Real forecastFixing (const Time &fixingTime) const override
 returns the fixing at the given time More...
 
virtual Real pastFixing (const Date &fixingDate) const override
 returns a past fixing at the given date More...
 
- Public Member Functions inherited from EqFxIndexBase
virtual ~EqFxIndexBase ()
 
virtual Real forecastFixing (const Time &fixingTime) const =0
 returns the fixing at the given time More...
 
virtual Real pastFixing (const Date &fixingDate) const =0
 returns a past fixing at the given date More...
 

Private Attributes

QuantLib::ext::shared_ptr< FutureExpiryCalculatorbasisFec_
 
QuantLib::ext::shared_ptr< QuantExt::CommodityIndexbaseIndex_
 
QuantLib::ext::shared_ptr< FutureExpiryCalculatorbaseFec_
 
bool addBasis_
 
QuantLib::Size monthOffset_
 
bool baseIsAveraging_
 
bool priceAsHistoricalFixing_
 
QuantLib::ext::shared_ptr< QuantLib::CashFlow > cashflow_
 

Additional Inherited Members

- Protected Member Functions inherited from CommodityIndex
void init ()
 
- Protected Attributes inherited from CommodityIndex
std::string underlyingName_
 
Date expiryDate_
 
Calendar fixingCalendar_
 
Handle< QuantExt::PriceTermStructurecurve_
 
std::string name_
 
bool isFuturesIndex_
 
bool keepDays_
 

Detailed Description

Commodity Basis Future Index.

This index can represent futures prices derived from basis future index and a base future index

Definition at line 36 of file commoditybasisfutureindex.hpp.

Constructor & Destructor Documentation

◆ CommodityBasisFutureIndex() [1/2]

CommodityBasisFutureIndex ( const std::string &  underlyingName,
const QuantLib::Date &  expiryDate,
const QuantLib::Calendar &  fixingCalendar,
const QuantLib::ext::shared_ptr< FutureExpiryCalculator > &  basisFec,
const QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > &  baseIndex,
const QuantLib::ext::shared_ptr< FutureExpiryCalculator > &  baseFec,
const QuantLib::Handle< QuantExt::PriceTermStructure > &  priceCurve = QuantLib::Handle<QuantExt::PriceTermStructure>(),
const bool  addBasis = true,
const QuantLib::Size  monthOffset = 0,
const bool  baseIsAveraging = false,
const bool  priceAsHistoricalFixing = true 
)

Definition at line 22 of file commoditybasisfutureindex.cpp.

32 baseIndex_(baseIndex), baseFec_(baseFec), addBasis_(addBasis), monthOffset_(monthOffset),
33 baseIsAveraging_(baseIsAveraging), priceAsHistoricalFixing_(priceAsHistoricalFixing) {
34 QL_REQUIRE(expiryDate_ != Date(), "non-empty expiry date expected for CommodityFuturesIndex");
35 QL_REQUIRE(baseIndex_ != nullptr, "non-null baseIndex required for CommodityBasisFutureIndex");
36 QL_REQUIRE(basisFec_ != nullptr,
37 "non-null future expiry calculator for the basis conventions CommodityBasisFutureIndex");
38 QL_REQUIRE(baseFec_ != nullptr,
39 "non-null future expiry calculator for the base conventions CommodityBasisFutureIndex");
40 registerWith(baseIndex);
41 if (priceAsHistoricalFixing_ == false)
43}
QuantLib::ext::shared_ptr< FutureExpiryCalculator > baseFec_
const QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > & baseIndex()
QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > baseIndex_
QuantLib::ext::shared_ptr< FutureExpiryCalculator > basisFec_
QuantLib::ext::shared_ptr< QuantLib::CashFlow > cashflow_
QuantLib::ext::shared_ptr< QuantLib::CashFlow > baseCashflow(const QuantLib::Date &paymentDate=QuantLib::Date()) const
CommodityFuturesIndex(const std::string &underlyingName, const Date &expiryDate, const Calendar &fixingCalendar, const Handle< QuantExt::PriceTermStructure > &priceCurve=Handle< QuantExt::PriceTermStructure >())
const QuantLib::Date & expiryDate() const
Calendar fixingCalendar() const override
const Handle< QuantExt::PriceTermStructure > & priceCurve() const
std::string underlyingName() const
+ Here is the call graph for this function:

◆ CommodityBasisFutureIndex() [2/2]

CommodityBasisFutureIndex ( const std::string &  underlyingName,
const QuantLib::Date &  expiryDate,
const QuantLib::Calendar &  fixingCalendar,
const QuantLib::ext::shared_ptr< CommodityBasisPriceTermStructure > &  priceCurve 
)

Definition at line 45 of file commoditybasisfutureindex.cpp.

49 priceCurve->baseIndex(), priceCurve->baseFutureExpiryCalculator(),
50 Handle<PriceTermStructure>(priceCurve), priceCurve->addBasis(),
51 priceCurve->monthOffset(), priceCurve->averagingBaseCashflow(),
52 priceCurve->priceAsHistoricalFixing()) {}
CommodityBasisFutureIndex(const std::string &underlyingName, const QuantLib::Date &expiryDate, const QuantLib::Calendar &fixingCalendar, const QuantLib::ext::shared_ptr< FutureExpiryCalculator > &basisFec, const QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > &baseIndex, const QuantLib::ext::shared_ptr< FutureExpiryCalculator > &baseFec, const QuantLib::Handle< QuantExt::PriceTermStructure > &priceCurve=QuantLib::Handle< QuantExt::PriceTermStructure >(), const bool addBasis=true, const QuantLib::Size monthOffset=0, const bool baseIsAveraging=false, const bool priceAsHistoricalFixing=true)

Member Function Documentation

◆ clone()

QuantLib::ext::shared_ptr< CommodityIndex > clone ( const QuantLib::Date &  expiryDate = QuantLib::Date(),
const boost::optional< QuantLib::Handle< PriceTermStructure > > &  ts = boost::none 
) const
overridevirtual

Implement the base clone. Ajust the base future to match the same contract month.

Implements CommodityIndex.

Definition at line 55 of file commoditybasisfutureindex.cpp.

56 {
57 const auto& pts = ts ? *ts : priceCurve();
58 const auto& ed = expiry == Date() ? expiryDate() : expiry;
59 return QuantLib::ext::make_shared<CommodityBasisFutureIndex>(underlyingName(), ed, fixingCalendar(), basisFec_, baseIndex_,
62}
+ Here is the call graph for this function:

◆ pastFixing()

QuantLib::Real pastFixing ( const QuantLib::Date &  fixingDate) const
override

Definition at line 76 of file commoditybasisfutureindex.cpp.

76 {
77 auto basisFixing = CommodityFuturesIndex::pastFixing(fixingDate);
79 return basisFixing;
80 } else if (basisFixing == QuantLib::Null<Real>()) {
81 return QuantLib::Null<Real>();
82 } else {
83 return addBasis_ ? cashflow_->amount() + basisFixing : cashflow_->amount() - basisFixing;
84 }
85}
virtual Real pastFixing(const Date &fixingDate) const override
returns a past fixing at the given date
+ Here is the call graph for this function:

◆ baseIndex()

const QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > & baseIndex ( )

Definition at line 59 of file commoditybasisfutureindex.hpp.

59{ return baseIndex_; }
+ Here is the caller graph for this function:

◆ baseCashflow()

QuantLib::ext::shared_ptr< QuantLib::CashFlow > baseCashflow ( const QuantLib::Date &  paymentDate = QuantLib::Date()) const

Definition at line 64 of file commoditybasisfutureindex.cpp.

64 {
65 // Fail-safe if expiryDate_ is not a future expiry date
66 auto nextFutureExpiry = basisFec_->nextExpiry(true, expiryDate_);
67 // Imply the contract month from the future expiry data
68 auto contractDate = basisFec_->contractDate(nextFutureExpiry);
69 Date periodStart = Date(1,contractDate.month(), contractDate.year()) - monthOffset_ * Months;
70 Date periodEnd = (periodStart + 1 * Months) - 1 * Days;
71 // Build the corresponding base-future casflow
73 paymentDate);
74}
QuantLib::ext::shared_ptr< CashFlow > makeCommodityCashflowForBasisFuture(const QuantLib::Date &start, const QuantLib::Date &end, const QuantLib::ext::shared_ptr< CommodityIndex > &baseIndex, const QuantLib::ext::shared_ptr< FutureExpiryCalculator > &baseFec, bool baseIsAveraging, const QuantLib::Date &paymentDate)
Make a commodity indexed cashflow.
Definition: commodity.cpp:7
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ basisFec_

QuantLib::ext::shared_ptr<FutureExpiryCalculator> basisFec_
private

Definition at line 63 of file commoditybasisfutureindex.hpp.

◆ baseIndex_

QuantLib::ext::shared_ptr<QuantExt::CommodityIndex> baseIndex_
private

Definition at line 64 of file commoditybasisfutureindex.hpp.

◆ baseFec_

QuantLib::ext::shared_ptr<FutureExpiryCalculator> baseFec_
private

Definition at line 65 of file commoditybasisfutureindex.hpp.

◆ addBasis_

bool addBasis_
private

Definition at line 66 of file commoditybasisfutureindex.hpp.

◆ monthOffset_

QuantLib::Size monthOffset_
private

Definition at line 67 of file commoditybasisfutureindex.hpp.

◆ baseIsAveraging_

bool baseIsAveraging_
private

Definition at line 68 of file commoditybasisfutureindex.hpp.

◆ priceAsHistoricalFixing_

bool priceAsHistoricalFixing_
private

Definition at line 69 of file commoditybasisfutureindex.hpp.

◆ cashflow_

QuantLib::ext::shared_ptr<QuantLib::CashFlow> cashflow_
private

Definition at line 70 of file commoditybasisfutureindex.hpp.