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