37 : BlackVolatilityTermStructure(referenceDate, baseVts->calendar(), baseVts->businessDayConvention(),
38 baseVts->dayCounter()),
40
41
42 QL_REQUIRE(!pts.empty(), "The price term structure should not be empty.");
43 QL_REQUIRE(!yts.empty(), "The yield term structure should not be empty.");
44 QL_REQUIRE(expCalc, "The expiry calculator should not be null.");
45 QL_REQUIRE(!baseVts.empty(), "The base volatility term structure should not be empty.");
46 QL_REQUIRE(!
index_->priceCurve().empty(),
"The commodity index should have a base price curve.");
47 QL_REQUIRE(
baseExpCalc_,
"The base expiry calculator should not be null.");
48
49
50 registerWith(pts);
51 registerWith(yts);
52 registerWith(baseVts);
53
54
56 if (maxTenor) {
57
58 maxDate = referenceDate + *maxTenor;
59 } else {
64 "Could not determine a maximum date for the ApoFutureSurface");
65 }
66 }
67 QL_REQUIRE(
maxDate > referenceDate,
"Expected the max date, " << io::iso_date(
maxDate)
68 << ", to be greater than the reference date, "
69 << io::iso_date(referenceDate) << ".");
70
71
72
73
74
75 apoDates_ = { expCalc->priorExpiry(
true, referenceDate) };
76 vector<Time> apoTimes;
79 apoTimes.push_back(timeFromReference(
apoDates_.back()));
80 }
81
82
83 Handle<Quote> spot(QuantLib::ext::make_shared<DerivedPriceQuote>(pts));
84 Handle<YieldTermStructure> pyts =
85 Handle<YieldTermStructure>(QuantLib::ext::make_shared<PriceTermStructureAdapter>(*pts, *yts));
86 pyts->enableExtrapolation();
87
88
89 bool stickyStrike = false;
90
91
92
93
94 vector<vector<Handle<Quote> > > vols(moneynessLevels.size());
95 for (Size i = 0; i < moneynessLevels.size(); i++) {
96 for (Size j = 0; j < apoTimes.size(); j++) {
97 vols_[i].push_back(QuantLib::ext::make_shared<SimpleQuote>(0.0));
98 vols[i].push_back(Handle<Quote>(
vols_[i].back()));
99 }
100 }
101
102
103 vts_ = QuantLib::ext::make_shared<BlackVarianceSurfaceMoneynessForward>(calendar_, spot, apoTimes, moneynessLevels, vols,
104 baseVts->dayCounter(), pyts, yts, stickyStrike,
105 flatStrikeExtrapolation);
106
107 vts_->enableExtrapolation();
108
109
110 apoEngine_ = QuantLib::ext::make_shared<CommodityAveragePriceOptionAnalyticalEngine>(yts, baseVts, beta);
111}
std::vector< std::vector< QuantLib::ext::shared_ptr< QuantLib::SimpleQuote > > > vols_
This will keep a handle on the APO vol quotes that are calculated.
QuantLib::ext::shared_ptr< BlackVarianceSurfaceMoneyness > vts_
The surface that is created to do the work.
QuantLib::ext::shared_ptr< CommodityIndex > index_
QuantLib::Date maxDate() const override
std::vector< QuantLib::Date > apoDates_
The APO schedule dates.
QuantLib::ext::shared_ptr< CommodityAveragePriceOptionBaseEngine > apoEngine_
The engine for valuing the APOs.
QuantLib::ext::shared_ptr< FutureExpiryCalculator > baseExpCalc_