QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
inflationtraits.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) 2007, 2008 StatPro Italia srl
6 Copyright (C) 2011 Ferdinando Ametrano
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
26#ifndef ql_inflation_bootstrap_traits_hpp
27#define ql_inflation_bootstrap_traits_hpp
28
29#include <ql/termstructures/inflation/interpolatedzeroinflationcurve.hpp>
30#include <ql/termstructures/inflation/interpolatedyoyinflationcurve.hpp>
31#include <ql/termstructures/bootstraphelper.hpp>
32
33namespace QuantLib {
34
35 namespace detail {
36 constexpr double avgInflation = 0.02;
37 constexpr double maxInflation = 0.5;
38 }
39
42 public:
44
45 // start of curve data
47 return inflationPeriod(t->referenceDate() - t->observationLag(), t->frequency()).first;
48 }
49 // value at reference date
51 return t->baseRate();
52 }
53
54 // guesses
55 template <class C>
56 static Rate guess(Size i,
57 const C* c,
58 bool validData,
59 Size) // firstAliveHelper
60 {
61 if (validData) // previous iteration value
62 return c->data()[i];
63
64 if (i==1) // first pillar
66
67 // could/should extrapolate
69 }
70
71 // constraints
72 template <class C>
74 const C* c,
75 bool validData,
76 Size) // firstAliveHelper
77 {
78 if (validData) {
79 Rate r = *(std::min_element(c->data().begin(), c->data().end()));
80 return r<0.0 ? Real(r*2.0) : r/2.0;
81 }
83 }
84 template <class C>
86 const C* c,
87 bool validData,
88 Size) // firstAliveHelper
89 {
90 if (validData) {
91 Rate r = *(std::max_element(c->data().begin(), c->data().end()));
92 return r<0.0 ? Real(r/2.0) : r*2.0;
93 }
94 // no constraints.
95 // We choose as max a value very unlikely to be exceeded.
97 }
98
99 // update with new guess
100 static void updateGuess(std::vector<Rate>& data,
101 Rate level,
102 Size i) {
103 data[i] = level;
104 }
105 // upper bound for convergence loop
106 // calibration is trivial, should be immediate
107 static Size maxIterations() { return 5; }
108 };
109
112 public:
113 // helper class
115
116 // start of curve data
118 if (t->indexIsInterpolated()) {
119 return t->referenceDate() - t->observationLag();
120 } else {
121 return inflationPeriod(t->referenceDate() - t->observationLag(),
122 t->frequency()).first;
123 }
124 }
125 // value at reference date
127 return t->baseRate();
128 }
129
130 // guesses
131 template <class C>
132 static Rate guess(Size i,
133 const C* c,
134 bool validData,
135 Size) // firstAliveHelper
136 {
137 if (validData) // previous iteration value
138 return c->data()[i];
139
140 if (i==1) // first pillar
142
143 // could/should extrapolate
145 }
146
147 // constraints
148 template <class C>
150 const C* c,
151 bool validData,
152 Size) // firstAliveHelper
153 {
154 if (validData) {
155 Rate r = *(std::min_element(c->data().begin(), c->data().end()));
156 return r<0.0 ? Real(r*2.0) : r/2.0;
157 }
158 return -detail::maxInflation;
159 }
160 template <class C>
162 const C* c,
163 bool validData,
164 Size) // firstAliveHelper
165 {
166 if (validData) {
167 Rate r = *(std::max_element(c->data().begin(), c->data().end()));
168 return r<0.0 ? Real(r/2.0) : r*2.0;
169 }
170 // no constraints.
171 // We choose as max a value very unlikely to be exceeded.
173 }
174
175 // update with new guess
176 static void updateGuess(std::vector<Rate>& data,
177 Rate level,
178 Size i) {
179 data[i] = level;
180 }
181 // upper bound for convergence loop
182 static Size maxIterations() { return 40; }
183 };
184
185}
186
187#endif
Base helper class for bootstrapping.
Concrete date class.
Definition: date.hpp:125
Base class for year-on-year inflation term structures.
Bootstrap traits to use for PiecewiseZeroInflationCurve.
static Date initialDate(const YoYInflationTermStructure *t)
static Rate minValueAfter(Size, const C *c, bool validData, Size)
static Rate guess(Size i, const C *c, bool validData, Size)
static Rate initialValue(const YoYInflationTermStructure *t)
BootstrapHelper< YoYInflationTermStructure > helper
static void updateGuess(std::vector< Rate > &data, Rate level, Size i)
static Rate maxValueAfter(Size, const C *c, bool validData, Size)
Interface for zero inflation term structures.
Bootstrap traits to use for PiecewiseZeroInflationCurve.
static Rate minValueAfter(Size, const C *c, bool validData, Size)
static Date initialDate(const ZeroInflationTermStructure *t)
static Rate guess(Size i, const C *c, bool validData, Size)
BootstrapHelper< ZeroInflationTermStructure > helper
static void updateGuess(std::vector< Rate > &data, Rate level, Size i)
static Rate initialValue(const ZeroInflationTermStructure *t)
static Rate maxValueAfter(Size, const C *c, bool validData, Size)
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
constexpr double maxInflation
constexpr double avgInflation
Definition: any.hpp:35
std::pair< Date, Date > inflationPeriod(const Date &d, Frequency frequency)
utility function giving the inflation period for a given date