24#ifndef quantlib_cpi_capfloor_term_price_surface_hpp
25#define quantlib_cpi_capfloor_term_price_surface_hpp
27#include <ql/termstructures/inflationtermstructure.hpp>
28#include <ql/math/interpolation.hpp>
29#include <ql/math/interpolations/interpolation2d.hpp>
30#include <ql/experimental/inflation/polynomial2Dspline.hpp>
31#include <ql/indexes/inflationindex.hpp>
63 const ext::shared_ptr<ZeroInflationIndex>& zii,
66 const std::vector<Rate>& cStrikes,
67 const std::vector<Rate>& fStrikes,
68 const std::vector<Period>& cfMaturities,
126 ext::shared_ptr<ZeroInflationIndex>
zii_;
145 template<
class Interpolator2D>
155 const ext::shared_ptr<ZeroInflationIndex>& zii,
158 const std::vector<Rate> &cStrikes,
159 const std::vector<Rate> &fStrikes,
160 const std::vector<Period> &cfMaturities,
163 const Interpolator2D &interpolator2d = Interpolator2D());
198 template<
class Interpolator2D>
202 const Period &observationLag,
206 const ext::shared_ptr<ZeroInflationIndex>& zii,
209 const std::vector<Rate> &cStrikes,
210 const std::vector<Rate> &fStrikes,
211 const std::vector<Period> &cfMaturities,
214 const Interpolator2D &interpolator2d)
216 zii, interpolationType, yts, cStrikes, fStrikes,
217 cfMaturities, cPrice, fPrice),
218 interpolator2d_(interpolator2d) {
238 QL_REQUIRE(!yts.
empty(),
"Yts is empty!!!");
240 for (
Size j = 0; j < cfMaturities_.size(); ++j) {
241 Period mat = cfMaturities_[j];
242 Real df = yts->discount(cpiOptionDateFromTenor(mat));
243 Real atm_quote = atmRate(cpiOptionDateFromTenor(mat));
244 Real atm = std::pow(1.0 + atm_quote, mat.
length());
246 for (
Size i = 0; i < cfStrikes_.size(); ++i) {
247 Real K_quote = cfStrikes_[i];
248 Real K = std::pow(1.0 + K_quote, mat.
length());
250 Size indF = std::find_if(fStrikes_.begin(), fStrikes_.end(),
close) - fStrikes_.begin();
251 Size indC = std::find_if(cStrikes_.begin(), cStrikes_.end(),
close) - cStrikes_.begin();
252 bool isFloorStrike = indF < fStrikes_.size();
253 bool isCapStrike = indC < cStrikes_.size();
255 fPriceB_[i][j] = fPrice_[indF][j];
257 cPriceB_[i][j] = fPrice_[indF][j] +
S - K * df;
261 cPriceB_[i][j] = cPrice_[indC][j];
262 if (!isFloorStrike) {
263 fPriceB_[i][j] = cPrice_[indC][j] + K * df -
S;
270 for (
Size i = 0; i < cPriceB_.rows(); ++i) {
271 for (
Size j = 0; j < cPriceB_.columns(); ++j) {
273 "InterpolatedCPICapFloorTermPriceSurface: did not "
274 "fill call price matrix at ("
275 << i <<
"," << j <<
"), this is unexpected");
277 "InterpolatedCPICapFloorTermPriceSurface: did not "
278 "fill floor price matrix at ("
279 << i <<
"," << j <<
"), this is unexpected");
283 cfMaturityTimes_.clear();
284 for (
Size i=0; i<cfMaturities_.size();i++) {
285 cfMaturityTimes_.push_back(timeFromReference(cpiOptionDateFromTenor(cfMaturities_[i])));
288 capPrice_ = interpolator2d_.interpolate(cfMaturityTimes_.begin(),cfMaturityTimes_.end(),
289 cfStrikes_.begin(), cfStrikes_.end(),
292 capPrice_.enableExtrapolation();
294 floorPrice_ = interpolator2d_.interpolate(cfMaturityTimes_.begin(),cfMaturityTimes_.end(),
295 cfStrikes_.begin(), cfStrikes_.end(),
298 floorPrice_.enableExtrapolation();
306 Rate atm = atmRate(d);
307 return k > atm ? capPrice(d,k): floorPrice(d,k);
314 Time t = timeFromReference(d);
315 return capPrice_(t,k);
322 Time t = timeFromReference(d);
323 return floorPrice_(t,k);
Provides cpi cap/floor prices by interpolation and put/call parity (not cap/floor/swap* parity).
virtual Real price(const Date &d, Rate k) const =0
virtual Rate maxStrike() const
virtual std::vector< Rate > strikes() const
virtual Date cpiOptionDateFromTenor(const Period &p) const
std::vector< Rate > cfStrikes_
std::vector< Period > cfMaturities_
std::vector< Rate > fStrikes_
Handle< YieldTermStructure > nominalTS_
virtual std::vector< Rate > floorStrikes() const
std::vector< Rate > cStrikes_
Date baseDate() const override
minimum (base) date
virtual Rate minStrike() const
virtual Real capPrice(const Date &d, Rate k) const =0
Period observationLag() const override
std::vector< Real > cfMaturityTimes_
virtual std::vector< Period > maturities() const
Rate atmRate(Date maturity) const
virtual Real nominal() const
inspectors
virtual bool checkStrike(Rate K)
virtual Date minDate() const
BusinessDayConvention bdc_
Date maxDate() const override
the latest date for which the curve can return values
virtual Real capPrice(const Period &d, Rate k) const
ext::shared_ptr< ZeroInflationIndex > zeroInflationIndex() const
ext::shared_ptr< ZeroInflationIndex > zii_
virtual bool checkMaturity(const Date &d)
virtual Real floorPrice(const Date &d, Rate k) const =0
virtual Real price(const Period &d, Rate k) const
virtual const Matrix & capPrices() const
CPI::InterpolationType interpolationType_
virtual BusinessDayConvention businessDayConvention() const
virtual Real floorPrice(const Period &d, Rate k) const
virtual std::vector< Rate > capStrikes() const
virtual const Matrix & floorPrices() const
Shared handle to an observable.
bool empty() const
checks if the contained shared pointer points to anything
Interface for inflation term structures.
virtual Rate baseRate() const
Interpolator2D interpolator2d_
void performCalculations() const
Interpolation2D capPrice_
Interpolation2D floorPrice_
InterpolatedCPICapFloorTermPriceSurface(Real nominal, Rate startRate, const Period &observationLag, const Calendar &cal, const BusinessDayConvention &bdc, const DayCounter &dc, const ext::shared_ptr< ZeroInflationIndex > &zii, CPI::InterpolationType interpolationType, const Handle< YieldTermStructure > &yts, const std::vector< Rate > &cStrikes, const std::vector< Rate > &fStrikes, const std::vector< Period > &cfMaturities, const Matrix &cPrice, const Matrix &fPrice, const Interpolator2D &interpolator2d=Interpolator2D())
Real capPrice(const Date &d, Rate k) const override
remember that the strike uses the quoting convention
Real floorPrice(const Date &d, Rate k) const override
remember that the strike uses the quoting convention
Real price(const Date &d, Rate k) const override
remember that the strikes use the quoting convention
base class for 2-D interpolations.
Matrix used in linear algebra.
template class providing a null value for a given type.
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
bool close(const Quantity &m1, const Quantity &m2, Size n)
bool close_enough(const Quantity &m1, const Quantity &m2, Size n)
InterpolationType
when you observe an index, how do you interpolate between fixings?