Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
zeroinflationcurveobservermoving.hpp
Go to the documentation of this file.
1/*
2Copyright (C) 2016 Quaternion Risk Management Ltd
3All rights reserved.
4
5This file is part of ORE, a free-software/open-source library
6for transparent pricing and risk analysis - http://opensourcerisk.org
7
8ORE is free software: you can redistribute it and/or modify it
9under the terms of the Modified BSD License. You should have received a
10copy of the license along with this program.
11The license is also available online at <http://opensourcerisk.org>
12
13This program is distributed on the basis that it will form a useful
14contribution to risk analytics and model standardisation, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/termstructures/zeroinflationcurveobservermoving.hpp
20 \brief Observable inflation term structure based on the interpolation of zero rate quotes,
21 but with floating reference date
22*/
23
24#ifndef quantext_zero_inflation_curve_observer_moving_hpp
25#define quantext_zero_inflation_curve_observer_moving_hpp
26
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>
32
33namespace QuantExt {
34using namespace QuantLib;
35
36//! Inflation term structure based on the interpolation of zero rates, with floating reference date
37/*! \ingroup termstructures */
38template <class Interpolator>
39class ZeroInflationCurveObserverMoving : public ZeroInflationTermStructure,
40 protected InterpolatedCurve<Interpolator>,
41 public LazyObject {
42public:
44 Natural settlementDays, const Calendar& calendar, const DayCounter& dayCounter, const Period& lag,
45 Frequency frequency, bool indexIsInterpolated, const std::vector<Time>& times,
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());
49
50 //! \name InflationTermStructure interface
51 //@{
52 Date baseDate() const override;
53 Time maxTime() const override;
54 Date maxDate() const override;
55 //@}
56
57 //! \name Inspectors
58 //@{
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<Time, Rate> > nodes() const;
63 const std::vector<Handle<Quote> >& quotes() const { return quotes_; };
64 //@}
65
66 //! \name Observer interface
67 //@{
68 void update() override;
69 //@}
70
71private:
72 //! \name LazyObject interface
73 //@{
74 void performCalculations() const override;
75 //@}
76
77protected:
78 //! \name ZeroInflationTermStructure Interface
79 //@{
80 Rate zeroRateImpl(Time t) const override;
81 //@}
82 std::vector<Handle<Quote> > quotes_;
84 mutable Date baseDate_;
85};
86
87// template definitions
88
89template <class Interpolator>
91 Natural settlementDays, const Calendar& calendar, const DayCounter& dayCounter, const Period& lag,
92 Frequency frequency, bool indexIsInterpolated, const std::vector<Time>& times,
93 const std::vector<Handle<Quote>>& rates, const QuantLib::ext::shared_ptr<Seasonality>& seasonality,
94 const Interpolator& interpolator)
95 : ZeroInflationTermStructure(settlementDays, calendar, dayCounter, rates[0]->value(), lag, frequency, seasonality),
96 InterpolatedCurve<Interpolator>(std::vector<Time>(), std::vector<Real>(), interpolator), quotes_(rates), indexIsInterpolated_(indexIsInterpolated) {
97
98 QL_REQUIRE(times.size() > 1, "too few times: " << times.size());
99 this->times_.resize(times.size());
100 this->times_[0] = times[0];
101 for (Size i = 1; i < times.size(); i++) {
102 QL_REQUIRE(times[i] > times[i - 1], "times not sorted");
103 this->times_[i] = times[i];
104 }
105
106 QL_REQUIRE(this->quotes_.size() == this->times_.size(),
107 "quotes/times count mismatch: " << this->quotes_.size() << " vs " << this->times_.size());
108
109 // initialise data vector, values are copied from quotes in performCalculations()
110 this->data_.resize(this->times_.size());
111 for (Size i = 0; i < this->times_.size(); i++)
112 this->data_[0] = 0.0;
113
114 this->interpolation_ =
115 this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin());
116 this->interpolation_.update();
117
118 // register with each of the quotes
119 for (Size i = 0; i < this->quotes_.size(); i++)
120 registerWith(this->quotes_[i]);
121}
122
123template <class T> Date ZeroInflationCurveObserverMoving<T>::baseDate() const {
124 // if indexIsInterpolated we fixed the dates in the constructor
125 calculate();
126 return baseDate_;
127}
128
129template <class T> Time ZeroInflationCurveObserverMoving<T>::maxTime() const { return this->times_.back(); }
130
131template <class T> Date ZeroInflationCurveObserverMoving<T>::maxDate() const { return this->maxDate_; }
132
133template <class T> inline Rate ZeroInflationCurveObserverMoving<T>::zeroRateImpl(Time t) const {
134 calculate();
135 return this->interpolation_(t, true);
136}
137
138template <class T> inline const std::vector<Time>& ZeroInflationCurveObserverMoving<T>::times() const {
139 return this->times_;
140}
141
142template <class T> inline const std::vector<Rate>& ZeroInflationCurveObserverMoving<T>::rates() const {
143 calculate();
144 return this->data_;
145}
146
147template <class T> inline const std::vector<Real>& ZeroInflationCurveObserverMoving<T>::data() const {
148 calculate();
149 return this->data_;
150}
151
152template <class T> inline void ZeroInflationCurveObserverMoving<T>::update() {
153 LazyObject::update();
154 ZeroInflationTermStructure::update();
155}
156
157template <class T> inline void ZeroInflationCurveObserverMoving<T>::performCalculations() const {
158
159 Date d = Settings::instance().evaluationDate();
160 Date d0 = d - this->observationLag();
161 if (!indexIsInterpolated_) {
162 baseDate_ = inflationPeriod(d0, this->frequency_).first;
163 } else {
164 baseDate_ = d0;
165 }
166
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();
172}
173} // namespace QuantExt
174
175#endif
Inflation term structure based on the interpolation of zero rates, with floating reference date.
ZeroInflationCurveObserverMoving(Natural settlementDays, const Calendar &calendar, const DayCounter &dayCounter, const Period &lag, Frequency frequency, bool indexIsInterpolated, const std::vector< Time > &times, 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< Handle< Quote > > & quotes() const