30 const Period& observationLag,
33 switch (interpolationType) {
35 return index->fixing(date - observationLag);
39 return index->fixing(fixingPeriod.first);
45 if (date == interpolationPeriod.first) {
49 return index->fixing(fixingPeriod.first);
54 auto I0 = index->fixing(fixingPeriod.first);
55 auto I1 = index->fixing(fixingPeriod.second + oneDay);
57 return I0 + (I1 - I0) * (date - interpolationPeriod.first) /
58 (
Real)((interpolationPeriod.second + oneDay) - interpolationPeriod.first);
61 QL_FAIL(
"unknown CPI interpolation type: " <<
int(interpolationType));
70 const Period& availabilityLag,
72 : familyName_(
std::move(familyName)), region_(
std::move(region)), revised_(revised),
73 frequency_(frequency), availabilityLag_(availabilityLag), currency_(
std::move(currency)) {
86 bool forceOverwrite) {
90 std::vector<Date> dates(
n);
91 std::vector<Rate> rates(
n);
92 for (
Size i=0; i<
n; ++i) {
93 dates[i] = lim.first + i;
98 rates.begin(), forceOverwrite);
105 const Period& availabilityLag,
108 :
InflationIndex(familyName, region, revised, frequency, availabilityLag, currency),
109 zeroInflation_(
std::move(zeroInflation)) {
119 Real I1 = ts[p.first];
121 "Missing " <<
name() <<
" fixing for " << p.first);
148 Date historicalFixingKnown =
150 Date latestNeededDate = fixingDate;
152 if (latestNeededDate <= historicalFixingKnown) {
156 }
else if (latestNeededDate > today) {
175 name() <<
" index fixing at base date " << baseDate <<
" is not available");
180 Date firstDateInPeriod = p.first;
183 baseDate, firstDateInPeriod);
184 return baseFixing * std::pow(1.0 + Z1, t1);
190 return ext::make_shared<ZeroInflationIndex>(
198 :
InflationIndex(
"YYR_" + underlyingIndex->familyName(), underlyingIndex->region(),
199 underlyingIndex->revised(), underlyingIndex->frequency(),
200 underlyingIndex->availabilityLag(), underlyingIndex->currency()),
201 interpolated_(interpolated), ratio_(true), underlyingIndex_(underlyingIndex),
202 yoyInflation_(
std::move(yoyInflation)) {
214 const Period& availabilityLag,
218 frequency, availabilityLag, currency,
std::move(yoyInflation)) {}
228 const Period& availabilityLag,
231 :
InflationIndex(familyName, region, revised, frequency, availabilityLag, currency),
232 interpolated_(interpolated), ratio_(ratio), yoyInflation_(
std::move(yoyInflation)) {
246 Date lastFix = lim.first-1;
248 Date flatMustForecastOn = lastFix+1;
251 if (
interpolated() && fixingDate >= interpMustForecastOn) {
255 if (!
interpolated() && fixingDate >= flatMustForecastOn) {
267 return pastFixing/previousFixing - 1.0;
274 Real dp = lim.second + 1 - lim.first;
275 Real dl = fixingDate - lim.first;
276 Rate limFirstFix = ts[lim.first];
278 "Missing " <<
name() <<
" fixing for "
280 Rate limSecondFix = ts[lim.second+1];
282 "Missing " <<
name() <<
" fixing for "
284 Real linearNow = limFirstFix + (limSecondFix-limFirstFix)*dl/dp;
292 Rate pastFixing = ts[lim.first];
294 "Missing " <<
name() <<
" fixing for " << lim.first);
Shared handle to an observable.
const TimeSeries< Real > & timeSeries() const
returns the fixing TimeSeries
void addFixings(const TimeSeries< Real > &t, bool forceOverwrite=false)
stores historical fixings from a TimeSeries
Base class for inflation-rate indexes,.
InflationIndex(std::string familyName, Region region, bool revised, Frequency frequency, const Period &availabilitiyLag, Currency currency)
Calendar fixingCalendar() const override
std::string name() const override
Returns the name of the index.
void addFixing(const Date &fixingDate, Rate fixing, bool forceOverwrite=false) override
Currency currency() const
Frequency frequency() const
Period availabilityLag() const
std::string familyName() const
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override=0
Calendar for reproducing theoretical calculations.
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Frequency frequency() const
Region class, used for inflation applicability.
const std::string & name() const
DateProxy & evaluationDate()
the date at which pricing is to be performed.
static Settings & instance()
access to the unique instance
Container for historical data.
Base class for year-on-year inflation indices.
Handle< YoYInflationTermStructure > yoyInflation_
ext::shared_ptr< YoYInflationIndex > clone(const Handle< YoYInflationTermStructure > &h) const
bool interpolated() const
Rate forecastFixing(const Date &fixingDate) const
YoYInflationIndex(const ext::shared_ptr< ZeroInflationIndex > &underlyingIndex, bool interpolated, Handle< YoYInflationTermStructure > ts={})
Constructor for year-on-year indices defined as a ratio.
Rate fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
ext::shared_ptr< ZeroInflationIndex > underlyingIndex_
ext::shared_ptr< ZeroInflationIndex > clone(const Handle< ZeroInflationTermStructure > &h) const
Handle< ZeroInflationTermStructure > zeroInflation_
ZeroInflationIndex(const std::string &familyName, const Region ®ion, bool revised, Frequency frequency, const Period &availabilityLag, const Currency ¤cy, Handle< ZeroInflationTermStructure > ts={})
Date lastFixingDate() const
Real forecastFixing(const Date &fixingDate) const
bool needsForecast(const Date &fixingDate) const
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
#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.
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
base classes for inflation indexes
Base classes for inflation term structures.
QuantLib::CPI::InterpolationType effectiveInterpolationType(const QuantLib::CPI::InterpolationType &type=QuantLib::CPI::AsIndex)
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)
Calendar for reproducing theoretical calculations.
#define QL_DEPRECATED_DISABLE_WARNING
#define QL_DEPRECATED_ENABLE_WARNING
static Real laggedFixing(const ext::shared_ptr< ZeroInflationIndex > &index, const Date &date, const Period &observationLag, InterpolationType interpolationType)
interpolated inflation fixing
InterpolationType
when you observe an index, how do you interpolate between fixings?
@ AsIndex
same interpolation as index
@ Linear
linearly between bracketing fixings
@ Flat
flat from previous fixing