• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lballabio / QuantLib / 14910176578

08 May 2025 03:28PM UTC coverage: 73.315% (+0.02%) from 73.3%
14910176578

Pull #2195

github

web-flow
Merge 3a61f499c into 5d972fb7b
Pull Request #2195: Added `Handle<Quote>` for spread in `OISRateHelper`

32 of 33 new or added lines in 2 files covered. (96.97%)

277 existing lines in 25 files now uncovered.

56277 of 76761 relevant lines covered (73.31%)

8687029.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.48
/ql/termstructures/inflation/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

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

29
#include <ql/termstructures/inflation/interpolatedzeroinflationcurve.hpp>
30
#include <ql/termstructures/inflation/interpolatedyoyinflationcurve.hpp>
31
#include <ql/termstructures/bootstraphelper.hpp>
32

33
namespace 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
41
    class ZeroInflationTraits {
42
      public:
43
        typedef BootstrapHelper<ZeroInflationTermStructure> helper;
44

45
        // start of curve data
46
        static Date initialDate(const ZeroInflationTermStructure* t) {
47
            return t->baseDate();
9✔
48
        }
49
        // value at reference date
50
        static Rate initialValue(const ZeroInflationTermStructure*) {
51
            // this will be overwritten during bootstrap
52
            return detail::avgInflation;
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
161✔
63
                return c->data()[i];
14✔
64

65
            return detail::avgInflation;
66
        }
67

68
        // constraints
69
        template <class C>
70
        static Rate minValueAfter(Size,
161✔
71
                                  const C* c,
72
                                  bool validData,
73
                                  Size) // firstAliveHelper
74
        {
75
            if (validData) {
161✔
76
                Rate r = *(std::min_element(c->data().begin(), c->data().end()));
14✔
77
                return r<0.0 ? Real(r*2.0) : r/2.0;
14✔
78
            }
79
            return -detail::maxInflation;
80
        }
81
        template <class C>
82
        static Rate maxValueAfter(Size,
161✔
83
                                  const C* c,
84
                                  bool validData,
85
                                  Size) // firstAliveHelper
86
        {
87
            if (validData) {
161✔
88
                Rate r = *(std::max_element(c->data().begin(), c->data().end()));
14✔
89
                return r<0.0 ? Real(r/2.0) : r*2.0;
14✔
90
            }
91
            // no constraints.
92
            // We choose as max a value very unlikely to be exceeded.
93
            return detail::maxInflation;
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;
1,017✔
101
            if (i==1)
1,017✔
102
                data[0] = level; // the first point is updated as well
64✔
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
110
    class YoYInflationTraits {
111
      public:
112
        // helper class
113
        typedef BootstrapHelper<YoYInflationTermStructure> helper;
114

115
        // start of curve data
116
        static Date initialDate(const YoYInflationTermStructure* t) {
117
            return t->baseDate();
9✔
118
        }
119

120
        // value at reference date
121
        static Rate initialValue(const YoYInflationTermStructure* t) {
122
            return t->baseRate();
9✔
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
165✔
UNCOV
133
                return c->data()[i];
×
134

135
            return detail::avgInflation;
136
        }
137

138
        // constraints
139
        template <class C>
140
        static Rate minValueAfter(Size,
165✔
141
                                  const C* c,
142
                                  bool validData,
143
                                  Size) // firstAliveHelper
144
        {
145
            if (validData) {
165✔
UNCOV
146
                Rate r = *(std::min_element(c->data().begin(), c->data().end()));
×
UNCOV
147
                return r<0.0 ? Real(r*2.0) : r/2.0;
×
148
            }
149
            return -detail::maxInflation;
150
        }
151
        template <class C>
152
        static Rate maxValueAfter(Size,
165✔
153
                                  const C* c,
154
                                  bool validData,
155
                                  Size) // firstAliveHelper
156
        {
157
            if (validData) {
165✔
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.
163
            return detail::maxInflation;
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;
862✔
171
        }
172
        // upper bound for convergence loop
173
        static Size maxIterations() { return 40; }
174
    };
175

176
}
177

178
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc