20#include <ql/utilities/null_deleter.hpp>
22using QuantLib::AcyclicVisitor;
23using QuantLib::Calendar;
25using QuantLib::Handle;
28using QuantLib::Visitor;
33 const QuantLib::ext::shared_ptr<CommoditySpotIndex>& index,
36 const Calendar& calendar,
39 init(index, start, end, calendar, useBusinessDays);
42AverageSpotPriceHelper::AverageSpotPriceHelper(Real price,
43 const QuantLib::ext::shared_ptr<CommoditySpotIndex>& index,
46 const Calendar& calendar,
49 init(index, start, end, calendar, useBusinessDays);
52void AverageSpotPriceHelper::init(
const QuantLib::ext::shared_ptr<CommoditySpotIndex>& index,
53 const Date& start,
const Date& end,
const Calendar& calendar,
bool useBusinessDays) {
57 auto indexClone = QuantLib::ext::make_shared<CommoditySpotIndex>(index->underlyingName(),
58 index->fixingCalendar(), termStructureHandle_);
62 indexClone->unregisterWith(termStructureHandle_);
63 registerWith(indexClone);
67 averageCashflow_ = QuantLib::ext::make_shared<CommodityIndexedAverageCashFlow>(1.0, start, end, end, indexClone,
68 calendar, 0.0, 1.0,
false, 0, 0,
nullptr,
true,
false, useBusinessDays);
72 const auto& mp = averageCashflow_->indices();
73 earliestDate_ = mp.begin()->first;
74 pillarDate_ = mp.rbegin()->first;
77Real AverageSpotPriceHelper::impliedQuote()
const {
78 QL_REQUIRE(termStructure_,
"AverageSpotPriceHelper term structure not set.");
79 return averageCashflow_->amount();
83 QuantLib::ext::shared_ptr<PriceTermStructure> temp(ts, null_deleter());
85 termStructureHandle_.linkTo(temp,
false);
86 PriceHelper::setTermStructure(ts);
89void AverageSpotPriceHelper::accept(AcyclicVisitor& v) {
90 if (
auto vis =
dynamic_cast<Visitor<AverageSpotPriceHelper>*
>(&v))
93 PriceHelper::accept(v);
96QuantLib::ext::shared_ptr<CommodityIndexedAverageCashFlow> AverageSpotPriceHelper::averageCashflow()
const {
97 return averageCashflow_;
Price helper for average of spot price over a period.
AverageSpotPriceHelper(const QuantLib::Handle< QuantLib::Quote > &price, const QuantLib::ext::shared_ptr< CommoditySpotIndex > &index, const QuantLib::Date &start, const QuantLib::Date &end, const QuantLib::Calendar &calendar=QuantLib::Calendar(), bool useBusinessDays=true)