QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
italy.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004 StatPro Italia srl
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
21#include <ql/errors.hpp>
22
23namespace QuantLib {
24
26 // all calendar instances on the same market share the same
27 // implementation instance
28 static ext::shared_ptr<Calendar::Impl> settlementImpl(
30 static ext::shared_ptr<Calendar::Impl> exchangeImpl(
32 switch (market) {
33 case Settlement:
34 impl_ = settlementImpl;
35 break;
36 case Exchange:
37 impl_ = exchangeImpl;
38 break;
39 default:
40 QL_FAIL("unknown market");
41 }
42 }
43
44
46 Weekday w = date.weekday();
47 Day d = date.dayOfMonth(), dd = date.dayOfYear();
48 Month m = date.month();
49 Year y = date.year();
50 Day em = easterMonday(y);
51 if (isWeekend(w)
52 // New Year's Day
53 || (d == 1 && m == January)
54 // Epiphany
55 || (d == 6 && m == January)
56 // Easter Monday
57 || (dd == em)
58 // Liberation Day
59 || (d == 25 && m == April)
60 // Labour Day
61 || (d == 1 && m == May)
62 // Republic Day
63 || (d == 2 && m == June && y >= 2000)
64 // Assumption
65 || (d == 15 && m == August)
66 // All Saints' Day
67 || (d == 1 && m == November)
68 // Immaculate Conception
69 || (d == 8 && m == December)
70 // Christmas
71 || (d == 25 && m == December)
72 // St. Stephen
73 || (d == 26 && m == December)
74 // December 31st, 1999 only
75 || (d == 31 && m == December && y == 1999))
76 return false; // NOLINT(readability-simplify-boolean-expr)
77 return true;
78 }
79
80
81 bool Italy::ExchangeImpl::isBusinessDay(const Date& date) const {
82 Weekday w = date.weekday();
83 Day d = date.dayOfMonth(), dd = date.dayOfYear();
84 Month m = date.month();
85 Year y = date.year();
86 Day em = easterMonday(y);
87 if (isWeekend(w)
88 // New Year's Day
89 || (d == 1 && m == January)
90 // Good Friday
91 || (dd == em-3)
92 // Easter Monday
93 || (dd == em)
94 // Labour Day
95 || (d == 1 && m == May)
96 // Assumption
97 || (d == 15 && m == August)
98 // Christmas' Eve
99 || (d == 24 && m == December)
100 // Christmas
101 || (d == 25 && m == December)
102 // St. Stephen
103 || (d == 26 && m == December)
104 // New Year's Eve
105 || (d == 31 && m == December))
106 return false; // NOLINT(readability-simplify-boolean-expr)
107 return true;
108 }
109
110}
111
static Day easterMonday(Year)
expressed relative to first day of year
Definition: calendar.cpp:199
bool isWeekend(Weekday) const override
Definition: calendar.cpp:195
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
Day dayOfYear() const
One-based (Jan 1st = 1)
Definition: date.hpp:404
bool isBusinessDay(const Date &) const override
Definition: italy.cpp:81
bool isBusinessDay(const Date &) const override
Definition: italy.cpp:45
Italy(Market market=Settlement)
Definition: italy.cpp:25
Market
Italian calendars.
Definition: italy.hpp:84
@ Settlement
generic settlement calendar
Definition: italy.hpp:84
@ Exchange
Milan stock-exchange calendar.
Definition: italy.hpp:85
Classes and functions for error handling.
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
Date d
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
@ May
Definition: date.hpp:61
@ April
Definition: date.hpp:60
@ November
Definition: date.hpp:67
@ June
Definition: date.hpp:62
Italian calendars.
Definition: any.hpp:35