25#include <ql/time/daycounters/actualactual.hpp>
26#include <ql/pricingengines/blackformula.hpp>
35 const QuantLib::Handle<QuantLib::CPIVolatilitySurface>& surface,
36 const bool ttmFromLastAvailableFixing)
37 : discountCurve_(discountCurve), volatilitySurface_(surface),
38 ttmFromLastAvailableFixing_(ttmFromLastAvailableFixing) {
58 QL_DEPRECATED_DISABLE_WARNING
59 bool isInterpolated =
arguments_.observationInterpolation == CPI::Linear ||
60 (
arguments_.observationInterpolation == CPI::AsIndex && index->interpolated());
61 QL_DEPRECATED_ENABLE_WARNING
64 index->frequency(), isInterpolated);
67 index->frequency(), isInterpolated);
69 Real optionBaseFixing =
arguments_.baseCPI == Null<Real>()
77 Time timeToMaturityFromInception =
78 inflationYearFraction(index->frequency(), isInterpolated, index->zeroInflationTermStructure()->dayCounter(),
79 optionBaseDate, optionObservationDate);
81 Real atmGrowth = atmCPIFixing / optionBaseFixing;
82 Real strike = std::pow(1.0 +
arguments_.strike, timeToMaturityFromInception);
85 auto observationPeriod = inflationPeriod(optionObservationDate, index->frequency());
86 auto requiredFixing = isInterpolated ? observationPeriod.first : observationPeriod.second + 1 * Days;
92 Real strikeZeroRate = 0.0;
93 Real ttmFromSurfaceBaseDate = 0.0;
94 Real surfaceBaseFixing = 0.0;
95 if (requiredFixing > lastKnownFixingDate) {
102 ttmFromSurfaceBaseDate =
104 index->zeroInflationTermStructure()->dayCounter(),
volatilitySurface_->baseDate(), optionObservationDate);
105 strikeZeroRate =
pow(optionBaseFixing / surfaceBaseFixing * strike, 1.0 / ttmFromSurfaceBaseDate) - 1.0;
106 vol =
volatilitySurface_->volatility(optionObservationDate, strikeZeroRate, 0 * Days);
111 stdDev = std::sqrt(ttm * vol * vol);
113 stdDev = std::sqrt(
volatilitySurface_->totalVariance(optionObservationDate, strikeZeroRate, 0 * Days));
119 results_.additionalResults[
"strike"] = strike;
120 results_.additionalResults[
"forward"] = atmGrowth;
121 results_.additionalResults[
"stdDev"] = stdDev;
122 results_.additionalResults[
"discount"] = d;
123 results_.additionalResults[
"vol"] = vol;
124 results_.additionalResults[
"timeToExpiry"] = stdDev * stdDev / (vol * vol);
125 results_.additionalResults[
"BaseDate_trade"] = optionBaseDate;
127 results_.additionalResults[
"FixingDate"] = optionObservationDate;
128 results_.additionalResults[
"PaymentDate"] = maturity;
129 results_.additionalResults[
"BaseCPI_trade"] = optionBaseFixing;
130 results_.additionalResults[
"BaseCPI_today"] = surfaceBaseFixing;
131 results_.additionalResults[
"ForwardCPI"] = atmCPIFixing;
133 results_.additionalResults[
"strike_asof_today"] = strikeZeroRate;
134 results_.additionalResults[
"timeToExpiry_from_trade_baseDate"] = timeToMaturityFromInception;
135 results_.additionalResults[
"timeToExpiry_from_todays_baseDate"] = ttmFromSurfaceBaseDate;
159 double stdDev,
double discount)
const {
160 return blackFormula(type, strike, forward, stdDev, discount);
const Instrument::results * results_
virtual double optionPriceImpl(QuantLib::Option::Type type, double strike, double forward, double stdDev, double discount) const override
QuantLib::Handle< QuantLib::CPIVolatilitySurface > volatilitySurface_
virtual double optionPriceImpl(QuantLib::Option::Type type, double forward, double strike, double stdDev, double discount) const =0
virtual void calculate() const override
QuantLib::Handle< QuantLib::YieldTermStructure > discountCurve_
void setVolatility(const QuantLib::Handle< QuantLib::CPIVolatilitySurface > &surface)
CPICapFloorEngine(const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve, const QuantLib::Handle< QuantLib::CPIVolatilitySurface > &surface, const bool ttmFromLastAvailableFixing=false)
bool ttmFromLastAvailableFixing_
CPI cap/floor engine using the Black pricing formula and interpreting the volatility data as lognorma...
some inflation related utilities.
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
QuantLib::Date lastAvailableFixing(const QuantLib::ZeroInflationIndex &index, const QuantLib::Date &asof)
Check if today - availabilityLag is already known, otherwise return the fixingDate of the previous fi...
QuantLib::Rate cpiFixing(const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &index, const QuantLib::Date &maturity, const QuantLib::Period &obsLag, bool interpolated)
Computes a CPI fixing giving an zeroIndex, with interpolation if needed.
CompiledFormula pow(CompiledFormula x, const CompiledFormula &y)
Swap::arguments * arguments_