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

lballabio / QuantLib / 18905857194

29 Oct 2025 11:09AM UTC coverage: 74.32% (+0.4%) from 73.914%
18905857194

Pull #2344

github

web-flow
Merge d353587bf into d823f4ecb
Pull Request #2344: add multicurve bootstrap

99 of 103 new or added lines in 8 files covered. (96.12%)

216 existing lines in 13 files now uncovered.

57072 of 76792 relevant lines covered (74.32%)

8781066.47 hits per line

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

66.67
/ql/termstructures/yieldtermstructure.hpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2004, 2009 Ferdinando Ametrano
5
 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
6
 Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl
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
 <https://www.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 yieldtermstructure.hpp
23
    \brief Interest-rate term structure
24
*/
25

26
#ifndef quantlib_yield_term_structure_hpp
27
#define quantlib_yield_term_structure_hpp
28

29
#include <ql/termstructure.hpp>
30
#include <ql/interestrate.hpp>
31
#include <ql/quote.hpp>
32
#include <vector>
33

34
namespace QuantLib {
35

36
    class MultiCurveBootstrapContributor;
37

38
    //! Interest-rate term structure
39
    /*! This abstract class defines the interface of concrete
40
        interest rate structures which will be derived from this one.
41

42
        \ingroup yieldtermstructures
43

44
        \test observability against evaluation date changes is checked.
45
    */
46
    class YieldTermStructure : public TermStructure {
47
      public:
48
        /*! \name Constructors
49
            See the TermStructure documentation for issues regarding
50
            constructors.
51
        */
52
        //@{
53
        explicit YieldTermStructure(const DayCounter& dc = DayCounter());
54
        YieldTermStructure(const Date& referenceDate,
55
                           const Calendar& cal = Calendar(),
56
                           const DayCounter& dc = DayCounter(),
57
                           std::vector<Handle<Quote> > jumps = {},
58
                           const std::vector<Date>& jumpDates = {});
59
        YieldTermStructure(Natural settlementDays,
60
                           const Calendar& cal,
61
                           const DayCounter& dc = DayCounter(),
62
                           std::vector<Handle<Quote> > jumps = {},
63
                           const std::vector<Date>& jumpDates = {});
64
        //@}
65

66
        /*! \name Discount factors
67

68
            These methods return the discount factor from a given date or time
69
            to the reference date.  In the latter case, the time is calculated
70
            as a fraction of year from the reference date.
71
        */
72
        //@{
73
        DiscountFactor discount(const Date& d,
74
                                bool extrapolate = false) const;
75
        /*! The same day-counting rule used by the term structure
76
            should be used for calculating the passed time t.
77
        */
78
        DiscountFactor discount(Time t,
79
                                bool extrapolate = false) const;
80
        //@}
81

82
        /*! \name Zero-yield rates
83

84
            These methods return the implied zero-yield rate for a
85
            given date or time.  In the former case, the time is
86
            calculated as a fraction of year from the reference date.
87
        */
88
        //@{
89
        /*! The resulting interest rate has the required daycounting
90
            rule.
91
        */
92
        InterestRate zeroRate(const Date& d,
93
                              const DayCounter& resultDayCounter,
94
                              Compounding comp,
95
                              Frequency freq = Annual,
96
                              bool extrapolate = false) const;
97

98
        /*! The resulting interest rate has the same day-counting rule
99
            used by the term structure. The same rule should be used
100
            for calculating the passed time t.
101
        */
102
        InterestRate zeroRate(Time t,
103
                              Compounding comp,
104
                              Frequency freq = Annual,
105
                              bool extrapolate = false) const;
106
        //@}
107

108
        /*! \name Forward rates
109

110
            These methods returns the forward interest rate between two dates
111
            or times.  In the former case, times are calculated as fractions
112
            of year from the reference date.
113

114
            If both dates (times) are equal the instantaneous forward rate is
115
            returned.
116
        */
117
        //@{
118
        /*! The resulting interest rate has the required day-counting
119
            rule.
120
        */
121
        InterestRate forwardRate(const Date& d1,
122
                                 const Date& d2,
123
                                 const DayCounter& resultDayCounter,
124
                                 Compounding comp,
125
                                 Frequency freq = Annual,
126
                                 bool extrapolate = false) const;
127
        /*! The resulting interest rate has the required day-counting
128
            rule.
129
            \warning dates are not adjusted for holidays
130
        */
131
        InterestRate forwardRate(const Date& d,
132
                                 const Period& p,
133
                                 const DayCounter& resultDayCounter,
134
                                 Compounding comp,
135
                                 Frequency freq = Annual,
136
                                 bool extrapolate = false) const;
137

138
        /*! The resulting interest rate has the same day-counting rule
139
            used by the term structure. The same rule should be used
140
            for calculating the passed times t1 and t2.
141
        */
142
        InterestRate forwardRate(Time t1,
143
                                 Time t2,
144
                                 Compounding comp,
145
                                 Frequency freq = Annual,
146
                                 bool extrapolate = false) const;
147
        //@}
148

149
        //! \name Jump inspectors
150
        //@{
151
        const std::vector<Date>& jumpDates() const;
152
        const std::vector<Time>& jumpTimes() const;
153
        //@}
154

155
        //! \name Observer interface
156
        //@{
157
        void update() override;
158
        //@}
159

NEW
160
        virtual const MultiCurveBootstrapContributor* multiCurveBootstrapContributor() const { return nullptr; }
×
161

162
      protected:
163
        /*! \name Calculations
164

165
            This method must be implemented in derived classes to
166
            perform the actual calculations. When it is called,
167
            range check has already been performed; therefore, it
168
            must assume that extrapolation is required.
169
        */
170
        //@{
171
        //! discount factor calculation
172
        virtual DiscountFactor discountImpl(Time) const = 0;
173
        //@}
174
      private:
175
        // methods
176
        void setJumps(const Date& referenceDate);
177
        // data members
178
        std::vector<Handle<Quote> > jumps_;
179
        std::vector<Date> jumpDates_;
180
        std::vector<Time> jumpTimes_;
181
        Size nJumps_ = 0;
182
        Date latestReference_;
183
    };
184

185
    // inline definitions
186

187
    inline
188
    DiscountFactor YieldTermStructure::discount(const Date& d,
62,488,107✔
189
                                                bool extrapolate) const {
190
        return discount(timeFromReference(d), extrapolate);
62,488,107✔
191
    }
192

193
    inline
194
    InterestRate YieldTermStructure::forwardRate(const Date& d,
195
                                                 const Period& p,
196
                                                 const DayCounter& dayCounter,
197
                                                 Compounding comp,
198
                                                 Frequency freq,
199
                                                 bool extrapolate) const {
200
        return forwardRate(d, d+p, dayCounter, comp, freq, extrapolate);
201
    }
202

203
    inline const std::vector<Date>& YieldTermStructure::jumpDates() const {
204
        return this->jumpDates_;
205
    }
206

207
    inline const std::vector<Time>& YieldTermStructure::jumpTimes() const {
208
        return this->jumpTimes_;
209
    }
210

211
}
212

213
#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