Coverage Report

Created: 2025-10-14 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/indexes/iborindex.cpp
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, 2008, 2009 StatPro Italia srl
6
 Copyright (C) 2009 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
#include <ql/indexes/iborindex.hpp>
23
#include <ql/termstructures/yieldtermstructure.hpp>
24
#include <utility>
25
26
namespace QuantLib {
27
28
    IborIndex::IborIndex(const std::string& familyName,
29
                         const Period& tenor,
30
                         Natural settlementDays,
31
                         const Currency& currency,
32
                         const Calendar& fixingCalendar,
33
                         BusinessDayConvention convention,
34
                         bool endOfMonth,
35
                         const DayCounter& dayCounter,
36
                         Handle<YieldTermStructure> h)
37
0
    : InterestRateIndex(familyName, tenor, settlementDays, currency, fixingCalendar, dayCounter),
38
0
      convention_(convention), termStructure_(std::move(h)), endOfMonth_(endOfMonth) {
39
0
        registerWith(termStructure_);
40
0
    }
41
42
0
    Rate IborIndex::forecastFixing(const Date& fixingDate) const {
43
0
        Date d1 = valueDate(fixingDate);
44
0
        Date d2 = maturityDate(d1);
45
0
        Time t = dayCounter_.yearFraction(d1, d2);
46
0
        QL_REQUIRE(t>0.0,
47
0
                   "\n cannot calculate forward rate between " <<
48
0
                   d1 << " and " << d2 <<
49
0
                   ":\n non positive time (" << t <<
50
0
                   ") using " << dayCounter_.name() << " daycounter");
51
0
        return forecastFixing(d1, d2, t);
52
0
    }
53
54
0
    Date IborIndex::maturityDate(const Date& valueDate) const {
55
0
        return fixingCalendar().advance(valueDate,
56
0
                                        tenor_,
57
0
                                        convention_,
58
0
                                        endOfMonth_);
59
0
    }
60
61
    ext::shared_ptr<IborIndex> IborIndex::clone(
62
0
                               const Handle<YieldTermStructure>& h) const {
63
0
        return ext::make_shared<IborIndex>(
64
0
                                        familyName(),
65
0
                                                      tenor(),
66
0
                                                      fixingDays(),
67
0
                                                      currency(),
68
0
                                                      fixingCalendar(),
69
0
                                                      businessDayConvention(),
70
0
                                                      endOfMonth(),
71
0
                                                      dayCounter(),
72
0
                                                      h);
73
0
    }
74
75
76
    OvernightIndex::OvernightIndex(const std::string& familyName,
77
                                   Natural settlementDays,
78
                                   const Currency& curr,
79
                                   const Calendar& fixCal,
80
                                   const DayCounter& dc,
81
                                   const Handle<YieldTermStructure>& h)
82
0
   : IborIndex(familyName, 1*Days, settlementDays, curr,
83
0
               fixCal, Following, false, dc, h) {}
84
85
    ext::shared_ptr<IborIndex> OvernightIndex::clone(
86
0
                               const Handle<YieldTermStructure>& h) const {
87
0
        return ext::shared_ptr<IborIndex>(
88
0
                                        new OvernightIndex(familyName(),
89
0
                                                           fixingDays(),
90
0
                                                           currency(),
91
0
                                                           fixingCalendar(),
92
0
                                                           dayCounter(),
93
0
                                                           h));
94
0
    }
95
96
}