QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
russia.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) 2010 StatPro Italia srl
5 Copyright (C) 2015 Dmitri Nesteruk
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
22#include <ql/errors.hpp>
23
24namespace QuantLib {
25
27 // all calendar instances share the same implementation instance
28 static ext::shared_ptr<Calendar::Impl> settlementImpl(
30 static ext::shared_ptr<Calendar::Impl> exchangeImpl(
32
33 switch (market) {
34 case Settlement:
35 impl_ = settlementImpl;
36 break;
37 case MOEX:
38 impl_ = exchangeImpl;
39 break;
40 default:
41 QL_FAIL("unknown market");
42 }
43 }
44
45 namespace {
46
47 bool isExtraHolidaySettlementImpl(Day d, Month month, Year year) {
48 switch (year) {
49 case 2017:
50 switch (month) {
51 case February: return d == 24;
52 case May: return d == 8;
53 case November: return d == 6;
54 default: return false;
55 }
56 case 2018:
57 switch (month) {
58 case March: return d == 9;
59 case April: return d == 30;
60 case May: return d == 2;
61 case June: return d == 11;
62 case December: return d == 31;
63 default: return false;
64 }
65 case 2019:
66 switch (month) {
67 case May: return d == 2 || d == 3 || d == 10;
68 default: return false;
69 }
70 case 2020:
71 switch (month) {
72 case March: return d == 30 || d == 31;
73 case April: return d == 1 || d == 2 || d == 3;
74 case May: return d == 4 || d == 5;
75 default: return false;
76 }
77 default:
78 return false;
79 }
80 }
81
82 }
83
85 Weekday w = date.weekday();
86 Day d = date.dayOfMonth();
87 Month m = date.month();
88 Year y = date.year();
89 if (isWeekend(w)
90 // New Year's holidays
91 || (y <= 2005 && d <= 2 && m == January)
92 || (y >= 2005 && d <= 5 && m == January)
93 // in 2012, the 6th was also a holiday
94 || (y == 2012 && d == 6 && m == January)
95 // Christmas (possibly moved to Monday)
96 || ((d == 7 || ((d == 8 || d == 9) && w == Monday)) &&
97 m == January)
98 // Defender of the Fatherland Day (possibly moved to Monday)
99 || ((d == 23 || ((d == 24 || d == 25) && w == Monday)) &&
100 m == February)
101 // International Women's Day (possibly moved to Monday)
102 || ((d == 8 || ((d == 9 || d == 10) && w == Monday)) &&
103 m == March)
104 // Labour Day (possibly moved to Monday)
105 || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) &&
106 m == May)
107 // Victory Day (possibly moved to Monday)
108 || ((d == 9 || ((d == 10 || d == 11) && w == Monday)) &&
109 m == May)
110 // Russia Day (possibly moved to Monday)
111 || ((d == 12 || ((d == 13 || d == 14) && w == Monday)) &&
112 m == June)
113 // Unity Day (possibly moved to Monday)
114 || ((d == 4 || ((d == 5 || d == 6) && w == Monday)) &&
115 m == November))
116 return false; // NOLINT(readability-simplify-boolean-expr)
117
118 if (isExtraHolidaySettlementImpl(d,m,y))
119 return false;
120
121 return true;
122 }
123
124 namespace {
125
126 bool isWorkingWeekend(Day d, Month month, Year year) {
127 switch (year) {
128 case 2012:
129 switch (month) {
130 case March: return d == 11;
131 case April: return d == 28;
132 case May: return d == 5 || d == 12;
133 case June: return d == 9;
134 default: return false;
135 }
136 case 2016:
137 switch (month)
138 {
139 case February: return d == 20;
140 default: return false;
141 }
142 case 2018:
143 switch (month) {
144 case April: return d == 28;
145 case June: return d == 9;
146 case December: return d == 29;
147 default: return false;
148 }
149 default:
150 return false;
151 }
152 }
153
154 bool isExtraHolidayExchangeImpl(Day d, Month month, Year year) {
155 switch (year) {
156 case 2012:
157 switch (month) {
158 case January: return d == 2;
159 case March: return d == 9;
160 case April: return d == 30;
161 case June: return d == 11;
162 default: return false;
163 }
164 case 2013:
165 switch (month) {
166 case January: return d == 1 || d == 2 || d == 3
167 || d == 4 || d == 7;
168 default: return false;
169 }
170 case 2014:
171 switch (month) {
172 case January: return d == 1 || d == 2 || d == 3 || d == 7;
173 default: return false;
174 }
175 case 2015:
176 switch (month) {
177 case January: return d == 1 || d == 2 || d == 7;
178 default: return false;
179 }
180 case 2016:
181 switch (month)
182 {
183 case January: return d == 1 || d == 7 || d == 8;
184 case May: return d == 2 || d == 3;
185 case June: return d == 13;
186 case December: return d == 30;
187 default: return false;
188 }
189 case 2017:
190 switch (month) {
191 case January: return d == 2;
192 case May: return d == 8;
193 default: return false;
194 }
195 case 2018:
196 switch (month) {
197 case January: return d == 1 || d == 2 || d == 8;
198 case December: return d == 31;
199 default: return false;
200 }
201 case 2019:
202 switch (month) {
203 case January: return d == 1 || d == 2 || d == 7;
204 case December: return d == 31;
205 default: return false;
206 }
207 case 2020:
208 switch (month) {
209 case January: return d == 1 || d == 2 || d == 7;
210 case February: return d == 24;
211 case June: return d == 24;
212 case July: return d == 1;
213 default: return false;
214 }
215 default:
216 return false;
217 }
218 }
219
220 }
221
223 Weekday w = date.weekday();
224 Day d = date.dayOfMonth();
225 Month m = date.month();
226 Year y = date.year();
227
228 // the exchange was formally established in 2011, so data are only
229 // available from 2012 to present
230 if (y < 2012)
231 QL_FAIL("MOEX calendar for the year " << y
232 << " does not exist.");
233
234 if (isWorkingWeekend(d,m,y))
235 return true;
236
237 // Known holidays
238 if (isWeekend(w)
239 // Defender of the Fatherland Day
240 || (d == 23 && m == February)
241 // International Women's Day (possibly moved to Monday)
242 || ((d == 8 || ((d == 9 || d == 10) && w == Monday)) && m == March)
243 // Labour Day
244 || (d == 1 && m == May)
245 // Victory Day (possibly moved to Monday)
246 || ((d == 9 || ((d == 10 || d == 11) && w == Monday)) && m == May)
247 // Russia Day
248 || (d == 12 && m == June)
249 // Unity Day (possibly moved to Monday)
250 || ((d == 4 || ((d == 5 || d == 6) && w == Monday))
251 && m == November)
252 // New Years Eve
253 || (d == 31 && m == December))
254 return false;
255
256 if (isExtraHolidayExchangeImpl(d,m,y))
257 return false;
258
259 return true;
260 }
261
262}
bool isWeekend(Weekday) const override
Definition: calendar.cpp:237
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: russia.cpp:222
bool isBusinessDay(const Date &) const override
Definition: russia.cpp:84
Russia(Market=Settlement)
Definition: russia.cpp:26
Market
Russian calendars.
Definition: russia.hpp:72
@ MOEX
Moscow Exchange calendar.
Definition: russia.hpp:73
@ Settlement
generic settlement calendar
Definition: russia.hpp:72
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
@ 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
@ June
Definition: date.hpp:62
@ Monday
Definition: weekday.hpp:42
Definition: any.hpp:35
Russian calendar.