QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
inflationindex.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Chris Kenyon
5 Copyright (C) 2021 Ralf Konrad Eckel
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
25#ifndef quantlib_inflation_index_hpp
26#define quantlib_inflation_index_hpp
27
28#include <ql/currency.hpp>
29#include <ql/handle.hpp>
30#include <ql/index.hpp>
31#include <ql/indexes/region.hpp>
32#include <ql/termstructures/inflationtermstructure.hpp>
33
34namespace QuantLib {
35
36 class ZeroInflationIndex;
37
38 struct CPI {
43 Linear
44 };
45
47
57 static Real laggedFixing(const ext::shared_ptr<ZeroInflationIndex>& index,
58 const Date& date,
59 const Period& observationLag,
60 InterpolationType interpolationType);
61 };
62
63
65 class InflationIndex : public Index, public Observer {
66 public:
67 InflationIndex(std::string familyName,
69 bool revised,
71 const Period& availabilitiyLag,
73
77 QL_DEPRECATED
78 InflationIndex(std::string familyName,
80 bool revised,
81 bool interpolated,
83 const Period& availabilitiyLag,
85
87
88 std::string name() const override;
89
95 Calendar fixingCalendar() const override;
96 bool isValidFixingDate(const Date&) const override { return true; }
97
109 Real fixing(const Date& fixingDate, bool forecastTodaysFixing = false) const override = 0;
110
115 void addFixing(const Date& fixingDate, Rate fixing, bool forceOverwrite = false) override;
117
119
120 void update() override;
122
124
125 std::string familyName() const;
126 Region region() const;
127 bool revised() const;
141 QL_DEPRECATED
142 bool interpolated() const;
143
144 Frequency frequency() const;
152 Period availabilityLag() const;
153 Currency currency() const;
155
156 protected:
158 std::string familyName_;
164
171 QL_DEPRECATED
172 bool interpolated_ = false;
173
174 private:
175 std::string name_;
176 };
177
178
181 public:
183 const std::string& familyName,
184 const Region& region,
185 bool revised,
187 const Period& availabilityLag,
188 const Currency& currency,
190
194 QL_DEPRECATED
196 const std::string& familyName,
197 const Region& region,
198 bool revised,
199 bool interpolated,
201 const Period& availabilityLag,
202 const Currency& currency,
204
206
207
210 Real fixing(const Date& fixingDate, bool forecastTodaysFixing = false) const override;
212
215 ext::shared_ptr<ZeroInflationIndex> clone(const Handle<ZeroInflationTermStructure>& h) const;
217 private:
218 bool needsForecast(const Date& fixingDate) const;
219 Real forecastFixing(const Date& fixingDate) const;
221 };
222
223
225
229 public:
231
232
238 const ext::shared_ptr<ZeroInflationIndex>& underlyingIndex,
239 bool interpolated,
241
243
248 const std::string& familyName,
249 const Region& region,
250 bool revised,
251 bool interpolated,
253 const Period& availabilityLag,
254 const Currency& currency,
256
258
268 QL_DEPRECATED
270 const std::string& familyName,
271 const Region& region,
272 bool revised,
273 bool interpolated,
274 bool ratio, // is this one a genuine index or a ratio?
276 const Period& availabilityLag,
277 const Currency& currency,
280
282
283
286 Rate fixing(const Date& fixingDate, bool forecastTodaysFixing = false) const override;
287
289
291 // Override the deprecation above
292 bool interpolated() const;
293 bool ratio() const;
294 ext::shared_ptr<ZeroInflationIndex> underlyingIndex() const;
296
297 ext::shared_ptr<YoYInflationIndex> clone(const Handle<YoYInflationTermStructure>& h) const;
299
300 protected:
301 // Override the deprecation above
303
304 private:
305 Rate forecastFixing(const Date& fixingDate) const;
306 bool ratio_;
307 ext::shared_ptr<ZeroInflationIndex> underlyingIndex_;
309 };
310
311
312 namespace detail {
313 namespace CPI {
314 // Returns either CPI::Flat or CPI::Linear depending on the combination of index and
315 // CPI::InterpolationType.
317 const ext::shared_ptr<ZeroInflationIndex>& index,
319
320
321 // checks whether the combination of index and CPI::InterpolationType results
322 // effectively in CPI::Linear
323 bool
324 isInterpolated(const ext::shared_ptr<ZeroInflationIndex>& index,
326 }
327 }
328
329
330 // inline
331
332 inline std::string InflationIndex::name() const {
333 return name_;
334 }
335
338 }
339
340 inline std::string InflationIndex::familyName() const {
341 return familyName_;
342 }
343
345 return region_;
346 }
347
348 inline bool InflationIndex::revised() const {
349 return revised_;
350 }
351
353 return frequency_;
354 }
355
357 return availabilityLag_;
358 }
359
361 return currency_;
362 }
363
366 return zeroInflation_;
367 }
368
370 return interpolated_;
371 }
372
373 inline bool YoYInflationIndex::ratio() const {
374 return ratio_;
375 }
376
377 inline ext::shared_ptr<ZeroInflationIndex> YoYInflationIndex::underlyingIndex() const {
378 return underlyingIndex_;
379 }
380
383 return yoyInflation_;
384 }
385
386 inline bool detail::CPI::isInterpolated(const ext::shared_ptr<ZeroInflationIndex>& index,
389 }
390}
391
392#endif
calendar class
Definition: calendar.hpp:61
Currency specification
Definition: currency.hpp:36
Concrete date class.
Definition: date.hpp:125
Shared handle to an observable.
Definition: handle.hpp:41
purely virtual base class for indexes
Definition: index.hpp:44
Base class for inflation-rate indexes,.
Calendar fixingCalendar() const override
QL_DEPRECATED bool interpolated() const
std::string name() const override
Returns the name of the index.
void addFixing(const Date &fixingDate, Rate fixing, bool forceOverwrite=false) override
bool isValidFixingDate(const Date &) const override
returns TRUE if the fixing date is a valid one
Frequency frequency() const
QL_DEPRECATED bool interpolated_
Period availabilityLag() const
std::string familyName() const
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override=0
Linear-interpolation factory and traits
Object that gets notified when a given observable changes.
Definition: observable.hpp:116
Region class, used for inflation applicability.
Definition: region.hpp:36
Base class for year-on-year inflation indices.
Handle< YoYInflationTermStructure > yoyInflation_
ext::shared_ptr< YoYInflationIndex > clone(const Handle< YoYInflationTermStructure > &h) const
Rate forecastFixing(const Date &fixingDate) const
Handle< YoYInflationTermStructure > yoyInflationTermStructure() const
Rate fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
ext::shared_ptr< ZeroInflationIndex > underlyingIndex() const
ext::shared_ptr< ZeroInflationIndex > underlyingIndex_
Base class for zero inflation indices.
ext::shared_ptr< ZeroInflationIndex > clone(const Handle< ZeroInflationTermStructure > &h) const
Handle< ZeroInflationTermStructure > zeroInflation_
Real forecastFixing(const Date &fixingDate) const
Handle< ZeroInflationTermStructure > zeroInflationTermStructure() const
bool needsForecast(const Date &fixingDate) const
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
Frequency
Frequency of events.
Definition: frequency.hpp:37
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
bool isInterpolated(const ext::shared_ptr< ZeroInflationIndex > &index, const QuantLib::CPI::InterpolationType &type=QuantLib::CPI::AsIndex)
QuantLib::CPI::InterpolationType effectiveInterpolationType(const ext::shared_ptr< ZeroInflationIndex > &index, const QuantLib::CPI::InterpolationType &type=QuantLib::CPI::AsIndex)
Definition: any.hpp:35
static Real laggedFixing(const ext::shared_ptr< ZeroInflationIndex > &index, const Date &date, const Period &observationLag, InterpolationType interpolationType)
interpolated inflation fixing
InterpolationType
when you observe an index, how do you interpolate between fixings?
@ AsIndex
same interpolation as index
@ Linear
linearly between bracketing fixings
@ Flat
flat from previous fixing