30 const Period& observationLag,
33 switch (interpolationType) {
37 return index->fixing(fixingPeriod.first);
43 auto I0 = index->fixing(fixingPeriod.first);
45 if (date == interpolationPeriod.first) {
54 auto I1 = index->fixing(fixingPeriod.second + oneDay);
56 return I0 + (I1 - I0) * (date - interpolationPeriod.first) /
57 (
Real)((interpolationPeriod.second + oneDay) - interpolationPeriod.first);
60 QL_FAIL(
"unknown CPI interpolation type: " <<
int(interpolationType));
67 const Period& observationLag,
70 switch (interpolationType) {
72 return index->fixing(date - observationLag);
76 return index->fixing(fixingPeriod.first);
79 if (index->ratio() && !index->needsForecast(date)) {
88 auto underlying = index->underlyingIndex();
100 auto Y0 = index->fixing(fixingPeriod.first);
102 if (date == interpolationPeriod.first) {
107 auto Y1 = index->fixing(fixingPeriod.second + oneDay);
109 return Y0 + (Y1 - Y0) * (date - interpolationPeriod.first) /
110 (
Real)((interpolationPeriod.second + oneDay) - interpolationPeriod.first);
114 QL_FAIL(
"unknown CPI interpolation type: " <<
int(interpolationType));
123 const Period& availabilityLag,
125 : familyName_(
std::move(familyName)), region_(
std::move(region)), revised_(revised),
126 frequency_(frequency), availabilityLag_(availabilityLag), currency_(
std::move(currency)) {
139 bool forceOverwrite) {
143 std::vector<Date> dates(
n);
144 std::vector<Rate> rates(
n);
145 for (
Size i=0; i<
n; ++i) {
146 dates[i] = lim.first + i;
151 rates.begin(), forceOverwrite);
158 const Period& availabilityLag,
161 :
InflationIndex(familyName, region, revised, frequency, availabilityLag, currency),
162 zeroInflation_(
std::move(zeroInflation)) {
171 "Missing " <<
name() <<
" fixing for "
197 auto latestPossibleHistoricalFixingPeriod =
202 Date latestNeededDate = fixingPeriod.first;
204 if (latestNeededDate < latestPossibleHistoricalFixingPeriod.first) {
208 }
else if (latestNeededDate > latestPossibleHistoricalFixingPeriod.second) {
223 name() <<
" index fixing at base date " << baseDate <<
" is not available");
228 Date firstDateInPeriod = fixingPeriod.first;
231 baseDate, firstDateInPeriod);
232 return baseFixing * std::pow(1.0 + Z1, t1);
238 return ext::make_shared<ZeroInflationIndex>(
245 :
InflationIndex(
"YYR_" + underlyingIndex->familyName(), underlyingIndex->region(),
246 underlyingIndex->revised(), underlyingIndex->frequency(),
247 underlyingIndex->availabilityLag(), underlyingIndex->currency()),
248 interpolated_(false), ratio_(true), underlyingIndex_(underlyingIndex),
249 yoyInflation_(
std::move(yoyInflation)) {
265 const Period& availabilityLag,
268 :
InflationIndex(familyName, region, revised, frequency, availabilityLag, currency),
269 interpolated_(false), ratio_(false), yoyInflation_(
std::move(yoyInflation)) {
278 const Period& availabilityLag,
281 :
YoYInflationIndex(familyName, region, revised, frequency, availabilityLag, currency,
std::move(yoyInflation)) {
310 Date latestNeededDate;
311 if (!
interpolated() || fixingDate == fixingPeriod.first)
312 latestNeededDate = fixingPeriod.first;
314 latestNeededDate = fixingPeriod.second + 1;
319 auto latestPossibleHistoricalFixingPeriod =
322 if (latestNeededDate < latestPossibleHistoricalFixingPeriod.first) {
326 }
else if (latestNeededDate > latestPossibleHistoricalFixingPeriod.second) {
352 Rate YY0 = ts[periodStart];
354 "Missing " <<
name() <<
" fixing for " << periodStart);
362 Real dp = periodEnd + 1 - periodStart;
363 Real dl = fixingDate - periodStart;
364 Rate YY1 = ts[periodEnd+1];
366 "Missing " <<
name() <<
" fixing for " << periodEnd+1);
367 return YY0 + (YY1 - YY0) * dl / dp;
382 d = fixingPeriod.first;
392 return ext::shared_ptr<YoYInflationIndex>(
396 return ext::shared_ptr<YoYInflationIndex>(
416 const ext::shared_ptr<YoYInflationIndex>& index) {
429 const ext::shared_ptr<YoYInflationIndex>& index) {
Shared handle to an observable.
ext::shared_ptr< Observable > notifier() const
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
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
Base class for year-on-year inflation indices.
Handle< YoYInflationTermStructure > yoyInflation_
ext::shared_ptr< YoYInflationIndex > clone(const Handle< YoYInflationTermStructure > &h) const
bool interpolated() const
Date lastFixingDate() const
Rate forecastFixing(const Date &fixingDate) const
Rate fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
ext::shared_ptr< ZeroInflationIndex > underlyingIndex_
bool needsForecast(const Date &fixingDate) const
YoYInflationIndex(const ext::shared_ptr< ZeroInflationIndex > &underlyingIndex, Handle< YoYInflationTermStructure > ts={})
Constructor for year-on-year indices defined as a ratio.
Real pastFixing(const Date &fixingDate) const override
returns a past fixing at the given date
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 pastFixing(const Date &fixingDate) const override
returns a past fixing at the given date
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.
bool isInterpolated(const QuantLib::CPI::InterpolationType &type)
QuantLib::CPI::InterpolationType effectiveInterpolationType(const QuantLib::CPI::InterpolationType &type)
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 laggedYoYRate(const ext::shared_ptr< YoYInflationIndex > &index, const Date &date, const Period &observationLag, InterpolationType interpolationType)
interpolated year-on-year inflation rate
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