30 ext::shared_ptr<Seasonality> seasonality,
33 frequency_(frequency), baseRate_(baseRate), baseDate_(baseDate),
34 hasExplicitBaseDate_(true) {
37 "Seasonality inconsistent with inflation term structure");
42 const Date& referenceDate,
46 ext::shared_ptr<Seasonality> seasonality,
49 frequency_(frequency), baseRate_(baseRate), baseDate_(baseDate),
50 hasExplicitBaseDate_(true) {
53 "Seasonality inconsistent with inflation term structure");
63 ext::shared_ptr<Seasonality> seasonality,
65 :
TermStructure(settlementDays, calendar, dayCounter), seasonality_(
std::move(seasonality)),
66 frequency_(frequency), baseRate_(baseRate), baseDate_(baseDate),
67 hasExplicitBaseDate_(true) {
70 "Seasonality inconsistent with inflation term structure");
76 const Period& observationLag,
79 ext::shared_ptr<Seasonality> seasonality)
81 observationLag_(observationLag), frequency_(frequency),
83 hasExplicitBaseDate_(false) {
86 "Seasonality inconsistent with inflation term structure");
91 const Date& referenceDate,
93 const Period& observationLag,
97 ext::shared_ptr<Seasonality> seasonality)
98 :
TermStructure(referenceDate, calendar, dayCounter), seasonality_(
std::move(seasonality)),
99 observationLag_(observationLag), frequency_(frequency), baseRate_(baseRate),
100 hasExplicitBaseDate_(false) {
103 "Seasonality inconsistent with inflation term structure");
111 const Period& observationLag,
114 ext::shared_ptr<Seasonality> seasonality)
115 :
TermStructure(settlementDays, calendar, dayCounter), seasonality_(
std::move(seasonality)),
116 observationLag_(observationLag), frequency_(frequency),
118 hasExplicitBaseDate_(false) {
121 "Seasonality inconsistent with inflation term structure");
134 const ext::shared_ptr<Seasonality>& seasonality) {
139 "Seasonality inconsistent with inflation term structure");
146 bool extrapolate)
const {
148 "date (" <<
d <<
") is before base date (" <<
baseDate() <<
")");
150 "date (" <<
d <<
") is past max curve date ("
155 bool extrapolate)
const {
157 "time (" <<
t <<
") is before base date");
159 "time (" <<
t <<
") is past max curve time ("
168 const ext::shared_ptr<Seasonality>& seasonality)
172 const Date& referenceDate,
176 const ext::shared_ptr<Seasonality>& seasonality)
185 const ext::shared_ptr<Seasonality>& seasonality)
193 const Period& observationLag,
195 const ext::shared_ptr<Seasonality> &seasonality)
197 dayCounter, seasonality) {}
200 const Date& referenceDate,
204 const Period& observationLag,
206 const ext::shared_ptr<Seasonality> &seasonality)
208 calendar, dayCounter, seasonality) {}
215 const Period& observationLag,
217 const ext::shared_ptr<Seasonality> &seasonality)
219 dayCounter, seasonality) {}
224 bool forceLinearInterpolation,
225 bool extrapolate)
const {
227 Period useLag = instObsLag;
233 if (forceLinearInterpolation) {
236 Real dp = dd.second - dd.first;
237 Real dt =
d - dd.first;
260 bool extrapolate)
const {
270 bool indexIsInterpolated,
272 const ext::shared_ptr<Seasonality> &seasonality)
274 indexIsInterpolated_(indexIsInterpolated) {}
277 const Date& referenceDate,
281 bool indexIsInterpolated,
283 const ext::shared_ptr<Seasonality> &seasonality)
285 dayCounter, seasonality, baseYoYRate),
286 indexIsInterpolated_(indexIsInterpolated) {}
294 bool indexIsInterpolated,
296 const ext::shared_ptr<Seasonality> &seasonality)
298 dayCounter, seasonality, baseYoYRate),
299 indexIsInterpolated_(indexIsInterpolated) {}
306 const Period& observationLag,
308 bool indexIsInterpolated,
309 const ext::shared_ptr<Seasonality> &seasonality)
311 dayCounter, seasonality),
312 indexIsInterpolated_(indexIsInterpolated) {}
315 const Date& referenceDate,
319 const Period& observationLag,
321 bool indexIsInterpolated,
322 const ext::shared_ptr<Seasonality> &seasonality)
324 calendar, dayCounter, seasonality),
325 indexIsInterpolated_(indexIsInterpolated) {}
332 const Period& observationLag,
334 bool indexIsInterpolated,
335 const ext::shared_ptr<Seasonality> &seasonality)
337 frequency, dayCounter, seasonality),
338 indexIsInterpolated_(indexIsInterpolated) {}
344 bool forceLinearInterpolation,
345 bool extrapolate)
const {
347 Period useLag = instObsLag;
353 if (forceLinearInterpolation) {
356 Real dp = dd.second - dd.first;
357 Real dt = (
d-useLag) - dd.first;
365 yoyRate = y1 + (y2-y1) * (dt/dp);
386 bool extrapolate)
const {
400 Month startMonth, endMonth;
416 if (month <=
March) {
419 }
else if (month <=
June) {
431 startMonth = endMonth = month;
434 QL_FAIL(
"Frequency not handled: " << frequency);
438 Date startDate =
Date(1, startMonth, year);
441 return std::make_pair(startDate,endDate);
450 if (indexIsInterpolated) {
static Date endOfMonth(const Date &d)
last day of the month to which the given date belongs
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Interface for inflation term structures.
bool hasSeasonality() const
InflationTermStructure(Date baseDate, Frequency frequency, const DayCounter &dayCounter=DayCounter(), ext::shared_ptr< Seasonality > seasonality={}, Rate baseRate=Null< Rate >())
bool hasExplicitBaseDate() const
ext::shared_ptr< Seasonality > seasonality_
ext::shared_ptr< Seasonality > seasonality() const
virtual Period observationLag() const
virtual Date baseDate() const
minimum (base) date
virtual Frequency frequency() const
void checkRange(const Date &, bool extrapolate) const
Basic term-structure functionality.
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
virtual Time maxTime() const
the latest time for which the curve can return values
virtual Date maxDate() const =0
the latest date for which the curve can return values
Time timeFromReference(const Date &date) const
date/time conversion
YoYInflationTermStructure(Date baseDate, Rate baseYoYRate, Frequency frequency, bool indexIsInterpolated, const DayCounter &dayCounter, const ext::shared_ptr< Seasonality > &seasonality={})
virtual Rate yoyRateImpl(Time time) const =0
to be defined in derived classes
virtual bool indexIsInterpolated() const
Rate yoyRate(const Date &d, const Period &instObsLag=Period(-1, Days), bool forceLinearInterpolation=false, bool extrapolate=false) const
year-on-year inflation rate.
Rate zeroRate(const Date &d, const Period &instObsLag=Period(-1, Days), bool forceLinearInterpolation=false, bool extrapolate=false) const
zero-coupon inflation rate.
ZeroInflationTermStructure(Date baseDate, Frequency frequency, const DayCounter &dayCounter, const ext::shared_ptr< Seasonality > &seasonality={})
virtual Rate zeroRateImpl(Time t) const =0
to be defined in derived classes
#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)
Frequency
Frequency of events.
@ Quarterly
every third month
Real Time
continuous quantity with 1-year units
unsigned QL_INTEGER Natural
positive integer
base classes for inflation indexes
Base classes for inflation term structures.
std::pair< Date, Date > inflationPeriod(const Date &d, Frequency frequency)
utility function giving the inflation period for a given date
Time inflationYearFraction(Frequency f, bool indexIsInterpolated, const DayCounter &dayCounter, const Date &d1, const Date &d2)
#define QL_DEPRECATED_DISABLE_WARNING
#define QL_DEPRECATED_ENABLE_WARNING