24#ifndef quantlib_cpi_capfloor_term_price_surface_hpp
25#define quantlib_cpi_capfloor_term_price_surface_hpp
63 ext::shared_ptr<ZeroInflationIndex> zii,
66 const std::vector<Rate>& cStrikes,
67 const std::vector<Rate>& fStrikes,
68 const std::vector<Period>& cfMaturities,
128 ext::shared_ptr<ZeroInflationIndex>
zii_;
149 template<
class Interpolator2D>
159 const ext::shared_ptr<ZeroInflationIndex>& zii,
162 const std::vector<Rate> &cStrikes,
163 const std::vector<Rate> &fStrikes,
164 const std::vector<Period> &cfMaturities,
167 const Interpolator2D &interpolator2d = Interpolator2D());
202 template<
class Interpolator2D>
206 const Period &observationLag,
210 const ext::shared_ptr<ZeroInflationIndex>& zii,
213 const std::vector<Rate> &cStrikes,
214 const std::vector<Rate> &fStrikes,
215 const std::vector<Period> &cfMaturities,
218 const Interpolator2D &interpolator2d)
220 zii, interpolationType, yts, cStrikes, fStrikes,
221 cfMaturities, cPrice, fPrice),
222 interpolator2d_(interpolator2d) {
244 for (
Size j = 0; j < cfMaturities_.size(); ++j) {
245 Period mat = cfMaturities_[j];
246 Real df = yts->discount(cpiOptionDateFromTenor(mat));
247 Real atm_quote = atmRate(cpiOptionDateFromTenor(mat));
248 Real atm = std::pow(1.0 + atm_quote, mat.
length());
250 for (
Size i = 0; i < cfStrikes_.size(); ++i) {
251 Real K_quote = cfStrikes_[i];
252 Real K = std::pow(1.0 + K_quote, mat.
length());
254 Size indF = std::find_if(fStrikes_.begin(), fStrikes_.end(),
close) - fStrikes_.begin();
255 Size indC = std::find_if(cStrikes_.begin(), cStrikes_.end(),
close) - cStrikes_.begin();
256 bool isFloorStrike = indF < fStrikes_.size();
257 bool isCapStrike = indC < cStrikes_.size();
259 fPriceB_[i][j] = fPrice_[indF][j];
261 cPriceB_[i][j] = fPrice_[indF][j] +
S - K * df;
265 cPriceB_[i][j] = cPrice_[indC][j];
266 if (!isFloorStrike) {
267 fPriceB_[i][j] = cPrice_[indC][j] + K * df -
S;
274 for (
Size i = 0; i < cPriceB_.rows(); ++i) {
275 for (
Size j = 0; j < cPriceB_.columns(); ++j) {
277 "InterpolatedCPICapFloorTermPriceSurface: did not "
278 "fill call price matrix at ("
279 << i <<
"," << j <<
"), this is unexpected");
281 "InterpolatedCPICapFloorTermPriceSurface: did not "
282 "fill floor price matrix at ("
283 << i <<
"," << j <<
"), this is unexpected");
287 cfMaturityTimes_.clear();
288 for (
Size i=0; i<cfMaturities_.size();i++) {
289 cfMaturityTimes_.push_back(timeFromReference(cpiOptionDateFromTenor(cfMaturities_[i])));
292 capPrice_ = interpolator2d_.interpolate(cfMaturityTimes_.begin(),cfMaturityTimes_.end(),
293 cfStrikes_.begin(), cfStrikes_.end(),
296 capPrice_.enableExtrapolation();
298 floorPrice_ = interpolator2d_.interpolate(cfMaturityTimes_.begin(),cfMaturityTimes_.end(),
299 cfStrikes_.begin(), cfStrikes_.end(),
302 floorPrice_.enableExtrapolation();
310 Rate atm = atmRate(
d);
311 return k > atm ? capPrice(
d,k): floorPrice(
d,k);
318 Time t = timeFromReference(
d);
319 return capPrice_(
t,k);
326 Time t = timeFromReference(
d);
327 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_
virtual Rate minStrike() const
virtual Real capPrice(const Date &d, Rate k) const =0
virtual Rate baseRate() const
std::vector< Real > cfMaturityTimes_
virtual std::vector< Period > maturities() const
virtual Period observationLag() const
Rate atmRate(Date maturity) const
virtual Date baseDate() 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 Frequency frequency() 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
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.
Basic term-structure functionality.
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Frequency
Frequency of events.
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
base classes for inflation indexes
Base classes for inflation term structures.
abstract base classes for 2-D interpolations
base class for 1-D interpolations
bool close(const Quantity &m1, const Quantity &m2, Size n)
bool close_enough(const Quantity &m1, const Quantity &m2, Size n)
polynomial interpolation in the y-direction, spline interpolation x-direction
InterpolationType
when you observe an index, how do you interpolate between fixings?