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,
64 virtual std::pair<std::vector<Time>, std::vector<Rate> >
66 virtual std::pair<std::vector<Date>, std::vector<Rate> >
70 virtual ext::shared_ptr<YoYInflationTermStructure>
YoYTS()
const = 0;
89 bool extrapolate =
true)
const = 0;
92 bool extrapolate =
true)
const = 0;
98 bool extrapolate =
true)
const;
101 bool extrapolate =
true)
const;
142 mutable ext::shared_ptr<YoYInflationTermStructure>
yoy_;
148 template<
class Interpolator2D,
class Interpolator1D>
155 const ext::shared_ptr<YoYInflationIndex>& yii,
161 const std::vector<Rate> &cStrikes,
162 const std::vector<Rate> &fStrikes,
163 const std::vector<Period> &cfMaturities,
166 const Interpolator2D &interpolator2d = Interpolator2D(),
184 ext::shared_ptr<YoYInflationTermStructure>
YoYTS()
const override {
return yoy_; }
193 bool extrapolate =
true)
const override {
198 return yoy_->yoyRate(
d, p,
false, extrapolate);
254 template<
class I2D,
class I1D>
259 const ext::shared_ptr<YoYInflationIndex>& yii,
265 const std::vector<Rate> &cStrikes,
266 const std::vector<Rate> &fStrikes,
267 const std::vector<Period> &cfMaturities,
270 const I2D &interpolator2d,
271 const I1D &interpolator1d)
273 baseRate, nominal, dc, cal, bdc,
274 cStrikes, fStrikes, cfMaturities,
276 interpolator2d_(interpolator2d), interpolator1d_(interpolator1d) {
277 performCalculations();
282 template<
class I2D,
class I1D>
289 template<
class I2D,
class I1D>
298 calculateYoYTermStructure();
302 template<
class I2D,
class I1D>
312 template<
class I2D,
class I1D>
320 template<
class I2D,
class I1D>
328 template<
class I2D,
class I1D>
336 template<
class I2D,
class I1D>
341 return (
a_(
t_,guess,
true) -
b_(
t_,guess,
true) );
345 template<
class I2D,
class I1D>
351 const Real maxSearchRange = 0.0201;
352 const Real maxExtrapolationMaturity = 5.01;
353 const Real searchStep = 0.0050;
354 const Real intrinsicValueAddOn = 0.001;
383 Real solverTolerance_ = 1e-7;
387 std::vector<Time> tmpSwapMaturities;
388 std::vector<Rate> tmpSwapRates;
393 Real sumDiscount = 0.0;
394 for (
Size j=0; j<numYears; ++j)
397 Real tmpMinSwapRateIntersection = -1.e10;
398 Real tmpMaxSwapRateIntersection = 1.e10;
402 if (minSwapRate > tmpMinSwapRateIntersection)
403 tmpMinSwapRateIntersection = minSwapRate;
408 if (maxSwapRate < tmpMaxSwapRateIntersection)
409 tmpMaxSwapRateIntersection = maxSwapRate;
411 maxSwapRateIntersection[i] = tmpMaxSwapRateIntersection;
412 minSwapRateIntersection[i] = tmpMinSwapRateIntersection;
415 bool trialsExceeded =
false;
416 int numTrials = (int)(maxSearchRange / searchStep);
422 strike =
fStrikes_.back() - counter * searchStep;
426 if (counter == numTrials + 1) {
429 trialsExceeded =
true;
434 hi = strike + searchStep;
440 strike =
fStrikes_.back() + counter * searchStep;
444 if (counter == numTrials + 1) {
447 trialsExceeded =
true;
451 lo = strike - searchStep;
458 if (!trialsExceeded) {
461 }
catch( std::exception &e) {
462 QL_FAIL(
"cap/floor intersection finding failed at t = " <<
t <<
", error msg: "<< e.what());
465 if (kI <= minSwapRateIntersection[i]) {
466 if (
t > maxExtrapolationMaturity)
467 QL_FAIL(
"cap/floor intersection finding failed at t = " <<
t <<
468 ", error msg: intersection value is below the arbitrage free lower bound "
469 << minSwapRateIntersection[i]);
473 tmpSwapMaturities.push_back(
t);
474 tmpSwapRates.push_back(kI);
475 validMaturity[i] =
true;
481 if (
t > maxExtrapolationMaturity)
482 QL_FAIL(
"cap/floor intersection finding failed at t = " <<
t <<
483 ", error msg: no interection found inside the admissible range");
493 if ( !validMaturity[i] ) {
499 Real newSwapRate = minSwapRateIntersection[i] + intrinsicValueAddOn;
500 if (newSwapRate > maxSwapRateIntersection[i])
501 newSwapRate = 0.5 * (minSwapRateIntersection[i] + maxSwapRateIntersection[i]);
522 template<
class I2D,
class I1D>
530 std::vector<ext::shared_ptr<BootstrapHelper<YoYInflationTermStructure> > > YYhelpers;
531 for (
Size i=1; i<=nYears; i++) {
535 ext::shared_ptr<BootstrapHelper<YoYInflationTermStructure> >
541 YYhelpers.push_back (anInstrument);
556 ext::make_shared<PiecewiseYoYInflationCurve<Linear>>(
560 pYITS->recalculate();
564 const Real eps = 1e-5;
565 for (
Size i=0; i<YYhelpers.size(); i++) {
567 QL_REQUIRE(fabs(YYhelpers[i]->impliedQuote() - original) <eps,
568 "could not reprice helper "<< i
569 <<
", data " << original
570 <<
", 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
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
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 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)
ext::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