Skip to content

Commit

Permalink
Deprecate indexIsInterpolated parameter in YoY curves
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Oct 17, 2024
1 parent 065e2c7 commit 64e79c5
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 36 deletions.
5 changes: 1 addition & 4 deletions ql/experimental/inflation/yoycapfloortermpricesurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -619,8 +617,7 @@ namespace QuantLib {
auto pYITS =
ext::make_shared<PiecewiseYoYInflationCurve<Linear>>(
nominalTS_->referenceDate(), baseDate, baseYoYRate,
yoyIndex()->frequency(), yoyIndex()->interpolated(),
dayCounter(), YYhelpers);
yoyIndex()->frequency(), dayCounter(), YYhelpers);
pYITS->recalculate();
yoy_ = pYITS; // store

Expand Down
68 changes: 62 additions & 6 deletions ql/termstructures/inflation/interpolatedyoyinflationcurve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ namespace QuantLib {
: public YoYInflationTermStructure,
protected InterpolatedCurve<Interpolator> {
public:
InterpolatedYoYInflationCurve(const Date& referenceDate,
std::vector<Date> dates,
const std::vector<Rate>& rates,
Frequency frequency,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& 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<Date> dates,
const std::vector<Rate>& rates,
Expand All @@ -53,11 +65,11 @@ namespace QuantLib {
const ext::shared_ptr<Seasonality>& 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,
Expand Down Expand Up @@ -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>& 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,
Expand All @@ -103,11 +127,11 @@ namespace QuantLib {
const ext::shared_ptr<Seasonality>& 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,
Expand All @@ -124,6 +148,22 @@ namespace QuantLib {

// template definitions

QL_DEPRECATED_DISABLE_WARNING

template <class Interpolator>
InterpolatedYoYInflationCurve<Interpolator>::InterpolatedYoYInflationCurve(
const Date& referenceDate,
std::vector<Date> dates,
const std::vector<Rate>& rates,
Frequency frequency,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& seasonality,
const Interpolator& interpolator)
: InterpolatedYoYInflationCurve(referenceDate, dates, rates, frequency,
false, dayCounter, seasonality, interpolator) {}

QL_DEPRECATED_ENABLE_WARNING

template <class Interpolator>
InterpolatedYoYInflationCurve<Interpolator>::InterpolatedYoYInflationCurve(
const Date& referenceDate,
Expand Down Expand Up @@ -157,6 +197,22 @@ namespace QuantLib {
this->interpolation_.update();
}

QL_DEPRECATED_DISABLE_WARNING

template <class Interpolator>
InterpolatedYoYInflationCurve<Interpolator>::
InterpolatedYoYInflationCurve(const Date& referenceDate,
Date baseDate,
Rate baseYoYRate,
Frequency frequency,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& seasonality,
const Interpolator& interpolator)
: InterpolatedYoYInflationCurve(referenceDate, baseDate, baseYoYRate, frequency,
false, dayCounter, seasonality, interpolator) {}

QL_DEPRECATED_ENABLE_WARNING

template <class Interpolator>
InterpolatedYoYInflationCurve<Interpolator>::
InterpolatedYoYInflationCurve(const Date& referenceDate,
Expand Down
29 changes: 26 additions & 3 deletions ql/termstructures/inflation/piecewiseyoyinflationcurve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ext::shared_ptr<typename Traits::helper> > instruments,
const ext::shared_ptr<Seasonality>& 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,
Expand All @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions ql/termstructures/inflationtermstructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> &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> &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> &seasonality)
: YoYInflationTermStructure(settlementDays, calendar, baseDate, baseYoYRate, frequency, false, dayCounter, seasonality) {}

QL_DEPRECATED_ENABLE_WARNING

YoYInflationTermStructure::YoYInflationTermStructure(
Date baseDate,
Expand Down
48 changes: 39 additions & 9 deletions ql/termstructures/inflationtermstructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,42 @@ namespace QuantLib {
public:
//! \name Constructors
//@{
YoYInflationTermStructure(Date baseDate,
Rate baseYoYRate,
Frequency frequency,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& seasonality = {});

YoYInflationTermStructure(const Date& referenceDate,
Date baseDate,
Rate baseYoYRate,
Frequency frequency,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& seasonality = {});

YoYInflationTermStructure(Natural settlementDays,
const Calendar& calendar,
Date baseDate,
Rate baseYoYRate,
Frequency frequency,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& 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,
bool indexIsInterpolated,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& 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,
Expand All @@ -266,6 +295,10 @@ namespace QuantLib {
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& 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,
Expand All @@ -275,23 +308,21 @@ namespace QuantLib {
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& 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,
Frequency frequency,
bool indexIsInterpolated,
const ext::shared_ptr<Seasonality>& 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,
Expand All @@ -301,11 +332,10 @@ namespace QuantLib {
bool indexIsInterpolated,
const ext::shared_ptr<Seasonality>& 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,
Expand Down
3 changes: 1 addition & 2 deletions test-suite/inflation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,7 @@ BOOST_AUTO_TEST_CASE(testYYTermStructure) {
auto pYYTS =
ext::make_shared<PiecewiseYoYInflationCurve<Linear>>(
evaluationDate, baseDate, baseYYRate,
iir->frequency(),iir->interpolated(), dc,
helpers);
iir->frequency(), dc, helpers);

// validation
// yoy swaps should reprice to zero
Expand Down
3 changes: 1 addition & 2 deletions test-suite/inflationcapfloor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ struct CommonVars {
Rate baseYYRate = yyData[0].rate/100.0;
auto pYYTS =
ext::make_shared<PiecewiseYoYInflationCurve<Linear>>(
evaluationDate, baseDate, baseYYRate, iir->frequency(),
iir->interpolated(), dc, helpers);
evaluationDate, baseDate, baseYYRate, iir->frequency(), dc, helpers);
yoyTS = ext::dynamic_pointer_cast<YoYInflationTermStructure>(pYYTS);

// make sure that the index has the latest yoy term structure
Expand Down
3 changes: 1 addition & 2 deletions test-suite/inflationcapflooredcoupon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ struct CommonVars {
Rate baseYYRate = yyData[0].rate/100.0;
auto pYYTS =
ext::make_shared<PiecewiseYoYInflationCurve<Linear>>(
evaluationDate, baseDate, baseYYRate, iir->frequency(),
iir->interpolated(), dc, helpers);
evaluationDate, baseDate, baseYYRate, iir->frequency(), dc, helpers);
yoyTS = ext::dynamic_pointer_cast<YoYInflationTermStructure>(pYYTS);

// make sure that the index has the latest yoy term structure
Expand Down
19 changes: 11 additions & 8 deletions test-suite/inflationvolatility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<InterpolatedYoYInflationCurve<Linear>>(
eval, d, r, Monthly, indexIsInterpolated, Actual365Fixed());
eval, d, r, Monthly, Actual365Fixed());
yoyEU.linkTo(pYTSEU);

// price data
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit 64e79c5

Please sign in to comment.