24#ifndef quantext_zero_inflation_curve_observer_static_hpp
25#define quantext_zero_inflation_curve_observer_static_hpp
27#include <ql/math/comparison.hpp>
28#include <ql/math/interpolations/linearinterpolation.hpp>
29#include <ql/patterns/lazyobject.hpp>
30#include <ql/termstructures/inflationtermstructure.hpp>
31#include <ql/termstructures/interpolatedcurve.hpp>
38template <
class Interpolator>
40 protected InterpolatedCurve<Interpolator>,
44 const Date& referenceDate,
const Calendar& calendar,
const DayCounter& dayCounter,
const Period& lag,
45 Frequency frequency,
bool indexIsInterpolated,
const std::vector<Date>&
dates,
46 const std::vector<Handle<Quote>>&
rates,
47 const QuantLib::ext::shared_ptr<Seasonality>& seasonality = QuantLib::ext::shared_ptr<Seasonality>(),
48 const Interpolator& interpolator = Interpolator());
58 const std::vector<Date>&
dates()
const;
59 const std::vector<Time>&
times()
const;
60 const std::vector<Real>&
data()
const;
61 const std::vector<Rate>&
rates()
const;
62 std::vector<std::pair<Date, Rate> >
nodes()
const;
89template <
class Interpolator>
91 const Date& referenceDate,
const Calendar& calendar,
const DayCounter& dayCounter,
const Period& lag,
92 Frequency frequency,
bool indexIsInterpolated,
const std::vector<Date>& dates,
93 const std::vector<Handle<Quote>>& rates,
const QuantLib::ext::shared_ptr<Seasonality>& seasonality,
94 const Interpolator& interpolator)
95 : ZeroInflationTermStructure(referenceDate, calendar, dayCounter, rates[0]->value(), lag, frequency, seasonality),
96 InterpolatedCurve<Interpolator>(std::vector<Time>(), std::vector<Real>(), interpolator), dates_(dates),
99 QL_REQUIRE(
dates_.size() > 1,
"too few dates: " <<
dates_.size());
116 for (Size i = 0; i <
dates_.size(); i++) {
117 dates_[i] = inflationPeriod(
dates_[i], frequency).first;
122 "quotes/dates count mismatch: " << this->quotes_.size() <<
" vs " <<
dates_.size());
125 this->data_.resize(
dates_.size());
126 for (Size i = 0; i <
dates_.size(); i++)
127 this->data_[0] = 0.0;
129 this->times_.resize(
dates_.size());
130 this->times_[0] = timeFromReference(
dates_[0]);
131 for (Size i = 1; i <
dates_.size(); i++) {
132 QL_REQUIRE(
dates_[i] >
dates_[i - 1],
"dates not sorted");
135 QL_REQUIRE(this->data_[i] > -1.0,
"zero inflation data < -100 %");
138 this->times_[i] = timeFromReference(
dates_[i]);
139 QL_REQUIRE(!close(this->times_[i], this->times_[i - 1]),
"two dates correspond to the same time "
140 "under this curve's day count convention");
143 this->interpolation_ =
144 this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin());
145 this->interpolation_.update();
148 for (Size i = 0; i <
quotes_.size(); i++)
155 return dates_.front();
160 if (indexIsInterpolated_) {
163 d = inflationPeriod(dates_.back(), frequency()).second;
170 return this->interpolation_(t,
true);
191 std::vector<std::pair<Date, Rate> > results(dates_.size());
192 for (Size i = 0; i < dates_.size(); ++i)
193 results[i] = std::make_pair(dates_[i], this->data_[i]);
198 LazyObject::update();
199 ZeroInflationTermStructure::update();
203 for (Size i = 0; i < dates_.size(); ++i)
204 this->data_[i] = quotes_[i]->value();
205 this->interpolation_ =
206 this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin());
207 this->interpolation_.update();
Inflation term structure based on the interpolation of zero rates.
const std::vector< Rate > & rates() const
ZeroInflationCurveObserverStatic(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())
void performCalculations() const
std::vector< Date > dates_
const std::vector< Date > & dates() const
bool indexIsInterpolated_
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_
Rate zeroRateImpl(Time t) const