Coverage Report

Created: 2026-03-11 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/termstructures/yield/flatforward.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) 2003, 2004, 2005, 2007 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 flatforward.hpp
22
    \brief flat forward rate term structure
23
*/
24
25
#ifndef quantlib_flat_forward_curve_hpp
26
#define quantlib_flat_forward_curve_hpp
27
28
#include <ql/patterns/lazyobject.hpp>
29
#include <ql/termstructures/yieldtermstructure.hpp>
30
#include <ql/quote.hpp>
31
32
namespace QuantLib {
33
34
    //! Flat interest-rate curve
35
    /*! \ingroup yieldtermstructures */
36
    class FlatForward : public YieldTermStructure,
37
                        public LazyObject {
38
      public:
39
        //! \name Constructors
40
        //@{
41
        FlatForward(const Date& referenceDate,
42
                    Handle<Quote> forward,
43
                    const DayCounter& dayCounter,
44
                    Compounding compounding = Continuous,
45
                    Frequency frequency = Annual);
46
        FlatForward(const Date& referenceDate,
47
                    Rate forward,
48
                    const DayCounter& dayCounter,
49
                    Compounding compounding = Continuous,
50
                    Frequency frequency = Annual);
51
        FlatForward(Natural settlementDays,
52
                    const Calendar& calendar,
53
                    Handle<Quote> forward,
54
                    const DayCounter& dayCounter,
55
                    Compounding compounding = Continuous,
56
                    Frequency frequency = Annual);
57
        FlatForward(Natural settlementDays,
58
                    const Calendar& calendar,
59
                    Rate forward,
60
                    const DayCounter& dayCounter,
61
                    Compounding compounding = Continuous,
62
                    Frequency frequency = Annual);
63
        //@}
64
65
        // inspectors
66
0
        Compounding compounding() const { return compounding_; }
67
0
        Frequency compoundingFrequency() const { return frequency_; }
68
69
        //! \name TermStructure interface
70
        //@{
71
0
        Date maxDate() const override { return Date::maxDate(); }
72
        //@}
73
74
        //! \name Observer interface
75
        //@{
76
        void update() override;
77
        //@}
78
      private:
79
        //! \name LazyObject interface
80
        //@{
81
        void performCalculations() const override;
82
        //@}
83
84
        //! \name YieldTermStructure implementation
85
        //@{
86
        DiscountFactor discountImpl(Time) const override;
87
        //@}
88
89
        Handle<Quote> forward_;
90
        Compounding compounding_;
91
        Frequency frequency_;
92
        mutable InterestRate rate_;
93
    };
94
95
    // inline definitions
96
97
362k
    inline void FlatForward::update() {
98
362k
        LazyObject::update();
99
362k
        YieldTermStructure::update();
100
362k
    }
101
102
0
    inline DiscountFactor FlatForward::discountImpl(Time t) const {
103
0
        calculate();
104
0
        return rate_.discountFactor(t);
105
0
    }
106
  
107
0
    inline void FlatForward::performCalculations() const {
108
0
        rate_ = InterestRate(forward_->value(), dayCounter(),
109
0
                             compounding_, frequency_);
110
0
    }
111
112
}
113
114
#endif