43#include <ql/time/daycounters/actualactual.hpp>
45#include <ql/experimental/inflation/cpicapfloortermpricesurface.hpp>
53 : priceSurf_(priceSurf) {
61 Handle<ZeroInflationIndex> zii(
arguments_.index);
62 Handle<ZeroInflationTermStructure> zits = zii->zeroInflationTermStructure();
63 Date baseDate = zits->baseDate();
65 Real baseFixing = zii->fixing(baseDate);
68 QL_DEPRECATED_DISABLE_WARNING
69 bool isInterpolated =
arguments_.observationInterpolation == CPI::Linear ||
70 (
arguments_.observationInterpolation == CPI::AsIndex && zii->interpolated());
71 QL_DEPRECATED_ENABLE_WARNING
74 std::pair<Date, Date> ipm = inflationPeriod(adjustedMaturity, zii->frequency());
75 adjustedMaturity = ipm.first;
79 std::pair<Date, Date> ips = inflationPeriod(adjustedStart, zii->frequency());
80 adjustedStart = ips.first;
82 Real timeFromStart = zits->dayCounter().yearFraction(adjustedStart, adjustedMaturity);
83 Real timeFromBase = zits->dayCounter().yearFraction(baseDate, adjustedMaturity);
84 Real strike =
pow(baseCPI / baseFixing *
pow(1.0 +
arguments_.strike, timeFromStart), 1.0 / timeFromBase) - 1.0;
92 QL_REQUIRE(lagDiff >= Period(0, Months),
"InterpolatingCPICapFloorEngine: "
93 "lag difference must be non-negative: "
99 Date effectiveMaturity =
arguments_.payDate - lagDiff;
102 if (
arguments_.observationInterpolation == CPI::AsIndex) {
106 npv =
priceSurf_->capPrice(effectiveMaturity, strike);
108 npv =
priceSurf_->floorPrice(effectiveMaturity, strike);
112 std::pair<Date, Date> dd = inflationPeriod(effectiveMaturity,
arguments_.index->frequency());
113 Real priceStart = 0.0;
116 priceStart =
priceSurf_->capPrice(dd.first, strike);
118 priceStart =
priceSurf_->floorPrice(dd.first, strike);
122 if (
arguments_.observationInterpolation == CPI::Flat) {
130 priceEnd =
priceSurf_->capPrice((dd.second + Period(1, Days)), strike);
132 priceEnd =
priceSurf_->floorPrice((dd.second + Period(1, Days)), strike);
135 npv = priceStart + (priceEnd - priceStart) * (effectiveMaturity - dd.first) /
136 ((dd.second + Period(1, Days)) - dd.first);
const Instrument::results * results_
virtual void calculate() const override
QuantLib::Handle< QuantLib::CPICapFloorTermPriceSurface > priceSurf_
InterpolatingCPICapFloorEngine(const QuantLib::Handle< QuantLib::CPICapFloorTermPriceSurface > &)
Extended version of the QuantLib engine, strike adjustment for seasoned CPI Cap/Floor pricing.
CompiledFormula pow(CompiledFormula x, const CompiledFormula &y)
Swap::arguments * arguments_