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

lballabio / QuantLib / 14910176578

08 May 2025 03:28PM UTC coverage: 73.315% (+0.02%) from 73.3%
14910176578

Pull #2195

github

web-flow
Merge 3a61f499c into 5d972fb7b
Pull Request #2195: Added `Handle<Quote>` for spread in `OISRateHelper`

32 of 33 new or added lines in 2 files covered. (96.97%)

277 existing lines in 25 files now uncovered.

56277 of 76761 relevant lines covered (73.31%)

8687029.35 hits per line

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

90.91
/ql/time/daycounters/actual365fixed.cpp
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) 2013 BGC Partners L.P.
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
 <http://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
#include <ql/time/daycounters/actual365fixed.hpp>
22
#include <cmath>
23

24
namespace QuantLib {
25

26
    ext::shared_ptr<DayCounter::Impl>
27
    Actual365Fixed::implementation(Actual365Fixed::Convention c) {
535,278✔
28
        switch (c) {
535,278✔
29
          case Standard:
535,275✔
30
            return ext::shared_ptr<DayCounter::Impl>(new Impl);
535,275✔
31
          case Canadian:
2✔
32
            return ext::shared_ptr<DayCounter::Impl>(new CA_Impl);
2✔
33
          case NoLeap:
1✔
34
            return ext::shared_ptr<DayCounter::Impl>(new NL_Impl);
1✔
35
          default:
×
36
            QL_FAIL("unknown Actual/365 (Fixed) convention");
×
37
        }
38
    }
39

40
    Time Actual365Fixed::CA_Impl::yearFraction(const Date& d1,
6✔
41
                                               const Date& d2,
42
                                               const Date& refPeriodStart,
43
                                               const Date& refPeriodEnd) const {
44
        if (d1 == d2)
6✔
45
            return 0.0;
46

47
        // We need the period to calculate the frequency
48
        QL_REQUIRE(refPeriodStart != Date(), "invalid refPeriodStart");
8✔
49
        QL_REQUIRE(refPeriodEnd != Date(), "invalid refPeriodEnd");
5✔
50

51
        Time dcs = daysBetween(d1,d2);
52
        Time dcc = daysBetween(refPeriodStart,refPeriodEnd);
53
        auto months = Integer(std::lround(12 * dcc / 365));
5✔
54
        QL_REQUIRE(months != 0,
7✔
55
                   "invalid reference period for Act/365 Canadian; "
56
                   "must be longer than a month");
57
        auto frequency = Integer(12 / months);
4✔
58
        QL_REQUIRE(frequency != 0,
6✔
59
                   "invalid reference period for Act/365 Canadian; "
60
                   "must not be longer than a year");
61

62
        if (dcs < Integer(365/frequency))
3✔
UNCOV
63
            return dcs/365.0;
×
64

65
        return 1./frequency - (dcc-dcs)/365.0;
3✔
66

67
    }
68

69
    Date::serial_type Actual365Fixed::NL_Impl::dayCount(const Date& d1,
4,360✔
70
                                                        const Date& d2) const {
71

72
        static const Integer MonthOffset[] = {
73
            0,  31,  59,  90, 120, 151,  // Jan - Jun
74
            181, 212, 243, 273, 304, 334   // Jun - Dec
75
        };
76

77
        Date::serial_type s1 = d1.dayOfMonth()
4,360✔
78
                             + MonthOffset[d1.month()-1] + (d1.year() * 365);
4,360✔
79
        Date::serial_type s2 = d2.dayOfMonth()
4,360✔
80
                             + MonthOffset[d2.month()-1] + (d2.year() * 365);
4,360✔
81

82
        if (d1.month() == Feb && d1.dayOfMonth() == 29) {
4,360✔
83
            --s1;
4✔
84
        }
85

86
        if (d2.month() == Feb && d2.dayOfMonth() == 29) {
4,360✔
87
            --s2;
1✔
88
        }
89

90
        return s2 - s1;
4,360✔
91
    }
92

93
    Time Actual365Fixed::NL_Impl::yearFraction(const Date& d1,
4,360✔
94
                                               const Date& d2,
95
                                               const Date& d3,
96
                                               const Date& d4) const {
97
        return dayCount(d1, d2)/365.0;
4,360✔
98
    }
99

100
}
101

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

© 2025 Coveralls, Inc