20#include <ql/indexes/inflationindex.hpp>
21#include <ql/termstructures/inflationtermstructure.hpp>
28 const Period& observationLag,
31 ext::shared_ptr<Seasonality> seasonality)
33 observationLag_(observationLag), frequency_(frequency),
37 "Seasonality inconsistent with inflation term structure");
42 const Date& referenceDate,
44 const Period& observationLag,
48 ext::shared_ptr<Seasonality> seasonality)
49 :
TermStructure(referenceDate, calendar, dayCounter), seasonality_(
std::move(seasonality)),
50 observationLag_(observationLag), frequency_(frequency), baseRate_(baseRate) {
53 "Seasonality inconsistent with inflation term structure");
61 const Period& observationLag,
64 ext::shared_ptr<Seasonality> seasonality)
65 :
TermStructure(settlementDays, calendar, dayCounter), seasonality_(
std::move(seasonality)),
66 observationLag_(observationLag), frequency_(frequency),
70 "Seasonality inconsistent with inflation term structure");
75 const ext::shared_ptr<Seasonality>& seasonality) {
80 "Seasonality inconsistent with inflation term structure");
87 bool extrapolate)
const {
89 "date (" << d <<
") is before base date (" <<
baseDate() <<
")");
91 "date (" << d <<
") is past max curve date ("
96 bool extrapolate)
const {
98 "time (" << t <<
") is before base date");
100 "time (" << t <<
") is past max curve time ("
109 const Period& observationLag,
111 const ext::shared_ptr<Seasonality> &seasonality)
113 dayCounter, seasonality) {}
116 const Date& referenceDate,
120 const Period& observationLag,
122 const ext::shared_ptr<Seasonality> &seasonality)
124 calendar, dayCounter, seasonality) {}
131 const Period& observationLag,
133 const ext::shared_ptr<Seasonality> &seasonality)
135 dayCounter, seasonality) {}
138 bool forceLinearInterpolation,
139 bool extrapolate)
const {
141 Period useLag = instObsLag;
147 if (forceLinearInterpolation) {
150 Real dp = dd.second - dd.first;
151 Real dt = d - dd.first;
174 bool extrapolate)
const {
183 const Period& observationLag,
185 bool indexIsInterpolated,
186 const ext::shared_ptr<Seasonality> &seasonality)
188 dayCounter, seasonality),
189 indexIsInterpolated_(indexIsInterpolated) {}
192 const Date& referenceDate,
196 const Period& observationLag,
198 bool indexIsInterpolated,
199 const ext::shared_ptr<Seasonality> &seasonality)
201 calendar, dayCounter, seasonality),
202 indexIsInterpolated_(indexIsInterpolated) {}
209 const Period& observationLag,
211 bool indexIsInterpolated,
212 const ext::shared_ptr<Seasonality> &seasonality)
214 frequency, dayCounter, seasonality),
215 indexIsInterpolated_(indexIsInterpolated) {}
219 bool forceLinearInterpolation,
220 bool extrapolate)
const {
222 Period useLag = instObsLag;
228 if (forceLinearInterpolation) {
231 Real dp = dd.second - dd.first;
232 Real dt = (d-useLag) - dd.first;
240 yoyRate = y1 + (y2-y1) * (dt/dp);
261 bool extrapolate)
const {
275 Month startMonth, endMonth;
291 if (month <=
March) {
294 }
else if (month <=
June) {
306 startMonth = endMonth = month;
309 QL_FAIL(
"Frequency not handled: " << frequency);
313 Date startDate =
Date(1, startMonth, year);
316 return std::make_pair(startDate,endDate);
325 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
ext::shared_ptr< Seasonality > seasonality_
ext::shared_ptr< Seasonality > seasonality() const
void setSeasonality(const ext::shared_ptr< Seasonality > &seasonality={})
Functions to set and get seasonality.
virtual Period observationLag() const
InflationTermStructure(Rate baseRate, const Period &observationLag, Frequency frequency, const DayCounter &dayCounter=DayCounter(), ext::shared_ptr< Seasonality > seasonality={})
virtual Frequency frequency() const
void checkRange(const Date &, bool extrapolate) const
virtual Date baseDate() const =0
minimum (base) date
Basic term-structure functionality.
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(const DayCounter &dayCounter, Rate baseYoYRate, const Period &lag, Frequency frequency, bool indexIsInterpolated, 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.
ZeroInflationTermStructure(const DayCounter &dayCounter, Rate baseZeroRate, const Period &lag, Frequency frequency, const ext::shared_ptr< Seasonality > &seasonality={})
virtual Rate zeroRateImpl(Time t) const =0
to be defined in derived classes
Rate zeroRate(const Date &d, const Period &instObsLag=Period(-1, Days), bool forceLinearInterpolation=false, bool extrapolate=false) const
zero-coupon inflation rate.
Frequency
Frequency of events.
@ Quarterly
every third month
Real Time
continuous quantity with 1-year units
unsigned QL_INTEGER Natural
positive integer
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)