25#ifndef quantext_yoy_inflation_curve_observer_moving_hpp
26#define quantext_yoy_inflation_curve_observer_moving_hpp
28#include <ql/math/comparison.hpp>
29#include <ql/math/interpolations/linearinterpolation.hpp>
30#include <ql/patterns/lazyobject.hpp>
31#include <ql/termstructures/inflationtermstructure.hpp>
32#include <ql/termstructures/interpolatedcurve.hpp>
39template <
class Interpolator>
41 protected InterpolatedCurve<Interpolator>,
45 Natural settlementDays,
const Calendar& calendar,
const DayCounter& dayCounter,
const Period& lag,
46 Frequency frequency,
bool indexIsInterpolated,
const std::vector<Time>&
times,
47 const std::vector<Handle<Quote>>&
rates,
48 const QuantLib::ext::shared_ptr<Seasonality>& seasonality = QuantLib::ext::shared_ptr<Seasonality>(),
49 const Interpolator& interpolator = Interpolator());
60 const std::vector<Time>&
times()
const;
61 const std::vector<Real>&
data()
const;
62 const std::vector<Rate>&
rates()
const;
90template <
class Interpolator>
92 Natural settlementDays,
const Calendar& calendar,
const DayCounter& dayCounter,
const Period& lag,
93 Frequency frequency,
bool indexIsInterpolated,
const std::vector<Time>& times,
94 const std::vector<Handle<Quote>>& rates,
const QuantLib::ext::shared_ptr<Seasonality>& seasonality,
95 const Interpolator& interpolator)
96 :
YoYInflationTermStructure(settlementDays, calendar, dayCounter, rates[0]->value(), lag, frequency, indexIsInterpolated, seasonality),
97 InterpolatedCurve<Interpolator>(std::vector<Time>(), std::vector<Real>(), interpolator), quotes_(rates), indexIsInterpolated_(indexIsInterpolated) {
99 QL_REQUIRE(
times.size() > 1,
"too few times: " <<
times.size());
100 this->times_.resize(
times.size());
101 this->times_[0] =
times[0];
102 for (Size i = 1; i <
times.size(); i++) {
103 QL_REQUIRE(
times[i] >
times[i - 1],
"times not sorted");
104 this->times_[i] =
times[i];
107 QL_REQUIRE(this->
quotes_.size() == this->times_.size(),
108 "quotes/times count mismatch: " << this->quotes_.size() <<
" vs " << this->times_.size());
111 this->data_.resize(this->times_.size());
112 for (Size i = 0; i < this->times_.size(); i++)
113 this->data_[0] = 0.0;
115 this->interpolation_ =
116 this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin());
117 this->interpolation_.update();
120 for (Size i = 0; i < this->
quotes_.size(); i++)
121 registerWith(this->
quotes_[i]);
136 return this->interpolation_(t,
true);
154 LazyObject::update();
155 YoYInflationTermStructure::update();
159 Date d = Settings::instance().evaluationDate();
160 Date d0 = d - this->observationLag();
161 if (!indexIsInterpolated_) {
162 baseDate_ = inflationPeriod(d0, this->frequency_).first;
167 for (Size i = 0; i < this->times_.size(); ++i)
168 this->data_[i] = quotes_[i]->value();
169 this->interpolation_ =
170 this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin());
171 this->interpolation_.update();
Inflation term structure based on the interpolation of zero rates.
Rate yoyRateImpl(Time t) const override
void performCalculations() const override
const std::vector< Rate > & rates() const
Date baseDate() const override
bool indexIsInterpolated_
const std::vector< Real > & data() const
const std::vector< Time > & times() const
const std::vector< Handle< Quote > > & quotes() const
Date maxDate() const override
std::vector< Handle< Quote > > quotes_
YoYInflationCurveObserverMoving(Natural settlementDays, const Calendar &calendar, const DayCounter &dayCounter, const Period &lag, Frequency frequency, bool indexIsInterpolated, const std::vector< Time > ×, const std::vector< Handle< Quote > > &rates, const QuantLib::ext::shared_ptr< Seasonality > &seasonality=QuantLib::ext::shared_ptr< Seasonality >(), const Interpolator &interpolator=Interpolator())
Time maxTime() const override