QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
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 if (t->hasExplicitBaseDate())
48 return t->baseDate();
49 else
50 return inflationPeriod(t->referenceDate() - t->observationLag(), t->frequency()).first;
51 }
52 // value at reference date
54 // this will be overwritten during bootstrap
56 }
57
58 // guesses
59 template <class C>
60 static Rate guess(Size i,
61 const C* c,
62 bool validData,
63 Size) // firstAliveHelper
64 {
65 if (validData) // previous iteration value
66 return c->data()[i];
67
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 if (i==1)
105 data[0] = level; // the first point is updated as well
106 }
107 // upper bound for convergence loop
108 // calibration is trivial, should be immediate
109 static Size maxIterations() { return 5; }
110 };
111
112 //! Bootstrap traits to use for PiecewiseZeroInflationCurve
114 public:
115 // helper class
117
118 // start of curve data
120 if (t->hasExplicitBaseDate()) {
121 return t->baseDate();
122 } else if (t->indexIsInterpolated()) {
123 return t->referenceDate() - t->observationLag();
124 } else {
125 return inflationPeriod(t->referenceDate() - t->observationLag(),
126 t->frequency()).first;
127 }
128 }
129
130 // value at reference date
132 return t->baseRate();
133 }
134
135 // guesses
136 template <class C>
137 static Rate guess(Size i,
138 const C* c,
139 bool validData,
140 Size) // firstAliveHelper
141 {
142 if (validData) // previous iteration value
143 return c->data()[i];
144
146 }
147
148 // constraints
149 template <class C>
151 const C* c,
152 bool validData,
153 Size) // firstAliveHelper
154 {
155 if (validData) {
156 Rate r = *(std::min_element(c->data().begin(), c->data().end()));
157 return r<0.0 ? Real(r*2.0) : r/2.0;
158 }
159 return -detail::maxInflation;
160 }
161 template <class C>
163 const C* c,
164 bool validData,
165 Size) // firstAliveHelper
166 {
167 if (validData) {
168 Rate r = *(std::max_element(c->data().begin(), c->data().end()));
169 return r<0.0 ? Real(r/2.0) : r*2.0;
170 }
171 // no constraints.
172 // We choose as max a value very unlikely to be exceeded.
174 }
175
176 // update with new guess
177 static void updateGuess(std::vector<Rate>& data,
178 Rate level,
179 Size i) {
180 data[i] = level;
181 }
182 // upper bound for convergence loop
183 static Size maxIterations() { return 40; }
184 };
185
186}
187
188#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:35
std::pair< Date, Date > inflationPeriod(const Date &d, Frequency frequency)
utility function giving the inflation period for a given date
ext::shared_ptr< YieldTermStructure > r