20#include <ql/utilities/null_deleter.hpp>
22using QuantLib::AcyclicVisitor;
23using QuantLib::Calendar;
25using QuantLib::Handle;
26using QuantLib::Natural;
29using QuantLib::Visitor;
34 const QuantLib::ext::shared_ptr<CommodityIndex>& index,
37 const QuantLib::ext::shared_ptr<FutureExpiryCalculator>& calc,
38 const Calendar& calendar,
39 Natural deliveryDateRoll,
40 Natural futureMonthOffset,
42 Natural dailyExpiryOffset)
44 init(index, start, end, calc, calendar, deliveryDateRoll, futureMonthOffset, useBusinessDays, dailyExpiryOffset);
47AverageFuturePriceHelper::AverageFuturePriceHelper(Real price,
48 const QuantLib::ext::shared_ptr<CommodityIndex>& index,
51 const QuantLib::ext::shared_ptr<FutureExpiryCalculator>& calc,
52 const Calendar& calendar,
53 Natural deliveryDateRoll,
54 Natural futureMonthOffset,
56 Natural dailyExpiryOffset)
58 init(index, start, end, calc, calendar, deliveryDateRoll, futureMonthOffset, useBusinessDays, dailyExpiryOffset);
61void AverageFuturePriceHelper::init(
const QuantLib::ext::shared_ptr<CommodityIndex>& index,
62 const Date& start,
const Date& end,
const QuantLib::ext::shared_ptr<FutureExpiryCalculator>& calc,
63 const Calendar& calendar, Natural deliveryDateRoll, Natural futureMonthOffset,
64 bool useBusinessDays, Natural dailyExpiryOffset) {
68 auto indexClone = index->clone(Date(), termStructureHandle_);
72 indexClone->unregisterWith(termStructureHandle_);
73 registerWith(indexClone);
76 averageCashflow_ = QuantLib::ext::make_shared<CommodityIndexedAverageCashFlow>(1.0, start, end, end, indexClone,
77 calendar, 0.0, 1.0,
true, deliveryDateRoll, futureMonthOffset, calc,
true,
false, useBusinessDays,
78 CommodityQuantityFrequency::PerCalculationPeriod, Null<Natural>(), dailyExpiryOffset);
83 const auto& mp = averageCashflow_->indices();
84 earliestDate_ = mp.begin()->second->expiryDate();
85 pillarDate_ = mp.rbegin()->second->expiryDate();
88Real AverageFuturePriceHelper::impliedQuote()
const {
89 QL_REQUIRE(termStructure_,
"AverageFuturePriceHelper term structure not set.");
90 averageCashflow_->update();
91 return averageCashflow_->amount();
95 QuantLib::ext::shared_ptr<PriceTermStructure> temp(ts, null_deleter());
97 termStructureHandle_.linkTo(temp,
false);
98 PriceHelper::setTermStructure(ts);
101void AverageFuturePriceHelper::accept(AcyclicVisitor& v) {
102 if (
auto vis =
dynamic_cast<Visitor<AverageFuturePriceHelper>*
>(&v))
105 PriceHelper::accept(v);
108QuantLib::ext::shared_ptr<CommodityIndexedAverageCashFlow> AverageFuturePriceHelper::averageCashflow()
const {
109 return averageCashflow_;
112void AverageFuturePriceHelper::deepUpdate() {
113 if (averageCashflow_)
114 averageCashflow_->update();
Price helper for average of future settlement prices over a period.
AverageFuturePriceHelper(const QuantLib::Handle< QuantLib::Quote > &price, const QuantLib::ext::shared_ptr< CommodityIndex > &index, const QuantLib::Date &start, const QuantLib::Date &end, const ext::shared_ptr< FutureExpiryCalculator > &calc, const QuantLib::Calendar &calendar=QuantLib::Calendar(), QuantLib::Natural deliveryDateRoll=0, QuantLib::Natural futureMonthOffset=0, bool useBusinessDays=true, QuantLib::Natural dailyExpiryOffset=QuantLib::Null< QuantLib::Natural >())