From 64e79c50e4ae878d743b431ef05a24cc3c40b48f Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Mon, 23 Sep 2024 14:44:56 +0200 Subject: [PATCH] Deprecate indexIsInterpolated parameter in YoY curves --- .../inflation/yoycapfloortermpricesurface.hpp | 5 +- .../interpolatedyoyinflationcurve.hpp | 68 +++++++++++++++++-- .../inflation/piecewiseyoyinflationcurve.hpp | 29 +++++++- ql/termstructures/inflationtermstructure.cpp | 30 ++++++++ ql/termstructures/inflationtermstructure.hpp | 48 ++++++++++--- test-suite/inflation.cpp | 3 +- test-suite/inflationcapfloor.cpp | 3 +- test-suite/inflationcapflooredcoupon.cpp | 3 +- test-suite/inflationvolatility.cpp | 19 +++--- 9 files changed, 172 insertions(+), 36 deletions(-) diff --git a/ql/experimental/inflation/yoycapfloortermpricesurface.hpp b/ql/experimental/inflation/yoycapfloortermpricesurface.hpp index 92aa0a5f66c..820bde7df8d 100644 --- a/ql/experimental/inflation/yoycapfloortermpricesurface.hpp +++ b/ql/experimental/inflation/yoycapfloortermpricesurface.hpp @@ -606,8 +606,6 @@ namespace QuantLib { } Date baseDate = - yoyIndex()->interpolated() ? - nominalTS_->referenceDate() - observationLag() : inflationPeriod(nominalTS_->referenceDate() - observationLag(), yoyIndex()->frequency()).first; // usually this base rate is known @@ -619,8 +617,7 @@ namespace QuantLib { auto pYITS = ext::make_shared>( nominalTS_->referenceDate(), baseDate, baseYoYRate, - yoyIndex()->frequency(), yoyIndex()->interpolated(), - dayCounter(), YYhelpers); + yoyIndex()->frequency(), dayCounter(), YYhelpers); pYITS->recalculate(); yoy_ = pYITS; // store diff --git a/ql/termstructures/inflation/interpolatedyoyinflationcurve.hpp b/ql/termstructures/inflation/interpolatedyoyinflationcurve.hpp index 1d97ace3b8e..0b5d6ca2ed5 100644 --- a/ql/termstructures/inflation/interpolatedyoyinflationcurve.hpp +++ b/ql/termstructures/inflation/interpolatedyoyinflationcurve.hpp @@ -44,6 +44,18 @@ namespace QuantLib { : public YoYInflationTermStructure, protected InterpolatedCurve { public: + InterpolatedYoYInflationCurve(const Date& referenceDate, + std::vector dates, + const std::vector& rates, + Frequency frequency, + const DayCounter& dayCounter, + const ext::shared_ptr& seasonality = {}, + const Interpolator& interpolator = Interpolator()); + + /*! \deprecated Use the overload without indexIsInterpolated. + Deprecated in version 1.36. + */ + [[deprecated("Use the overload without indexIsInterpolated")]] InterpolatedYoYInflationCurve(const Date& referenceDate, std::vector dates, const std::vector& rates, @@ -53,11 +65,11 @@ namespace QuantLib { const ext::shared_ptr& seasonality = {}, const Interpolator& interpolator = Interpolator()); - /*! \deprecated Use the other overload and pass the base date directly - as the first date in the vector instead of using a lag. + /*! \deprecated Use the overload without lag and indexIsInterpolated and + pass the base date as the first date in the vector. Deprecated in version 1.34. */ - QL_DEPRECATED + [[deprecated("Use the overload without lag and indexIsInterpolated and pass the base date as the first date in the vector")]] InterpolatedYoYInflationCurve(const Date& referenceDate, const Calendar& calendar, const DayCounter& dayCounter, @@ -94,6 +106,18 @@ namespace QuantLib { (or can't) provide the points for interpolation on construction. */ + InterpolatedYoYInflationCurve(const Date& referenceDate, + Date baseDate, + Rate baseYoYRate, + Frequency frequency, + const DayCounter& dayCounter, + const ext::shared_ptr& seasonality = {}, + const Interpolator& interpolator = Interpolator()); + + /*! \deprecated Use the overload without indexIsInterpolated. + Deprecated in version 1.36. + */ + [[deprecated("Use the overload without indexIsInterpolated")]] InterpolatedYoYInflationCurve(const Date& referenceDate, Date baseDate, Rate baseYoYRate, @@ -103,11 +127,11 @@ namespace QuantLib { const ext::shared_ptr& seasonality = {}, const Interpolator& interpolator = Interpolator()); - /*! \deprecated Use the other overload and pass the base date directly - instead of using a lag. + /*! \deprecated Use the overload without lag and indexIsInterpolated and + pass the base date as the first date in the vector. Deprecated in version 1.34. */ - QL_DEPRECATED + [[deprecated("Use the overload without lag and indexIsInterpolated and pass the base date as the first date in the vector")]] InterpolatedYoYInflationCurve(const Date& referenceDate, const Calendar& calendar, const DayCounter& dayCounter, @@ -124,6 +148,22 @@ namespace QuantLib { // template definitions + QL_DEPRECATED_DISABLE_WARNING + + template + InterpolatedYoYInflationCurve::InterpolatedYoYInflationCurve( + const Date& referenceDate, + std::vector dates, + const std::vector& rates, + Frequency frequency, + const DayCounter& dayCounter, + const ext::shared_ptr& seasonality, + const Interpolator& interpolator) + : InterpolatedYoYInflationCurve(referenceDate, dates, rates, frequency, + false, dayCounter, seasonality, interpolator) {} + + QL_DEPRECATED_ENABLE_WARNING + template InterpolatedYoYInflationCurve::InterpolatedYoYInflationCurve( const Date& referenceDate, @@ -157,6 +197,22 @@ namespace QuantLib { this->interpolation_.update(); } + QL_DEPRECATED_DISABLE_WARNING + + template + InterpolatedYoYInflationCurve:: + InterpolatedYoYInflationCurve(const Date& referenceDate, + Date baseDate, + Rate baseYoYRate, + Frequency frequency, + const DayCounter& dayCounter, + const ext::shared_ptr& seasonality, + const Interpolator& interpolator) + : InterpolatedYoYInflationCurve(referenceDate, baseDate, baseYoYRate, frequency, + false, dayCounter, seasonality, interpolator) {} + + QL_DEPRECATED_ENABLE_WARNING + template InterpolatedYoYInflationCurve:: InterpolatedYoYInflationCurve(const Date& referenceDate, diff --git a/ql/termstructures/inflation/piecewiseyoyinflationcurve.hpp b/ql/termstructures/inflation/piecewiseyoyinflationcurve.hpp index 2d0d1c30332..d1852861202 100644 --- a/ql/termstructures/inflation/piecewiseyoyinflationcurve.hpp +++ b/ql/termstructures/inflation/piecewiseyoyinflationcurve.hpp @@ -47,8 +47,31 @@ namespace QuantLib { public: typedef Traits traits_type; typedef Interpolator interpolator_type; + //! \name Constructors //@{ + + QL_DEPRECATED_DISABLE_WARNING + + PiecewiseYoYInflationCurve( + const Date& referenceDate, + Date baseDate, + Rate baseYoYRate, + Frequency frequency, + const DayCounter& dayCounter, + std::vector > instruments, + const ext::shared_ptr& seasonality = {}, + Real accuracy = 1.0e-12, + const Interpolator& i = Interpolator()) + : PiecewiseYoYInflationCurve(referenceDate, baseDate, baseYoYRate, frequency, false, + dayCounter, instruments, seasonality, accuracy, i) {} + + QL_DEPRECATED_ENABLE_WARNING + + /*! \deprecated Use the overload without indexIsInterpolated. + Deprecated in version 1.36. + */ + [[deprecated("Use the overload without indexIsInterpolated")]] PiecewiseYoYInflationCurve( const Date& referenceDate, Date baseDate, @@ -75,11 +98,11 @@ namespace QuantLib { QL_DEPRECATED_DISABLE_WARNING - /*! \deprecated Use the other overload and pass the base date directly - instead of using a lag. + /*! \deprecated Use the overload without lag and indexIsInterpolated and + pass the base date as the first date in the vector. Deprecated in version 1.34. */ - QL_DEPRECATED + [[deprecated("Use the overload without lag and indexIsInterpolated and pass the base date as the first date in the vector")]] PiecewiseYoYInflationCurve( const Date& referenceDate, const Calendar& calendar, diff --git a/ql/termstructures/inflationtermstructure.cpp b/ql/termstructures/inflationtermstructure.cpp index 32fe6d37dac..6b4e59859e0 100644 --- a/ql/termstructures/inflationtermstructure.cpp +++ b/ql/termstructures/inflationtermstructure.cpp @@ -262,6 +262,36 @@ namespace QuantLib { return zeroRateImpl(t); } + QL_DEPRECATED_DISABLE_WARNING + + YoYInflationTermStructure::YoYInflationTermStructure( + Date baseDate, + Rate baseYoYRate, + Frequency frequency, + const DayCounter& dayCounter, + const ext::shared_ptr &seasonality) + : YoYInflationTermStructure(baseDate, baseYoYRate, frequency, false, dayCounter, seasonality) {} + + YoYInflationTermStructure::YoYInflationTermStructure( + const Date& referenceDate, + Date baseDate, + Rate baseYoYRate, + Frequency frequency, + const DayCounter& dayCounter, + const ext::shared_ptr &seasonality) + : YoYInflationTermStructure(referenceDate, baseDate, baseYoYRate, frequency, false, dayCounter, seasonality) {} + + YoYInflationTermStructure::YoYInflationTermStructure( + Natural settlementDays, + const Calendar& calendar, + Date baseDate, + Rate baseYoYRate, + Frequency frequency, + const DayCounter& dayCounter, + const ext::shared_ptr &seasonality) + : YoYInflationTermStructure(settlementDays, calendar, baseDate, baseYoYRate, frequency, false, dayCounter, seasonality) {} + + QL_DEPRECATED_ENABLE_WARNING YoYInflationTermStructure::YoYInflationTermStructure( Date baseDate, diff --git a/ql/termstructures/inflationtermstructure.hpp b/ql/termstructures/inflationtermstructure.hpp index 2fdd97dad17..6cdadd13301 100644 --- a/ql/termstructures/inflationtermstructure.hpp +++ b/ql/termstructures/inflationtermstructure.hpp @@ -251,6 +251,31 @@ namespace QuantLib { public: //! \name Constructors //@{ + YoYInflationTermStructure(Date baseDate, + Rate baseYoYRate, + Frequency frequency, + const DayCounter& dayCounter, + const ext::shared_ptr& seasonality = {}); + + YoYInflationTermStructure(const Date& referenceDate, + Date baseDate, + Rate baseYoYRate, + Frequency frequency, + const DayCounter& dayCounter, + const ext::shared_ptr& seasonality = {}); + + YoYInflationTermStructure(Natural settlementDays, + const Calendar& calendar, + Date baseDate, + Rate baseYoYRate, + Frequency frequency, + const DayCounter& dayCounter, + const ext::shared_ptr& seasonality = {}); + + /*! \deprecated Use an overload with an explicit base date and without indexIsInterpolated. + Deprecated in version 1.36. + */ + [[deprecated("Use an overload with an explicit base date and without indexIsInterpolated")]] YoYInflationTermStructure(Date baseDate, Rate baseYoYRate, Frequency frequency, @@ -258,6 +283,10 @@ namespace QuantLib { const DayCounter& dayCounter, const ext::shared_ptr& seasonality = {}); + /*! \deprecated Use an overload with an explicit base date and without indexIsInterpolated. + Deprecated in version 1.36. + */ + [[deprecated("Use an overload with an explicit base date and without indexIsInterpolated")]] YoYInflationTermStructure(const Date& referenceDate, Date baseDate, Rate baseYoYRate, @@ -266,6 +295,10 @@ namespace QuantLib { const DayCounter& dayCounter, const ext::shared_ptr& seasonality = {}); + /*! \deprecated Use an overload with an explicit base date and without indexIsInterpolated. + Deprecated in version 1.36. + */ + [[deprecated("Use an overload with an explicit base date and without indexIsInterpolated")]] YoYInflationTermStructure(Natural settlementDays, const Calendar& calendar, Date baseDate, @@ -275,11 +308,10 @@ namespace QuantLib { const DayCounter& dayCounter, const ext::shared_ptr& seasonality = {}); - /*! \deprecated Use another overload and pass the base date directly - instead of using a lag. + /*! \deprecated Use an overload with an explicit base date and without indexIsInterpolated. Deprecated in version 1.34. */ - QL_DEPRECATED + [[deprecated("Use an overload with an explicit base date and without indexIsInterpolated")]] YoYInflationTermStructure(const DayCounter& dayCounter, Rate baseYoYRate, const Period& lag, @@ -287,11 +319,10 @@ namespace QuantLib { bool indexIsInterpolated, const ext::shared_ptr& seasonality = {}); - /*! \deprecated Use another overload and pass the base date directly - instead of using a lag. + /*! \deprecated Use an overload with an explicit base date and without indexIsInterpolated. Deprecated in version 1.34. */ - QL_DEPRECATED + [[deprecated("Use an overload with an explicit base date and without indexIsInterpolated")]] YoYInflationTermStructure(const Date& referenceDate, const Calendar& calendar, const DayCounter& dayCounter, @@ -301,11 +332,10 @@ namespace QuantLib { bool indexIsInterpolated, const ext::shared_ptr& seasonality = {}); - /*! \deprecated Use another overload and pass the base date directly - instead of using a lag. + /*! \deprecated Use an overload with an explicit base date and without indexIsInterpolated. Deprecated in version 1.34. */ - QL_DEPRECATED + [[deprecated("Use an overload with an explicit base date and without indexIsInterpolated")]] YoYInflationTermStructure(Natural settlementDays, const Calendar& calendar, const DayCounter& dayCounter, diff --git a/test-suite/inflation.cpp b/test-suite/inflation.cpp index eef4dca9b89..65372c74fb1 100644 --- a/test-suite/inflation.cpp +++ b/test-suite/inflation.cpp @@ -1145,8 +1145,7 @@ BOOST_AUTO_TEST_CASE(testYYTermStructure) { auto pYYTS = ext::make_shared>( evaluationDate, baseDate, baseYYRate, - iir->frequency(),iir->interpolated(), dc, - helpers); + iir->frequency(), dc, helpers); // validation // yoy swaps should reprice to zero diff --git a/test-suite/inflationcapfloor.cpp b/test-suite/inflationcapfloor.cpp index 20434d196ff..c980a031517 100644 --- a/test-suite/inflationcapfloor.cpp +++ b/test-suite/inflationcapfloor.cpp @@ -180,8 +180,7 @@ struct CommonVars { Rate baseYYRate = yyData[0].rate/100.0; auto pYYTS = ext::make_shared>( - evaluationDate, baseDate, baseYYRate, iir->frequency(), - iir->interpolated(), dc, helpers); + evaluationDate, baseDate, baseYYRate, iir->frequency(), dc, helpers); yoyTS = ext::dynamic_pointer_cast(pYYTS); // make sure that the index has the latest yoy term structure diff --git a/test-suite/inflationcapflooredcoupon.cpp b/test-suite/inflationcapflooredcoupon.cpp index bcd0a742a21..3728b3e8bd3 100644 --- a/test-suite/inflationcapflooredcoupon.cpp +++ b/test-suite/inflationcapflooredcoupon.cpp @@ -188,8 +188,7 @@ struct CommonVars { Rate baseYYRate = yyData[0].rate/100.0; auto pYYTS = ext::make_shared>( - evaluationDate, baseDate, baseYYRate, iir->frequency(), - iir->interpolated(), dc, helpers); + evaluationDate, baseDate, baseYYRate, iir->frequency(), dc, helpers); yoyTS = ext::dynamic_pointer_cast(pYYTS); // make sure that the index has the latest yoy term structure diff --git a/test-suite/inflationvolatility.cpp b/test-suite/inflationvolatility.cpp index 19a57636b73..5e9daa5f612 100644 --- a/test-suite/inflationvolatility.cpp +++ b/test-suite/inflationvolatility.cpp @@ -171,19 +171,22 @@ void setup() { d.clear(); r.clear(); - Date baseDate = TARGET().advance(eval, -2, Months, ModifiedFollowing); - for (Size i = 0; i < std::size(yoyEUrates); i++) { - Date dd = TARGET().advance(baseDate, i, Years, ModifiedFollowing); + // the base date is based on the last published index fixing + Date baseDate = inflationPeriod(eval - 1*Months, yoyIndexEU->frequency()).first; + d.push_back(baseDate); + r.push_back(yoyEUrates[0]); + + // cap maturities are based on the observation lag + Date capStartDate = TARGET().advance(eval, -2, Months, ModifiedFollowing); + for (Size i = 1; i < std::size(yoyEUrates); i++) { + Date dd = TARGET().advance(capStartDate, i, Years, ModifiedFollowing); d.push_back(dd); r.push_back(yoyEUrates[i]); } - bool indexIsInterpolated = true; // actually false for UKRPI but smooth surfaces are - // better for finding intersections etc - auto pYTSEU = ext::make_shared>( - eval, d, r, Monthly, indexIsInterpolated, Actual365Fixed()); + eval, d, r, Monthly, Actual365Fixed()); yoyEU.linkTo(pYTSEU); // price data @@ -364,7 +367,7 @@ BOOST_AUTO_TEST_CASE(testYoYPriceSurfaceToATM) { 0.0258498, 0.0262883, 0.0267915}; const Real swaps[] = {0.024586, 0.0247575, 0.0249396, 0.0252596, 0.0258498, 0.0262883, 0.0267915}; - const Real ayoy[] = {0.0247659, 0.0251437, 0.0255945, 0.0265234, + const Real ayoy[] = {0.0247659, 0.0251437, 0.0255945, 0.0265015, 0.0280457, 0.0285534, 0.0295884}; Real eps = 2e-5; for(Size i = 0; i < yyATMt.first.size(); i++) {