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

lballabio / QuantLib / 24251916648

10 Apr 2026 03:59PM UTC coverage: 74.434% (+0.003%) from 74.431%
24251916648

Pull #2533

github

web-flow
Merge bdf0848aa into 148aff0ac
Pull Request #2533: Cache invariants in ImpliedTermStructure

11 of 11 new or added lines in 1 file covered. (100.0%)

4 existing lines in 1 file now uncovered.

58265 of 78277 relevant lines covered (74.43%)

8764995.42 hits per line

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

84.62
/ql/termstructures/yield/impliedtermstructure.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) 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 impliedtermstructure.hpp
22
    \brief Implied term structure
23
*/
24

25
#ifndef quantlib_implied_term_structure_hpp
26
#define quantlib_implied_term_structure_hpp
27

28
#include <ql/termstructures/yieldtermstructure.hpp>
29
#include <ql/utilities/null.hpp>
30
#include <utility>
31

32
namespace QuantLib {
33

34
    //! Implied term structure at a given date in the future
35
    /*! The given date will be the implied reference date.
36

37
        \note This term structure will remain linked to the original
38
              structure, i.e., any changes in the latter will be
39
              reflected in this structure as well.
40

41
        \ingroup yieldtermstructures
42

43
        \test
44
        - the correctness of the returned values is tested by
45
          checking them against numerical calculations.
46
        - observability against changes in the underlying term
47
          structure is checked.
48
    */
49
    class ImpliedTermStructure : public YieldTermStructure {
50
      public:
51
        ImpliedTermStructure(Handle<YieldTermStructure>, const Date& referenceDate);
52
        //! \name YieldTermStructure interface
53
        //@{
54
        DayCounter dayCounter() const override;
55
        Calendar calendar() const override;
56
        Natural settlementDays() const override;
57
        Date maxDate() const override;
58

59
      protected:
60
        DiscountFactor discountImpl(Time) const override;
61
        //@}
62
        //! \name Observer interface
63
        //@{
64
        void update() override;
65
        //@}
66
      private:
67
        Handle<YieldTermStructure> originalCurve_;
68
        mutable DiscountFactor refDf_ = 0;
69
        mutable Time refTime_ = Null<Time>();
70
    };
71

72

73
    // inline definitions
74

75
    inline ImpliedTermStructure::ImpliedTermStructure(Handle<YieldTermStructure> h,
86,962✔
76
                                                      const Date& referenceDate)
86,962✔
77
    : YieldTermStructure(referenceDate), originalCurve_(std::move(h)) {
173,924✔
78
        registerWith(originalCurve_);
86,962✔
79
    }
86,962✔
80

81
    inline DayCounter ImpliedTermStructure::dayCounter() const {
434,812✔
82
        return originalCurve_->dayCounter();
434,812✔
83
    }
84

UNCOV
85
    inline Calendar ImpliedTermStructure::calendar() const {
×
UNCOV
86
        return originalCurve_->calendar();
×
87
    }
88

UNCOV
89
    inline Natural ImpliedTermStructure::settlementDays() const {
×
UNCOV
90
        return originalCurve_->settlementDays();
×
91
    }
92

93
    inline Date ImpliedTermStructure::maxDate() const {
130,444✔
94
        return originalCurve_->maxDate();
130,444✔
95
    }
96

97
    inline void ImpliedTermStructure::update() {
31,250✔
98
        refDf_ = 0;
31,250✔
99
        refTime_ = Null<Time>();
31,250✔
100
        if (!originalCurve_.empty())
31,250✔
101
            enableExtrapolation(originalCurve_->allowsExtrapolation());
31,250✔
102
        YieldTermStructure::update();
31,250✔
103
    }
31,250✔
104

105
    inline DiscountFactor ImpliedTermStructure::discountImpl(Time t) const {
130,448✔
106
        /* t is relative to the current reference date
107
           and needs to be converted to the time relative
108
           to the reference date of the original curve */
109
        if (refDf_ == 0) {
130,448✔
110
            const Date ref = referenceDate();
86,963✔
111
            refTime_ = dayCounter().yearFraction(originalCurve_->referenceDate(), ref);
86,963✔
112
            refDf_ = originalCurve_->discount(ref, true);
86,963✔
113
        }
114
        return originalCurve_->discount(t + refTime_, true) / refDf_;
130,448✔
115
    }
116

117
}
118

119

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