Coverage Report

Created: 2025-12-08 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/indexes/interestrateindex.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, 2006, 2007, 2009 StatPro Italia srl
6
 Copyright (C) 2006, 2011 Ferdinando Ametrano
7
8
 This file is part of QuantLib, a free-software/open-source library
9
 for financial quantitative analysts and developers - http://quantlib.org/
10
11
 QuantLib is free software: you can redistribute it and/or modify it
12
 under the terms of the QuantLib license.  You should have received a
13
 copy of the license along with this program; if not, please email
14
 <quantlib-dev@lists.sf.net>. The license is also available online at
15
 <https://www.quantlib.org/license.shtml>.
16
17
 This program is distributed in the hope that it will be useful, but WITHOUT
18
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 FOR A PARTICULAR PURPOSE.  See the license for more details.
20
*/
21
22
/*! \file interestrateindex.hpp
23
    \brief base class for interest rate indexes
24
*/
25
26
#ifndef quantlib_interestrateindex_hpp
27
#define quantlib_interestrateindex_hpp
28
29
#include <ql/index.hpp>
30
#include <ql/time/calendar.hpp>
31
#include <ql/currency.hpp>
32
#include <ql/time/daycounter.hpp>
33
#include <ql/time/period.hpp>
34
35
namespace QuantLib {
36
37
    //! base class for interest rate indexes
38
    /*! \todo add methods returning InterestRate */
39
    class InterestRateIndex : public Index {
40
      public:
41
        InterestRateIndex(std::string familyName,
42
                          const Period& tenor,
43
                          Natural settlementDays,
44
                          Currency currency,
45
                          Calendar fixingCalendar,
46
                          DayCounter dayCounter);
47
        //! \name Index interface
48
        //@{
49
        std::string name() const override;
50
        Calendar fixingCalendar() const override;
51
        bool isValidFixingDate(const Date& fixingDate) const override;
52
        Rate fixing(const Date& fixingDate, bool forecastTodaysFixing = false) const override;
53
        //@}
54
        //! \name Inspectors
55
        //@{
56
0
        std::string familyName() const { return familyName_; }
57
0
        Period tenor() const { return tenor_; }
58
0
        Natural fixingDays() const { return fixingDays_; }
59
0
        const Currency& currency() const { return currency_; }
60
0
        const DayCounter& dayCounter() const { return dayCounter_; }
61
        //@}
62
        /*! \name Date calculations
63
64
            These method can be overridden to implement particular
65
            conventions (e.g. EurLibor)
66
67
            @{
68
        */
69
        virtual Date fixingDate(const Date& valueDate) const;
70
        virtual Date valueDate(const Date& fixingDate) const;
71
        virtual Date maturityDate(const Date& valueDate) const = 0;
72
        //@}
73
        //! \name Fixing calculations
74
        //@{
75
        //! It can be overridden to implement particular conventions
76
        virtual Rate forecastFixing(const Date& fixingDate) const = 0;
77
        // @}
78
      protected:
79
        std::string familyName_;
80
        Period tenor_;
81
        Natural fixingDays_;
82
        Currency currency_;
83
        DayCounter dayCounter_;
84
        std::string name_;
85
      private:
86
        Calendar fixingCalendar_;
87
    };
88
89
90
    // inline definitions
91
92
0
    inline std::string InterestRateIndex::name() const {
93
0
        return name_;
94
0
    }
95
96
0
    inline Calendar InterestRateIndex::fixingCalendar() const {
97
0
        return fixingCalendar_;
98
0
    }
99
100
0
    inline bool InterestRateIndex::isValidFixingDate(const Date& d) const {
101
0
        return fixingCalendar().isBusinessDay(d);
102
0
    }
103
104
0
    inline Date InterestRateIndex::fixingDate(const Date& valueDate) const {
105
0
        Date fixingDate = fixingCalendar().advance(valueDate,
106
0
            -static_cast<Integer>(fixingDays_), Days);
107
0
        return fixingDate;
108
0
    }
109
110
0
    inline Date InterestRateIndex::valueDate(const Date& fixingDate) const {
111
0
        QL_REQUIRE(isValidFixingDate(fixingDate),
112
0
                   fixingDate << " is not a valid fixing date");
113
0
        return fixingCalendar().advance(fixingDate, fixingDays_, Days);
114
0
    }
115
}
116
117
#endif