25#ifndef quantlib_yoy_capfloor_term_price_surface_hpp
26#define quantlib_yoy_capfloor_term_price_surface_hpp
28#include <ql/indexes/inflationindex.hpp>
29#include <ql/termstructures/inflation/piecewiseyoyinflationcurve.hpp>
30#include <ql/termstructures/inflation/inflationhelpers.hpp>
31#include <ql/experimental/inflation/polynomial2Dspline.hpp>
46 const ext::shared_ptr<YoYInflationIndex>& yii,
52 const std::vector<Rate>& cStrikes,
53 const std::vector<Rate>& fStrikes,
54 const std::vector<Period>& cfMaturities,
62 virtual std::pair<std::vector<Time>, std::vector<Rate> >
64 virtual std::pair<std::vector<Date>, std::vector<Rate> >
68 virtual ext::shared_ptr<YoYInflationTermStructure>
YoYTS()
const = 0;
86 bool extrapolate =
true)
const = 0;
89 bool extrapolate =
true)
const = 0;
95 bool extrapolate =
true)
const;
98 bool extrapolate =
true)
const;
138 mutable ext::shared_ptr<YoYInflationTermStructure>
yoy_;
144 template<
class Interpolator2D,
class Interpolator1D>
151 const ext::shared_ptr<YoYInflationIndex>& yii,
157 const std::vector<Rate> &cStrikes,
158 const std::vector<Rate> &fStrikes,
159 const std::vector<Period> &cfMaturities,
162 const Interpolator2D &interpolator2d = Interpolator2D(),
180 ext::shared_ptr<YoYInflationTermStructure>
YoYTS()
const override {
return yoy_; }
189 bool extrapolate =
true)
const override {
193 return yoy_->yoyRate(d, obsLag,
false, extrapolate);
241 template<
class I2D,
class I1D>
246 const ext::shared_ptr<YoYInflationIndex>& yii,
252 const std::vector<Rate> &cStrikes,
253 const std::vector<Rate> &fStrikes,
254 const std::vector<Period> &cfMaturities,
257 const I2D &interpolator2d,
258 const I1D &interpolator1d)
260 baseRate, nominal, dc, cal, bdc,
261 cStrikes, fStrikes, cfMaturities,
263 interpolator2d_(interpolator2d), interpolator1d_(interpolator1d) {
264 performCalculations();
269 template<
class I2D,
class I1D>
276 template<
class I2D,
class I1D>
285 calculateYoYTermStructure();
289 template<
class I2D,
class I1D>
294 : t_(t), a_(a), b_(b) {
299 template<
class I2D,
class I1D>
307 template<
class I2D,
class I1D>
315 template<
class I2D,
class I1D>
323 template<
class I2D,
class I1D>
328 return ( a_(t_,guess,
true) - b_(t_,guess,
true) );
332 template<
class I2D,
class I1D>
338 const Real maxSearchRange = 0.0201;
339 const Real maxExtrapolationMaturity = 5.01;
340 const Real searchStep = 0.0050;
341 const Real intrinsicValueAddOn = 0.001;
370 Real solverTolerance_ = 1e-7;
374 std::vector<Time> tmpSwapMaturities;
375 std::vector<Rate> tmpSwapRates;
379 Size numYears = (
Size)std::lround(t);
380 Real sumDiscount = 0.0;
381 for (
Size j=0; j<numYears; ++j)
384 Real tmpMinSwapRateIntersection = -1.e10;
385 Real tmpMaxSwapRateIntersection = 1.e10;
389 if (minSwapRate > tmpMinSwapRateIntersection)
390 tmpMinSwapRateIntersection = minSwapRate;
395 if (maxSwapRate < tmpMaxSwapRateIntersection)
396 tmpMaxSwapRateIntersection = maxSwapRate;
398 maxSwapRateIntersection[i] = tmpMaxSwapRateIntersection;
399 minSwapRateIntersection[i] = tmpMinSwapRateIntersection;
402 bool trialsExceeded =
false;
403 int numTrials = (int)(maxSearchRange / searchStep);
409 strike =
fStrikes_.back() - counter * searchStep;
413 if (counter == numTrials + 1) {
416 trialsExceeded =
true;
421 hi = strike + searchStep;
427 strike =
fStrikes_.back() + counter * searchStep;
431 if (counter == numTrials + 1) {
434 trialsExceeded =
true;
438 lo = strike - searchStep;
445 if (!trialsExceeded) {
448 }
catch( std::exception &e) {
449 QL_FAIL(
"cap/floor intersection finding failed at t = " << t <<
", error msg: "<< e.what());
452 if (kI <= minSwapRateIntersection[i]) {
453 if (t > maxExtrapolationMaturity)
454 QL_FAIL(
"cap/floor intersection finding failed at t = " << t <<
455 ", error msg: intersection value is below the arbitrage free lower bound "
456 << minSwapRateIntersection[i]);
460 tmpSwapMaturities.push_back(t);
461 tmpSwapRates.push_back(kI);
462 validMaturity[i] =
true;
468 if (t > maxExtrapolationMaturity)
469 QL_FAIL(
"cap/floor intersection finding failed at t = " << t <<
470 ", error msg: no interection found inside the admissible range");
480 if ( !validMaturity[i] ) {
486 Real newSwapRate = minSwapRateIntersection[i] + intrinsicValueAddOn;
487 if (newSwapRate > maxSwapRateIntersection[i])
488 newSwapRate = 0.5 * (minSwapRateIntersection[i] + maxSwapRateIntersection[i]);
509 template<
class I2D,
class I1D>
517 std::vector<ext::shared_ptr<BootstrapHelper<YoYInflationTermStructure> > > YYhelpers;
518 for (
Size i=1; i<=nYears; i++) {
522 ext::shared_ptr<BootstrapHelper<YoYInflationTermStructure> >
528 YYhelpers.push_back (anInstrument);
537 ext::shared_ptr<PiecewiseYoYInflationCurve<Linear> > pYITS(
541 yoyIndex()->interpolated(), baseYoYRate,
543 pYITS->recalculate();
547 const Real eps = 1e-5;
548 for (
Size i=0; i<YYhelpers.size(); i++) {
550 QL_REQUIRE(fabs(YYhelpers[i]->impliedQuote() - original) <eps,
551 "could not reprice helper "<< i
552 <<
", data " << original
553 <<
", implied quote " << YYhelpers[i]->impliedQuote()
Shared handle to an observable.
Interface for inflation term structures.
virtual Rate baseRate() const
virtual Period observationLag() const
virtual Frequency frequency() const
const Interpolation2D & b_
Real operator()(Rate guess) const
const Interpolation2D & a_
ObjectiveFunction(Time t, const Interpolation2D &, const Interpolation2D &)
Interpolator2D interpolator2d_
Rate atmYoYRate(const Date &d, const Period &obsLag=Period(-1, Days), bool extrapolate=true) const override
std::vector< Rate > fStrikesB_
Real capPrice(const Date &d, Rate k) const override
Real floorPrice(const Date &d, Rate k) const override
std::pair< std::vector< Date >, std::vector< Rate > > atmYoYSwapDateRates() const override
void performCalculations() const
Rate atmYoYSwapRate(const Date &d, bool extrapolate=true) const override
Natural fixingDays() const override
ext::shared_ptr< YoYInflationTermStructure > YoYTS() const override
derived from yoy swap rates
Date baseDate() const override
minimum (base) date
Interpolation2D capPrice_
Rate price(const Date &d, Rate k) const override
std::pair< std::vector< Time >, std::vector< Rate > > atmYoYSwapTimeRates() const override
atm yoy swaps from put-call parity on cap/floor data
Interpolation2D floorPrice_
InterpolatedYoYCapFloorTermPriceSurface(Natural fixingDays, const Period &yyLag, const ext::shared_ptr< YoYInflationIndex > &yii, Rate baseRate, const Handle< YieldTermStructure > &nominal, const DayCounter &dc, const Calendar &cal, const BusinessDayConvention &bdc, 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(), const Interpolator1D &interpolator1d=Interpolator1D())
Interpolation2D floorPrice2_
Date maxDate() const override
inflation term structure interface
void intersect() const
intersection of cap and floor price surfaces at given strikes
void calculateYoYTermStructure() const
mess of making it, i.e. create instruments from quotes and bootstrap
std::vector< Rate > cStrikesB_
Interpolation atmYoYSwapRateCurve_
Interpolator1D interpolator1d_
base class for 2-D interpolations.
base class for 1-D interpolations.
Matrix used in linear algebra.
Piecewise year-on-year inflation term structure.
market element returning a stored value
Real solve(const F &f, Real accuracy, Real guess, Real step) const
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
virtual Calendar calendar() const
the calendar used for reference and/or option date calculation
Time timeFromReference(const Date &date) const
date/time conversion
virtual DayCounter dayCounter() const
the day counter used for date/time conversion
Year-on-year inflation-swap bootstrap helper.
Abstract base class, inheriting from InflationTermStructure.
virtual Natural fixingDays() const
virtual Real price(const Date &d, Rate k) const =0
virtual Rate maxStrike() const
virtual std::vector< Rate > strikes() const
virtual Rate atmYoYRate(const Date &d, const Period &obsLag=Period(-1, Days), bool extrapolate=true) const =0
std::vector< Rate > cfStrikes_
std::vector< Period > cfMaturities_
std::vector< Rate > fStrikes_
virtual Date minMaturity() const
Handle< YieldTermStructure > nominalTS_
virtual std::vector< Rate > floorStrikes() const
std::vector< Rate > cStrikes_
virtual ext::shared_ptr< YoYInflationTermStructure > YoYTS() const =0
derived from yoy swap rates
virtual Rate minStrike() const
virtual Real capPrice(const Date &d, Rate k) const =0
bool indexIsInterpolated() const
bool indexIsInterpolated_
ext::shared_ptr< YoYInflationIndex > yoyIndex() const
index yoy is based on
std::pair< std::vector< Time >, std::vector< Rate > > atmYoYSwapTimeRates_
virtual BusinessDayConvention businessDayConvention() const
inspectors
std::vector< Real > cfMaturityTimes_
virtual std::vector< Period > maturities() const
std::pair< std::vector< Date >, std::vector< Rate > > atmYoYSwapDateRates_
virtual bool checkStrike(Rate K)
BusinessDayConvention bdc_
virtual Rate atmYoYSwapRate(const Date &d, bool extrapolate=true) const =0
virtual Date maxMaturity() const
ext::shared_ptr< YoYInflationTermStructure > yoy_
virtual bool checkMaturity(const Date &d)
virtual Real floorPrice(const Date &d, Rate k) const =0
virtual std::pair< std::vector< Date >, std::vector< Rate > > atmYoYSwapDateRates() const =0
virtual std::vector< Rate > capStrikes() const
ext::shared_ptr< YoYInflationIndex > yoyIndex_
virtual std::pair< std::vector< Time >, std::vector< Rate > > atmYoYSwapTimeRates() const =0
atm yoy swaps from put-call parity on cap/floor data
virtual Date yoyOptionDateFromTenor(const Period &p) const
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
unsigned QL_INTEGER Natural
positive integer
std::size_t Size
size of a container