Coverage Report

Created: 2026-09-28 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/termstructures/yield/zerospreadedtermstructure.hpp
Line
Count
Source
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/derivedtermstructure.hpp>
30
#include <ql/termstructures/yield/zeroyieldstructure.hpp>
31
#include <utility>
32
33
namespace QuantLib {
34
35
    //! Term structure with an added spread on the zero yield rate
36
    /*! \note This term structure will remain linked to the original
37
              structure, i.e., any changes in the latter will be
38
              reflected in this structure as well.
39
40
        \ingroup yieldtermstructures
41
42
        \test
43
        - the correctness of the returned values is tested by
44
          checking them against numerical calculations.
45
        - observability against changes in the underlying term
46
          structure and in the added spread is checked.
47
    */
48
    class ZeroSpreadedTermStructure
49
        : public RelativeDerivedYieldTermStructure<ZeroYieldStructure> {
50
      public:
51
        ZeroSpreadedTermStructure(Handle<YieldTermStructure>,
52
                                  Handle<Quote> spread,
53
                                  Compounding comp = Continuous,
54
                                  Frequency freq = NoFrequency);
55
56
        /*! \deprecated Use the constructor without a day counter.
57
                        Deprecated in version 1.41.
58
        */
59
        [[deprecated("Use the constructor without DayCounter")]]
60
        ZeroSpreadedTermStructure(Handle<YieldTermStructure>,
61
                                  Handle<Quote> spread,
62
                                  Compounding comp,
63
                                  Frequency freq,
64
                                  const DayCounter& dc);
65
      protected:
66
        //! returns the spreaded zero yield rate
67
        Rate zeroYieldImpl(Time) const override;
68
      private:
69
        Handle<Quote> spread_;
70
        Compounding comp_;
71
        Frequency freq_;
72
    };
73
74
    inline ZeroSpreadedTermStructure::ZeroSpreadedTermStructure(Handle<YieldTermStructure> h,
75
                                                                Handle<Quote> spread,
76
                                                                Compounding comp,
77
                                                                Frequency freq)
78
0
    : RelativeDerivedYieldTermStructure(std::move(h)), spread_(std::move(spread)),
79
0
      comp_(comp), freq_(freq) {
80
0
        registerWith(spread_);
81
0
    }
82
83
    inline ZeroSpreadedTermStructure::ZeroSpreadedTermStructure(Handle<YieldTermStructure> h,
84
                                                                Handle<Quote> spread,
85
                                                                Compounding comp,
86
                                                                Frequency freq,
87
                                                                const DayCounter& dc)
88
    : ZeroSpreadedTermStructure(std::move(h), std::move(spread), comp, freq) {}
89
90
0
    inline Rate ZeroSpreadedTermStructure::zeroYieldImpl(Time t) const {
91
0
        InterestRate zeroRate =
92
0
            originalCurve_->zeroRate(t, comp_, freq_, true);
93
0
        InterestRate spreadedRate(zeroRate + spread_->value(),
94
0
                                  zeroRate.dayCounter(),
95
0
                                  zeroRate.compounding(),
96
0
                                  zeroRate.frequency());
97
0
        return spreadedRate.equivalentRate(Continuous, NoFrequency, t);
98
0
    }
99
100
}
101
102
#endif