Skip to content

Commit

Permalink
Deprecate indexIsInterpolated parameter in YoY inflation curves (#2099
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lballabio authored Oct 18, 2024
2 parents ee7f9aa + 16495ab commit 98e6e3b
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 59 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
2 changes: 2 additions & 0 deletions ql/termstructures/inflation/inflationtraits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ namespace QuantLib {

// start of curve data
static Date initialDate(const YoYInflationTermStructure* t) {
QL_DEPRECATED_DISABLE_WARNING
if (t->hasExplicitBaseDate()) {
return t->baseDate();
} else if (t->indexIsInterpolated()) {
Expand All @@ -125,6 +126,7 @@ namespace QuantLib {
return inflationPeriod(t->referenceDate() - t->observationLag(),
t->frequency()).first;
}
QL_DEPRECATED_ENABLE_WARNING
}

// value at reference date
Expand Down
80 changes: 68 additions & 12 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.37.
*/
[[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.37.
*/
[[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 @@ -130,12 +154,11 @@ namespace QuantLib {
std::vector<Date> dates,
const std::vector<Rate>& rates,
Frequency frequency,
bool indexIsInterpolated,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& seasonality,
const Interpolator& interpolator)
: YoYInflationTermStructure(referenceDate, dates.at(0), rates[0], frequency,
indexIsInterpolated, dayCounter, seasonality),
: YoYInflationTermStructure(referenceDate, dates.at(0), rates[0],
frequency, dayCounter, seasonality),
InterpolatedCurve<Interpolator>(std::vector<Time>(), rates, interpolator),
dates_(std::move(dates)) {

Expand All @@ -157,20 +180,53 @@ namespace QuantLib {
this->interpolation_.update();
}

template <class Interpolator>
InterpolatedYoYInflationCurve<Interpolator>::InterpolatedYoYInflationCurve(
const Date& referenceDate,
std::vector<Date> dates,
const std::vector<Rate>& rates,
Frequency frequency,
bool indexIsInterpolated,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& seasonality,
const Interpolator& interpolator)
: InterpolatedYoYInflationCurve(referenceDate, dates, rates, frequency,
dayCounter, seasonality, interpolator) {
QL_DEPRECATED_DISABLE_WARNING
indexIsInterpolated_ = indexIsInterpolated;
QL_DEPRECATED_ENABLE_WARNING
}

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

template <class Interpolator>
InterpolatedYoYInflationCurve<Interpolator>::
InterpolatedYoYInflationCurve(const Date& referenceDate,
Date baseDate,
Rate baseYoYRate,
Frequency frequency,
bool indexIsInterpolated,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality>& seasonality,
const Interpolator& interpolator)
: InterpolatedYoYInflationCurve(referenceDate, baseDate, baseYoYRate, frequency,
dayCounter, seasonality, interpolator) {
QL_DEPRECATED_DISABLE_WARNING
indexIsInterpolated_ = indexIsInterpolated;
QL_DEPRECATED_ENABLE_WARNING
}


QL_DEPRECATED_DISABLE_WARNING

Expand Down
32 changes: 27 additions & 5 deletions ql/termstructures/inflation/piecewiseyoyinflationcurve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ namespace QuantLib {
public:
typedef Traits traits_type;
typedef Interpolator interpolator_type;

//! \name Constructors
//@{

PiecewiseYoYInflationCurve(
const Date& referenceDate,
Date baseDate,
Rate baseYoYRate,
Frequency frequency,
bool indexIsInterpolated,
const DayCounter& dayCounter,
std::vector<ext::shared_ptr<typename Traits::helper> > instruments,
const ext::shared_ptr<Seasonality>& seasonality = {},
Expand All @@ -64,22 +65,43 @@ namespace QuantLib {
baseDate,
baseYoYRate,
frequency,
indexIsInterpolated,
dayCounter,
seasonality,
i),
instruments_(std::move(instruments)), accuracy_(accuracy) {
bootstrap_.setup(this);
}

/*! \deprecated Use the overload without indexIsInterpolated.
Deprecated in version 1.37.
*/
[[deprecated("Use the overload without indexIsInterpolated")]]
PiecewiseYoYInflationCurve(
const Date& referenceDate,
Date baseDate,
Rate baseYoYRate,
Frequency frequency,
bool indexIsInterpolated,
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,
dayCounter, instruments, seasonality, accuracy, i) {
QL_DEPRECATED_DISABLE_WARNING
this->indexIsInterpolated_ = indexIsInterpolated;
QL_DEPRECATED_ENABLE_WARNING
}


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
57 changes: 44 additions & 13 deletions ql/termstructures/inflationtermstructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,45 @@ namespace QuantLib {
}


QL_DEPRECATED_DISABLE_WARNING

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

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

YoYInflationTermStructure::YoYInflationTermStructure(
Natural settlementDays,
const Calendar& calendar,
Date baseDate,
Rate baseYoYRate,
Frequency frequency,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality> &seasonality)
: InflationTermStructure(settlementDays, calendar, baseDate, frequency, dayCounter, seasonality, baseYoYRate) {}

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

YoYInflationTermStructure::YoYInflationTermStructure(
const Date& referenceDate,
Expand All @@ -281,9 +311,10 @@ namespace QuantLib {
bool indexIsInterpolated,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality> &seasonality)
: InflationTermStructure(referenceDate, baseDate, frequency,
dayCounter, seasonality, baseYoYRate),
indexIsInterpolated_(indexIsInterpolated) {}
: YoYInflationTermStructure(referenceDate, baseDate, baseYoYRate,
frequency, dayCounter, seasonality) {
indexIsInterpolated_ = indexIsInterpolated;
}

YoYInflationTermStructure::YoYInflationTermStructure(
Natural settlementDays,
Expand All @@ -294,11 +325,10 @@ namespace QuantLib {
bool indexIsInterpolated,
const DayCounter& dayCounter,
const ext::shared_ptr<Seasonality> &seasonality)
: InflationTermStructure(settlementDays, calendar, baseDate, frequency,
dayCounter, seasonality, baseYoYRate),
indexIsInterpolated_(indexIsInterpolated) {}

QL_DEPRECATED_DISABLE_WARNING
: YoYInflationTermStructure(settlementDays, calendar, baseDate, baseYoYRate,
frequency, dayCounter, seasonality) {
indexIsInterpolated_ = indexIsInterpolated;
}

YoYInflationTermStructure::YoYInflationTermStructure(
const DayCounter& dayCounter,
Expand Down Expand Up @@ -339,10 +369,9 @@ namespace QuantLib {

QL_DEPRECATED_ENABLE_WARNING


Rate YoYInflationTermStructure::yoyRate(const Date &d, const Period& instObsLag,
bool forceLinearInterpolation,
bool extrapolate) const {
bool forceLinearInterpolation,
bool extrapolate) const {

Period useLag = instObsLag;
if (instObsLag == Period(-1,Days)) {
Expand All @@ -364,6 +393,7 @@ namespace QuantLib {
Rate y2 = yoyRateImpl(t2);
yoyRate = y1 + (y2-y1) * (dt/dp);
} else {
QL_DEPRECATED_DISABLE_WARNING
if (indexIsInterpolated()) {
InflationTermStructure::checkRange(d-useLag, extrapolate);
Time t = timeFromReference(d-useLag);
Expand All @@ -374,6 +404,7 @@ namespace QuantLib {
Time t = timeFromReference(dd.first);
yoyRate = yoyRateImpl(t);
}
QL_DEPRECATED_ENABLE_WARNING
}

if (hasSeasonality()) {
Expand Down
Loading

0 comments on commit 98e6e3b

Please sign in to comment.