23 const QuantLib::Date& expiryDate,
24 const QuantLib::Calendar& fixingCalendar,
25 const QuantLib::ext::shared_ptr<FutureExpiryCalculator>& basisFec,
26 const QuantLib::ext::shared_ptr<QuantExt::CommodityIndex>& baseIndex,
27 const QuantLib::ext::shared_ptr<FutureExpiryCalculator>& baseFec,
28 const QuantLib::Handle<QuantExt::PriceTermStructure>& priceCurve,
29 const bool addBasis,
const QuantLib::Size monthOffset,
30 const bool baseIsAveraging,
const bool priceAsHistoricalFixing)
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");
37 "non-null future expiry calculator for the basis conventions CommodityBasisFutureIndex");
39 "non-null future expiry calculator for the base conventions CommodityBasisFutureIndex");
46 const std::string& underlyingName,
const QuantLib::Date& expiryDate,
const QuantLib::Calendar& fixingCalendar,
47 const QuantLib::ext::shared_ptr<CommodityBasisPriceTermStructure>& priceCurve)
49 priceCurve->baseIndex(), priceCurve->baseFutureExpiryCalculator(),
51 priceCurve->monthOffset(), priceCurve->averagingBaseCashflow(),
52 priceCurve->priceAsHistoricalFixing()) {}
54QuantLib::ext::shared_ptr<CommodityIndex>
56 const boost::optional<QuantLib::Handle<PriceTermStructure>>& ts)
const {
58 const auto& ed = expiry == Date() ?
expiryDate() : expiry;
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;
80 }
else if (basisFixing == QuantLib::Null<Real>()) {
81 return QuantLib::Null<Real>();
Commodity Basis Future Index.
QuantLib::ext::shared_ptr< FutureExpiryCalculator > baseFec_
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)
const QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > & baseIndex()
QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > baseIndex_
QuantLib::Size monthOffset_
QuantLib::ext::shared_ptr< FutureExpiryCalculator > basisFec_
QuantLib::ext::shared_ptr< CommodityIndex > clone(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.
QuantLib::ext::shared_ptr< QuantLib::CashFlow > cashflow_
bool priceAsHistoricalFixing_
QuantLib::Real pastFixing(const QuantLib::Date &fixingDate) const override
QuantLib::ext::shared_ptr< QuantLib::CashFlow > baseCashflow(const QuantLib::Date &paymentDate=QuantLib::Date()) const
const QuantLib::Date & expiryDate() const
Calendar fixingCalendar() const override
const Handle< QuantExt::PriceTermStructure > & priceCurve() const
std::string underlyingName() const
virtual Real pastFixing(const Date &fixingDate) const override
returns a past fixing at the given date
commodity basis future index class for holding price histories and forwarding.
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.