25#ifndef quantext_yoy_inflation_curve_observer_static_hpp
26#define quantext_yoy_inflation_curve_observer_static_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 const Date& referenceDate,
const Calendar& calendar,
const DayCounter& dayCounter,
const Period& lag,
46 Frequency frequency,
bool indexIsInterpolated,
const std::vector<Date>&
dates,
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());
59 const std::vector<Date>&
dates()
const;
60 const std::vector<Time>&
times()
const;
61 const std::vector<Real>&
data()
const;
62 const std::vector<Rate>&
rates()
const;
63 std::vector<std::pair<Date, Rate> >
nodes()
const;
90template <
class Interpolator>
92 const Date& referenceDate,
const Calendar& calendar,
const DayCounter& dayCounter,
const Period& lag,
93 Frequency frequency,
bool indexIsInterpolated,
const std::vector<Date>& dates,
94 const std::vector<Handle<Quote>>& rates,
const QuantLib::ext::shared_ptr<Seasonality>& seasonality,
95 const Interpolator& interpolator)
97 indexIsInterpolated, seasonality),
98 InterpolatedCurve<Interpolator>(std::vector<Time>(), std::vector<Real>(), interpolator), dates_(dates),
99 quotes_(rates), indexIsInterpolated_(indexIsInterpolated) {
101 QL_REQUIRE(
dates_.size() > 1,
"too few dates: " <<
dates_.size());
118 for (Size i = 0; i <
dates_.size(); i++) {
119 dates_[i] = inflationPeriod(
dates_[i], frequency).first;
124 "quotes/dates count mismatch: " << this->quotes_.size() <<
" vs " <<
dates_.size());
127 this->data_.resize(
dates_.size());
128 for (Size i = 0; i <
dates_.size(); i++)
129 this->data_[0] = 0.0;
131 this->times_.resize(
dates_.size());
132 this->times_[0] = timeFromReference(
dates_[0]);
133 for (Size i = 1; i <
dates_.size(); i++) {
134 QL_REQUIRE(
dates_[i] >
dates_[i - 1],
"dates not sorted");
137 QL_REQUIRE(this->data_[i] > -1.0,
"zero inflation data < -100 %");
140 this->times_[i] = timeFromReference(
dates_[i]);
141 QL_REQUIRE(!close(this->times_[i], this->times_[i - 1]),
"two dates correspond to the same time "
142 "under this curve's day count convention");
145 this->interpolation_ =
146 this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin());
147 this->interpolation_.update();
150 for (Size i = 0; i <
quotes_.size(); i++)
157 return dates_.front();
162 if (indexIsInterpolated()) {
165 d = inflationPeriod(dates_.back(), frequency()).second;
172 return this->interpolation_(t,
true);
193 std::vector<std::pair<Date, Rate> > results(dates_.size());
194 for (Size i = 0; i < dates_.size(); ++i)
195 results[i] = std::make_pair(dates_[i], this->data_[i]);
200 LazyObject::update();
201 YoYInflationTermStructure::update();
205 for (Size i = 0; i < dates_.size(); ++i)
206 this->data_[i] = quotes_[i]->value();
207 this->interpolation_ =
208 this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin());
209 this->interpolation_.update();
Inflation term structure based on the interpolation of zero rates.
const std::vector< Rate > & rates() const
Rate yoyRateImpl(Time t) const
void performCalculations() const
std::vector< Date > dates_
const std::vector< Date > & dates() const
bool indexIsInterpolated_
YoYInflationCurveObserverStatic(const Date &referenceDate, const Calendar &calendar, const DayCounter &dayCounter, const Period &lag, Frequency frequency, bool indexIsInterpolated, const std::vector< Date > &dates, const std::vector< Handle< Quote > > &rates, const QuantLib::ext::shared_ptr< Seasonality > &seasonality=QuantLib::ext::shared_ptr< Seasonality >(), const Interpolator &interpolator=Interpolator())
const std::vector< Real > & data() const
std::vector< std::pair< Date, Rate > > nodes() const
const std::vector< Time > & times() const
const std::vector< Handle< Quote > > & quotes() const
std::vector< Handle< Quote > > quotes_