QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
japan.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000-2003 RiskMap srl
5 Copyright (C) 2003 Kawanishi Tomoya
6 Copyright (C) 2016, 2019, 2020 Eisuke Tani
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 <http://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/time/calendars/japan.hpp>
23
24namespace QuantLib {
25
27 // all calendar instances share the same implementation instance
28 static ext::shared_ptr<Calendar::Impl> impl(new Japan::Impl);
29 impl_ = impl;
30 }
31
33 return w == Saturday || w == Sunday;
34 }
35
36 bool Japan::Impl::isBusinessDay(const Date& date) const {
37 Weekday w = date.weekday();
38 Day d = date.dayOfMonth();
39 Month m = date.month();
40 Year y = date.year();
41 // equinox calculation
42 const Time exact_vernal_equinox_time = 20.69115;
43 const Time exact_autumnal_equinox_time = 23.09;
44 const Time diff_per_year = 0.242194;
45 const Time moving_amount = (y-2000)*diff_per_year;
46 Integer number_of_leap_years = (y-2000)/4+(y-2000)/100-(y-2000)/400;
47 Day ve = // vernal equinox day
48 Day(exact_vernal_equinox_time
49 + moving_amount - number_of_leap_years);
50 Day ae = // autumnal equinox day
51 Day(exact_autumnal_equinox_time
52 + moving_amount - number_of_leap_years);
53 // checks
54 if (isWeekend(w)
55 // New Year's Day
56 || (d == 1 && m == January)
57 // Bank Holiday
58 || (d == 2 && m == January)
59 // Bank Holiday
60 || (d == 3 && m == January)
61 // Coming of Age Day (2nd Monday in January),
62 // was January 15th until 2000
63 || (w == Monday && (d >= 8 && d <= 14) && m == January
64 && y >= 2000)
65 || ((d == 15 || (d == 16 && w == Monday)) && m == January
66 && y < 2000)
67 // National Foundation Day
68 || ((d == 11 || (d == 12 && w == Monday)) && m == February)
69 // Emperor's Birthday (Emperor Naruhito)
70 || ((d == 23 || (d == 24 && w == Monday)) && m == February
71 && y >= 2020)
72 // Emperor's Birthday (Emperor Akihito)
73 || ((d == 23 || (d == 24 && w == Monday)) && m == December
74 && (y >= 1989 && y < 2019))
75 // Vernal Equinox
76 || ((d == ve || (d == ve+1 && w == Monday)) && m == March)
77 // Greenery Day
78 || ((d == 29 || (d == 30 && w == Monday)) && m == April)
79 // Constitution Memorial Day
80 || (d == 3 && m == May)
81 // Holiday for a Nation
82 || (d == 4 && m == May)
83 // Children's Day
84 || (d == 5 && m == May)
85 // any of the three above observed later if on Saturday or Sunday
86 || (d == 6 && m == May
87 && (w == Monday || w == Tuesday || w == Wednesday))
88 // Marine Day (3rd Monday in July),
89 // was July 20th until 2003, not a holiday before 1996,
90 // July 23rd in 2020 due to Olympics games
91 // July 22nd in 2021 due to Olympics games
92 || (w == Monday && (d >= 15 && d <= 21) && m == July
93 && ((y >= 2003 && y < 2020) || y >= 2022))
94 || ((d == 20 || (d == 21 && w == Monday)) && m == July
95 && y >= 1996 && y < 2003)
96 || (d == 23 && m == July && y == 2020)
97 || (d == 22 && m == July && y == 2021)
98 // Mountain Day
99 // (moved in 2020 due to Olympics games)
100 // (moved in 2021 due to Olympics games)
101 || ((d == 11 || (d == 12 && w == Monday)) && m == August
102 && ((y >= 2016 && y < 2020) || y >= 2022))
103 || (d == 10 && m == August && y == 2020)
104 || (d == 9 && m == August && y == 2021)
105 // Respect for the Aged Day (3rd Monday in September),
106 // was September 15th until 2003
107 || (w == Monday && (d >= 15 && d <= 21) && m == September
108 && y >= 2003)
109 || ((d == 15 || (d == 16 && w == Monday)) && m == September
110 && y < 2003)
111 // If a single day falls between Respect for the Aged Day
112 // and the Autumnal Equinox, it is holiday
113 || (w == Tuesday && d+1 == ae && d >= 16 && d <= 22
114 && m == September && y >= 2003)
115 // Autumnal Equinox
116 || ((d == ae || (d == ae+1 && w == Monday)) && m == September)
117 // Health and Sports Day (2nd Monday in October),
118 // was October 10th until 2000,
119 // July 24th in 2020 due to Olympics games
120 // July 23rd in 2021 due to Olympics games
121 || (w == Monday && (d >= 8 && d <= 14) && m == October
122 && ((y >= 2000 && y < 2020) || y >= 2022))
123 || ((d == 10 || (d == 11 && w == Monday)) && m == October
124 && y < 2000)
125 || (d == 24 && m == July && y == 2020)
126 || (d == 23 && m == July && y == 2021)
127 // National Culture Day
128 || ((d == 3 || (d == 4 && w == Monday)) && m == November)
129 // Labor Thanksgiving Day
130 || ((d == 23 || (d == 24 && w == Monday)) && m == November)
131 // Bank Holiday
132 || (d == 31 && m == December)
133 // one-shot holidays
134 // Marriage of Prince Akihito
135 || (d == 10 && m == April && y == 1959)
136 // Rites of Imperial Funeral
137 || (d == 24 && m == February && y == 1989)
138 // Enthronement Ceremony (Emperor Akihito)
139 || (d == 12 && m == November && y == 1990)
140 // Marriage of Prince Naruhito
141 || (d == 9 && m == June && y == 1993)
142 // Special holiday based on Japanese public holidays law
143 || (d == 30 && m == April && y == 2019)
144 // Enthronement Day (Emperor Naruhito)
145 || (d == 1 && m == May && y == 2019)
146 // Special holiday based on Japanese public holidays law
147 || (d == 2 && m == May && y == 2019)
148 // Enthronement Ceremony (Emperor Naruhito)
149 || (d == 22 && m == October && y == 2019))
150 return false; // NOLINT(readability-simplify-boolean-expr)
151 return true;
152 }
153
154}
bool isWeekend(Weekday w) const
Definition: calendar.hpp:255
ext::shared_ptr< Impl > impl_
Definition: calendar.hpp:72
Concrete date class.
Definition: date.hpp:125
Month month() const
Definition: date.cpp:82
Year year() const
Definition: date.cpp:93
Day dayOfMonth() const
Definition: date.hpp:400
Weekday weekday() const
Definition: date.hpp:395
bool isBusinessDay(const Date &) const override
Definition: japan.cpp:36
bool isWeekend(Weekday) const override
Definition: japan.cpp:32
Integer Year
Year number.
Definition: date.hpp:87
Integer Day
Day number.
Definition: date.hpp:53
Month
Month names.
Definition: date.hpp:57
@ December
Definition: date.hpp:68
@ August
Definition: date.hpp:64
@ January
Definition: date.hpp:57
@ July
Definition: date.hpp:63
@ May
Definition: date.hpp:61
@ March
Definition: date.hpp:59
@ February
Definition: date.hpp:58
@ April
Definition: date.hpp:60
@ November
Definition: date.hpp:67
@ October
Definition: date.hpp:66
@ June
Definition: date.hpp:62
@ September
Definition: date.hpp:65
@ Wednesday
Definition: weekday.hpp:44
@ Monday
Definition: weekday.hpp:42
@ Sunday
Definition: weekday.hpp:41
@ Tuesday
Definition: weekday.hpp:43
@ Saturday
Definition: weekday.hpp:47
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Definition: any.hpp:35