QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
inflationtraits.hpp
Go to the documentation of this file.
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
22/*! \file inflationtraits.hpp
23 \brief inflation bootstrap traits
24*/
25
26#ifndef ql_inflation_bootstrap_traits_hpp
27#define ql_inflation_bootstrap_traits_hpp
28
32
33namespace QuantLib {
34
35 namespace detail {
36 constexpr double avgInflation = 0.02;
37 constexpr double maxInflation = 0.5;
38 }
39
40 //! Bootstrap traits to use for PiecewiseZeroInflationCurve
42 public:
44
45 // start of curve data
47 return t->baseDate();
48 }
49 // value at reference date
51 // this will be overwritten during bootstrap
53 }
54
55 // guesses
56 template <class C>
57 static Rate guess(Size i,
58 const C* c,
59 bool validData,
60 Size) // firstAliveHelper
61 {
62 if (validData) // previous iteration value
63 return c->data()[i];
64
66 }
67
68 // constraints
69 template <class C>
71 const C* c,
72 bool validData,
73 Size) // firstAliveHelper
74 {
75 if (validData) {
76 Rate r = *(std::min_element(c->data().begin(), c->data().end()));
77 return r<0.0 ? Real(r*2.0) : r/2.0;
78 }
80 }
81 template <class C>
83 const C* c,
84 bool validData,
85 Size) // firstAliveHelper
86 {
87 if (validData) {
88 Rate r = *(std::max_element(c->data().begin(), c->data().end()));
89 return r<0.0 ? Real(r/2.0) : r*2.0;
90 }
91 // no constraints.
92 // We choose as max a value very unlikely to be exceeded.
94 }
95
96 // update with new guess
97 static void updateGuess(std::vector<Rate>& data,
98 Rate level,
99 Size i) {
100 data[i] = level;
101 if (i==1)
102 data[0] = level; // the first point is updated as well
103 }
104 // upper bound for convergence loop
105 // calibration is trivial, should be immediate
106 static Size maxIterations() { return 5; }
107 };
108
109 //! Bootstrap traits to use for PiecewiseZeroInflationCurve
111 public:
112 // helper class
114
115 // start of curve data
117 return t->baseDate();
118 }
119
120 // value at reference date
122 return t->baseRate();
123 }
124
125 // guesses
126 template <class C>
127 static Rate guess(Size i,
128 const C* c,
129 bool validData,
130 Size) // firstAliveHelper
131 {
132 if (validData) // previous iteration value
133 return c->data()[i];
134
136 }
137
138 // constraints
139 template <class C>
141 const C* c,
142 bool validData,
143 Size) // firstAliveHelper
144 {
145 if (validData) {
146 Rate r = *(std::min_element(c->data().begin(), c->data().end()));
147 return r<0.0 ? Real(r*2.0) : r/2.0;
148 }
149 return -detail::maxInflation;
150 }
151 template <class C>
153 const C* c,
154 bool validData,
155 Size) // firstAliveHelper
156 {
157 if (validData) {
158 Rate r = *(std::max_element(c->data().begin(), c->data().end()));
159 return r<0.0 ? Real(r/2.0) : r*2.0;
160 }
161 // no constraints.
162 // We choose as max a value very unlikely to be exceeded.
164 }
165
166 // update with new guess
167 static void updateGuess(std::vector<Rate>& data,
168 Rate level,
169 Size i) {
170 data[i] = level;
171 }
172 // upper bound for convergence loop
173 static Size maxIterations() { return 40; }
174 };
175
176}
177
178#endif
base helper class used for bootstrapping
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 *)
static Rate maxValueAfter(Size, const C *c, bool validData, Size)
const DefaultType & t
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
Inflation term structure based on the interpolation of year-on-year rates.
Inflation term structure based on the interpolation of zero rates.
constexpr double maxInflation
constexpr double avgInflation
Definition: any.hpp:37
ext::shared_ptr< YieldTermStructure > r