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

lballabio / QuantLib / 19787828006

29 Nov 2025 06:42PM UTC coverage: 74.352% (+0.4%) from 73.914%
19787828006

Pull #2344

github

web-flow
Merge e103123e2 into 08ef06893
Pull Request #2344: add multicurve bootstrap

117 of 131 new or added lines in 6 files covered. (89.31%)

413 existing lines in 27 files now uncovered.

57224 of 76964 relevant lines covered (74.35%)

8799680.15 hits per line

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

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

3
/*
4
 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5
 Copyright (C) 2007, 2008 StatPro Italia srl
6

7
 This file is part of QuantLib, a free-software/open-source library
8
 for financial quantitative analysts and developers - http://quantlib.org/
9

10
 QuantLib is free software: you can redistribute it and/or modify it
11
 under the terms of the QuantLib license.  You should have received a
12
 copy of the license along with this program; if not, please email
13
 <quantlib-dev@lists.sf.net>. The license is also available online at
14
 <https://www.quantlib.org/license.shtml>.
15

16
 This program is distributed in the hope that it will be useful, but WITHOUT
17
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 FOR A PARTICULAR PURPOSE.  See the license for more details.
19
*/
20

21
/*! \file zerospreadedtermstructure.hpp
22
    \brief Zero spreaded term structure
23
*/
24

25
#ifndef quantlib_zero_spreaded_term_structure_hpp
26
#define quantlib_zero_spreaded_term_structure_hpp
27

28
#include <ql/quote.hpp>
29
#include <ql/termstructures/yield/zeroyieldstructure.hpp>
30
#include <utility>
31

32
namespace QuantLib {
33

34
    //! Term structure with an added spread on the zero yield rate
35
    /*! \note This term structure will remain linked to the original
36
              structure, i.e., any changes in the latter will be
37
              reflected in this structure as well.
38

39
        \ingroup yieldtermstructures
40

41
        \test
42
        - the correctness of the returned values is tested by
43
          checking them against numerical calculations.
44
        - observability against changes in the underlying term
45
          structure and in the added spread is checked.
46
    */
47
    class ZeroSpreadedTermStructure : public ZeroYieldStructure {
48
      public:
49
        ZeroSpreadedTermStructure(Handle<YieldTermStructure>,
50
                                  Handle<Quote> spread,
51
                                  Compounding comp = Continuous,
52
                                  Frequency freq = NoFrequency);
53

54
        /*! \deprecated Use the constructor without a day counter.
55
                        Deprecated in version 1.41.
56
        */
57
        [[deprecated("Use the constructor without DayCounter")]]
58
        ZeroSpreadedTermStructure(Handle<YieldTermStructure>,
59
                                  Handle<Quote> spread,
60
                                  Compounding comp,
61
                                  Frequency freq,
62
                                  const DayCounter& dc);
63
        //! \name YieldTermStructure interface
64
        //@{
65
        DayCounter dayCounter() const override;
66
        Calendar calendar() const override;
67
        Natural settlementDays() const override;
68
        const Date& referenceDate() const override;
69
        Date maxDate() const override;
70
        Time maxTime() const override;
71
        //@}
72
        //! \name Observer interface
73
        //@{
74
        void update() override;
75
        //@}
76
      protected:
77
        //! returns the spreaded zero yield rate
78
        Rate zeroYieldImpl(Time) const override;
79
        //! returns the spreaded forward rate
80
        /* This method must disappear should the spread become a curve */
81
        Rate forwardImpl(Time) const;
82
      private:
83
        Handle<YieldTermStructure> originalCurve_;
84
        Handle<Quote> spread_;
85
        Compounding comp_;
86
        Frequency freq_;
87
    };
88

89
    inline ZeroSpreadedTermStructure::ZeroSpreadedTermStructure(Handle<YieldTermStructure> h,
10,838✔
90
                                                                Handle<Quote> spread,
91
                                                                Compounding comp,
92
                                                                Frequency freq)
10,838✔
93
    : originalCurve_(std::move(h)), spread_(std::move(spread)), comp_(comp), freq_(freq) {
21,676✔
94
        if (!originalCurve_.empty())
10,838✔
95
            enableExtrapolation(originalCurve_->allowsExtrapolation());
10,826✔
96
        registerWith(originalCurve_);
21,676✔
97
        registerWith(spread_);
10,838✔
98
    }
10,838✔
99

100
    inline ZeroSpreadedTermStructure::ZeroSpreadedTermStructure(Handle<YieldTermStructure> h,
101
                                                                Handle<Quote> spread,
102
                                                                Compounding comp,
103
                                                                Frequency freq,
104
                                                                const DayCounter& dc)
105
    : ZeroSpreadedTermStructure(std::move(h), std::move(spread), comp, freq) {}
106

107
    inline DayCounter ZeroSpreadedTermStructure::dayCounter() const {
469,836✔
108
        return originalCurve_->dayCounter();
469,836✔
109
    }
110

111
    inline Calendar ZeroSpreadedTermStructure::calendar() const {
×
UNCOV
112
        return originalCurve_->calendar();
×
113
    }
114

UNCOV
115
    inline Natural ZeroSpreadedTermStructure::settlementDays() const {
×
UNCOV
116
        return originalCurve_->settlementDays();
×
117
    }
118

119
    inline const Date& ZeroSpreadedTermStructure::referenceDate() const {
488,736✔
120
        return originalCurve_->referenceDate();
488,736✔
121
    }
122

UNCOV
123
    inline Date ZeroSpreadedTermStructure::maxDate() const {
×
UNCOV
124
        return originalCurve_->maxDate();
×
125
    }
126

127
    inline Time ZeroSpreadedTermStructure::maxTime() const {
470,040✔
128
        return originalCurve_->maxTime();
470,040✔
129
    }
130

131
    inline void ZeroSpreadedTermStructure::update() {
18,369✔
132
        if (!originalCurve_.empty()) {
18,369✔
133
            YieldTermStructure::update();
18,368✔
134
            enableExtrapolation(originalCurve_->allowsExtrapolation());
18,368✔
135
        } else {
136
            /* The implementation inherited from YieldTermStructure
137
               asks for our reference date, which we don't have since
138
               the original curve is still not set. Therefore, we skip
139
               over that and just call the base-class behavior. */
140
            // NOLINTNEXTLINE(bugprone-parent-virtual-call)
141
            TermStructure::update();
1✔
142
        }
143
    }
18,369✔
144

145
    inline Rate ZeroSpreadedTermStructure::zeroYieldImpl(Time t) const {
468,590✔
146
        // to be fixed: user-defined daycounter should be used
147
        InterestRate zeroRate =
148
            originalCurve_->zeroRate(t, comp_, freq_, true);
468,590✔
149
        InterestRate spreadedRate(zeroRate + spread_->value(),
468,590✔
150
                                  zeroRate.dayCounter(),
151
                                  zeroRate.compounding(),
152
                                  zeroRate.frequency());
468,590✔
153
        return spreadedRate.equivalentRate(Continuous, NoFrequency, t);
1,405,770✔
154
    }
155

156
    inline Rate ZeroSpreadedTermStructure::forwardImpl(Time t) const {
157
        return originalCurve_->forwardRate(t, t, comp_, freq_, true)
158
            + spread_->value();
159
    }
160

161
}
162

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

© 2026 Coveralls, Inc