Coverage Report

Created: 2025-08-05 06:45

/src/quantlib/ql/termstructure.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2004, 2005, 2006, 2007 StatPro Italia srl
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <http://quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
#include <ql/math/comparison.hpp>
21
#include <ql/termstructure.hpp>
22
#include <utility>
23
24
namespace QuantLib {
25
26
    TermStructure::TermStructure(DayCounter dc)
27
0
    : settlementDays_(Null<Natural>()), dayCounter_(std::move(dc)) {}
28
29
    TermStructure::TermStructure(const Date& referenceDate, Calendar cal, DayCounter dc)
30
3.02k
    : calendar_(std::move(cal)), referenceDate_(referenceDate), settlementDays_(Null<Natural>()),
31
3.02k
      dayCounter_(std::move(dc)) {}
32
33
    TermStructure::TermStructure(Natural settlementDays, Calendar cal, DayCounter dc)
34
0
    : moving_(true), updated_(false), calendar_(std::move(cal)), settlementDays_(settlementDays),
35
0
      dayCounter_(std::move(dc)) {
36
0
        registerWith(Settings::instance().evaluationDate());
37
0
    }
38
39
414k
    const Date& TermStructure::referenceDate() const {
40
414k
        if (!updated_) {
41
0
            Date today = Settings::instance().evaluationDate();
42
0
            referenceDate_ = calendar().advance(today, settlementDays(), Days);
43
0
            updated_ = true;
44
0
        }
45
414k
        return referenceDate_;
46
414k
    }
47
48
618k
    void TermStructure::update() {
49
618k
        if (moving_)
50
0
            updated_ = false;
51
618k
        notifyObservers();
52
618k
    }
53
54
    void TermStructure::checkRange(const Date& d,
55
0
                                   bool extrapolate) const {
56
0
        QL_REQUIRE(d >= referenceDate(),
57
0
                   "date (" << d << ") before reference date (" <<
58
0
                   referenceDate() << ")");
59
0
        QL_REQUIRE(extrapolate || allowsExtrapolation() || d <= maxDate(),
60
0
                   "date (" << d << ") is past max curve date ("
61
0
                            << maxDate() << ")");
62
0
    }
63
64
    void TermStructure::checkRange(Time t,
65
0
                                   bool extrapolate) const {
66
0
        QL_REQUIRE(t >= 0.0,
67
0
                   "negative time (" << t << ") given");
68
0
        QL_REQUIRE(extrapolate || allowsExtrapolation()
69
0
                   || t <= maxTime() || close_enough(t, maxTime()),
70
0
                   "time (" << t << ") is past max curve time ("
71
0
                            << maxTime() << ")");
72
0
    }
73
74
}