25#ifndef quantlib_yoy_capfloor_term_price_surface_hpp
26#define quantlib_yoy_capfloor_term_price_surface_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,
61 [[deprecated(
"Use the overload that passes an interpolation type instead")]]
64 const ext::shared_ptr<YoYInflationIndex>& yii,
70 const std::vector<Rate>& cStrikes,
71 const std::vector<Rate>& fStrikes,
72 const std::vector<Period>& cfMaturities,
82 virtual std::pair<std::vector<Time>, std::vector<Rate> >
84 virtual std::pair<std::vector<Date>, std::vector<Rate> >
88 virtual ext::shared_ptr<YoYInflationTermStructure>
YoYTS()
const = 0;
107 bool extrapolate =
true)
const = 0;
110 bool extrapolate =
true)
const = 0;
116 bool extrapolate =
true)
const;
119 bool extrapolate =
true)
const;
160 mutable ext::shared_ptr<YoYInflationTermStructure>
yoy_;
166 template<
class Interpolator2D,
class Interpolator1D>
173 const ext::shared_ptr<YoYInflationIndex>& yii,
179 const std::vector<Rate> &cStrikes,
180 const std::vector<Rate> &fStrikes,
181 const std::vector<Period> &cfMaturities,
184 const Interpolator2D &interpolator2d = Interpolator2D(),
190 [[deprecated(
"Use the overload that passes an interpolation type instead")]]
194 const ext::shared_ptr<YoYInflationIndex>& yii,
200 const std::vector<Rate> &cStrikes,
201 const std::vector<Rate> &fStrikes,
202 const std::vector<Period> &cfMaturities,
205 const Interpolator2D &interpolator2d = Interpolator2D(),
223 ext::shared_ptr<YoYInflationTermStructure>
YoYTS()
const override {
return yoy_; }
232 bool extrapolate =
true)
const override {
237 return yoy_->yoyRate(
d, p,
false, extrapolate);
293 template<
class I2D,
class I1D>
298 const ext::shared_ptr<YoYInflationIndex>& yii,
304 const std::vector<Rate> &cStrikes,
305 const std::vector<Rate> &fStrikes,
306 const std::vector<Period> &cfMaturities,
309 const I2D &interpolator2d,
310 const I1D &interpolator1d)
312 interpolation, nominal, dc, cal, bdc,
313 cStrikes, fStrikes, cfMaturities,
315 interpolator2d_(interpolator2d), interpolator1d_(interpolator1d) {
316 performCalculations();
319 template<
class I2D,
class I1D>
324 const ext::shared_ptr<YoYInflationIndex>& yii,
326 const Handle<YieldTermStructure> &nominal,
327 const DayCounter &dc,
330 const std::vector<Rate> &cStrikes,
331 const std::vector<Rate> &fStrikes,
332 const std::vector<Period> &cfMaturities,
333 const Matrix &cPrice,
334 const Matrix &fPrice,
335 const I2D &interpolator2d,
336 const I1D &interpolator1d)
337 : InterpolatedYoYCapFloorTermPriceSurface(fixingDays, yyLag, yii, CPI::AsIndex,
338 nominal, dc, cal, bdc,
339 cStrikes, fStrikes, cfMaturities,
341 interpolator2d, interpolator1d) {}
345 template<
class I2D,
class I1D>
352 template<
class I2D,
class I1D>
361 calculateYoYTermStructure();
365 template<
class I2D,
class I1D>
375 template<
class I2D,
class I1D>
383 template<
class I2D,
class I1D>
391 template<
class I2D,
class I1D>
399 template<
class I2D,
class I1D>
404 return (
a_(
t_,guess,
true) -
b_(
t_,guess,
true) );
408 template<
class I2D,
class I1D>
414 const Real maxSearchRange = 0.0201;
415 const Real maxExtrapolationMaturity = 5.01;
416 const Real searchStep = 0.0050;
417 const Real intrinsicValueAddOn = 0.001;
446 Real solverTolerance_ = 1e-7;
450 std::vector<Time> tmpSwapMaturities;
451 std::vector<Rate> tmpSwapRates;
456 Real sumDiscount = 0.0;
457 for (
Size j=0; j<numYears; ++j)
460 Real tmpMinSwapRateIntersection = -1.e10;
461 Real tmpMaxSwapRateIntersection = 1.e10;
465 if (minSwapRate > tmpMinSwapRateIntersection)
466 tmpMinSwapRateIntersection = minSwapRate;
471 if (maxSwapRate < tmpMaxSwapRateIntersection)
472 tmpMaxSwapRateIntersection = maxSwapRate;
474 maxSwapRateIntersection[i] = tmpMaxSwapRateIntersection;
475 minSwapRateIntersection[i] = tmpMinSwapRateIntersection;
478 bool trialsExceeded =
false;
479 int numTrials = (int)(maxSearchRange / searchStep);
485 strike =
fStrikes_.back() - counter * searchStep;
489 if (counter == numTrials + 1) {
492 trialsExceeded =
true;
497 hi = strike + searchStep;
503 strike =
fStrikes_.back() + counter * searchStep;
507 if (counter == numTrials + 1) {
510 trialsExceeded =
true;
514 lo = strike - searchStep;
521 if (!trialsExceeded) {
524 }
catch( std::exception &e) {
525 QL_FAIL(
"cap/floor intersection finding failed at t = " <<
t <<
", error msg: "<< e.what());
528 if (kI <= minSwapRateIntersection[i]) {
529 if (
t > maxExtrapolationMaturity)
530 QL_FAIL(
"cap/floor intersection finding failed at t = " <<
t <<
531 ", error msg: intersection value is below the arbitrage free lower bound "
532 << minSwapRateIntersection[i]);
536 tmpSwapMaturities.push_back(
t);
537 tmpSwapRates.push_back(kI);
538 validMaturity[i] =
true;
544 if (
t > maxExtrapolationMaturity)
545 QL_FAIL(
"cap/floor intersection finding failed at t = " <<
t <<
546 ", error msg: no interection found inside the admissible range");
556 if ( !validMaturity[i] ) {
562 Real newSwapRate = minSwapRateIntersection[i] + intrinsicValueAddOn;
563 if (newSwapRate > maxSwapRateIntersection[i])
564 newSwapRate = 0.5 * (minSwapRateIntersection[i] + maxSwapRateIntersection[i]);
585 template<
class I2D,
class I1D>
593 std::vector<ext::shared_ptr<BootstrapHelper<YoYInflationTermStructure> > > YYhelpers;
594 for (
Size i=1; i<=nYears; i++) {
599 ext::make_shared<YearOnYearInflationSwapHelper>(
605 YYhelpers.push_back (anInstrument);
618 ext::make_shared<PiecewiseYoYInflationCurve<Linear>>(
621 pYITS->recalculate();
625 const Real eps = 1e-5;
626 for (
Size i=0; i<YYhelpers.size(); i++) {
628 QL_REQUIRE(fabs(YYhelpers[i]->impliedQuote() - original) <eps,
629 "could not reprice helper "<< i
630 <<
", data " << original
631 <<
", implied quote " << YYhelpers[i]->impliedQuote()
Shared handle to an observable.
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
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
InterpolatedYoYCapFloorTermPriceSurface(Natural fixingDays, const Period &yyLag, const ext::shared_ptr< YoYInflationIndex > &yii, CPI::InterpolationType interpolation, 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())
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.
market element returning a stored value
Real solve(const F &f, Real accuracy, Real guess, Real step) const
Basic term-structure functionality.
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
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 Period observationLag() const
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 Frequency frequency() const
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
virtual Date baseDate() const =0
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
std::function< Real(Real)> b
Frequency
Frequency of events.
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
Bootstrap helpers for inflation term structures.
base classes for inflation indexes
std::pair< Date, Date > inflationPeriod(const Date &d, Frequency frequency)
utility function giving the inflation period for a given date
Piecewise year-on-year inflation term structure.
polynomial interpolation in the y-direction, spline interpolation x-direction
InterpolationType
when you observe an index, how do you interpolate between fixings?
@ Linear
linearly between bracketing fixings
@ Flat
flat from previous fixing