Coverage Report

Created: 2025-12-08 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/time/calendars/canada.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) 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
#include <ql/time/calendars/canada.hpp>
22
#include <ql/errors.hpp>
23
24
namespace QuantLib {
25
26
0
    Canada::Canada(Canada::Market market) {
27
        // all calendar instances share the same implementation instance
28
0
        static ext::shared_ptr<Calendar::Impl> settlementImpl(
29
0
                                                  new Canada::SettlementImpl);
30
0
        static ext::shared_ptr<Calendar::Impl> tsxImpl(new Canada::TsxImpl);
31
0
        switch (market) {
32
0
          case Settlement:
33
0
            impl_ = settlementImpl;
34
0
            break;
35
0
          case TSX:
36
0
            impl_ = tsxImpl;
37
0
            break;
38
0
          default:
39
0
            QL_FAIL("unknown market");
40
0
        }
41
0
    }
42
43
0
    bool Canada::SettlementImpl::isBusinessDay(const Date& date) const {
44
0
        Weekday w = date.weekday();
45
0
        Day d = date.dayOfMonth(), dd = date.dayOfYear();
46
0
        Month m = date.month();
47
0
        Year y = date.year();
48
0
        Day em = easterMonday(y);
49
0
        if (isWeekend(w)
50
            // New Year's Day (possibly moved to Monday)
51
0
            || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) && m == January)
52
            // Family Day (third Monday in February, since 2008)
53
0
            || ((d >= 15 && d <= 21) && w == Monday && m == February
54
0
                && y >= 2008)
55
            // Good Friday
56
0
            || (dd == em-3)
57
            // The Monday on or preceding 24 May (Victoria Day)
58
0
            || (d > 17 && d <= 24 && w == Monday && m == May)
59
            // July 1st, possibly moved to Monday (Canada Day)
60
0
            || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) && m==July)
61
            // first Monday of August (Provincial Holiday)
62
0
            || (d <= 7 && w == Monday && m == August)
63
            // first Monday of September (Labor Day)
64
0
            || (d <= 7 && w == Monday && m == September)
65
            // September 30th, possibly moved to Monday
66
            // (National Day for Truth and Reconciliation, since 2021)
67
0
            || (((d == 30 && m == September) || (d <= 2 && m == October && w == Monday)) && y >= 2021)
68
            // second Monday of October (Thanksgiving Day)
69
0
            || (d > 7 && d <= 14 && w == Monday && m == October)
70
            // November 11th (possibly moved to Monday)
71
0
            || ((d == 11 || ((d == 12 || d == 13) && w == Monday))
72
0
                && m == November)
73
            // Christmas (possibly moved to Monday or Tuesday)
74
0
            || ((d == 25 || (d == 27 && (w == Monday || w == Tuesday)))
75
0
                && m == December)
76
            // Boxing Day (possibly moved to Monday or Tuesday)
77
0
            || ((d == 26 || (d == 28 && (w == Monday || w == Tuesday)))
78
0
                && m == December)
79
0
            )
80
0
            return false; // NOLINT(readability-simplify-boolean-expr)
81
0
        return true;
82
0
    }
83
84
0
    bool Canada::TsxImpl::isBusinessDay(const Date& date) const {
85
0
        Weekday w = date.weekday();
86
0
        Day d = date.dayOfMonth(), dd = date.dayOfYear();
87
0
        Month m = date.month();
88
0
        Year y = date.year();
89
0
        Day em = easterMonday(y);
90
0
        if (isWeekend(w)
91
            // New Year's Day (possibly moved to Monday)
92
0
            || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) && m == January)
93
            // Family Day (third Monday in February, since 2008)
94
0
            || ((d >= 15 && d <= 21) && w == Monday && m == February
95
0
                && y >= 2008)
96
            // Good Friday
97
0
            || (dd == em-3)
98
            // The Monday on or preceding 24 May (Victoria Day)
99
0
            || (d > 17 && d <= 24 && w == Monday && m == May)
100
            // July 1st, possibly moved to Monday (Canada Day)
101
0
            || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) && m==July)
102
            // first Monday of August (Provincial Holiday)
103
0
            || (d <= 7 && w == Monday && m == August)
104
            // first Monday of September (Labor Day)
105
0
            || (d <= 7 && w == Monday && m == September)
106
            // second Monday of October (Thanksgiving Day)
107
0
            || (d > 7 && d <= 14 && w == Monday && m == October)
108
            // Christmas (possibly moved to Monday or Tuesday)
109
0
            || ((d == 25 || (d == 27 && (w == Monday || w == Tuesday)))
110
0
                && m == December)
111
            // Boxing Day (possibly moved to Monday or Tuesday)
112
0
            || ((d == 26 || (d == 28 && (w == Monday || w == Tuesday)))
113
0
                && m == December)
114
0
            )
115
0
            return false; // NOLINT(readability-simplify-boolean-expr)
116
0
        return true;
117
0
    }
118
119
}