-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add public holidays calendars for Ukraine, UK, and US
Added implementation of public holidays for Ukraine, the UK, and the US in the third-party calendar module. Including various markets and special closures days. Calendar functionality was expanded to indicate business days specific to these countries. This will aid in accurate business day calculations for these markets. Test cases were also added to validate the accuracy of the holidays and business days implemented.
- Loading branch information
1 parent
aee8b8a
commit d4617f0
Showing
52 changed files
with
7,220 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
pub enum DateRolling { | ||
Unadjusted, | ||
Following, | ||
ModifiedFollowing, | ||
Preceding, | ||
ModifiedPreceding, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::date::Date; | ||
|
||
pub trait Calendar { | ||
fn is_business_day(&self, date: Date) -> bool; | ||
|
||
fn is_holiday(&self, date: Date) -> bool { | ||
!self.is_business_day(date) | ||
} | ||
} | ||
|
||
impl<C: calendar::Calendar> Calendar for C { | ||
fn is_business_day(&self, date: Date) -> bool { | ||
self.is_business_day(date.0) | ||
} | ||
|
||
fn is_holiday(&self, date: Date) -> bool { | ||
self.is_holiday(date.0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
mod business_day_convention; | ||
// mod calendar; | ||
mod calendar; | ||
pub mod date; | ||
pub mod day_count; | ||
pub mod frequency; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 hnakashima | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
The externally maintained library from which parts of the Software is derived | ||
is: | ||
- finquant, licensed as follows: | ||
""" | ||
MIT License | ||
|
||
Copyright (c) 2023 Jeremy Wang | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Holidays in Argentina. | ||
|
||
use crate::Calendar; | ||
use chrono::{NaiveDate, Weekday}; | ||
|
||
#[derive(Default, Debug)] | ||
pub struct Argentina; | ||
|
||
impl Calendar for Argentina { | ||
fn is_business_day(&self, date: NaiveDate) -> bool { | ||
let (d, w, m, y, dd) = self.naive_date_to_dkmy(date); | ||
let em = self.easter_monday(y); | ||
|
||
if self.is_weekend(date) | ||
// New Year's Day | ||
|| (d == 1 && m == 1) | ||
// Holy Thursday | ||
|| (dd == em - 4) | ||
// Good Weekday::Fri | ||
|| (dd == em - 3) | ||
// Labour Day | ||
|| (d == 1 && m == 5) | ||
// 5 Revolution | ||
|| (d == 25 && m == 5) | ||
// Death of General Manuel Belgrano | ||
|| ((15..=21).contains(&d) && w == Weekday::Mon && m == 6) | ||
// Independence Day | ||
|| (d == 9 && m == 7) | ||
// Death of General José de San Martín | ||
|| ((15..=21).contains(&d) && w == Weekday::Mon && m == 8) | ||
// Columbus Day | ||
|| ((d == 10 || d == 11 || d == 12 || d == 15 || d == 16) | ||
&& w == Weekday::Mon && m == 10) | ||
// Immaculate Conception | ||
|| (d == 8 && m == 12) | ||
// Christmas Eve | ||
|| (d == 24 && m == 12) | ||
// New Year's Eve | ||
|| ((d == 31 || (d == 30 && w == Weekday::Fri)) && m == 12) | ||
{ | ||
return false; | ||
} | ||
true | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::Argentina; | ||
use crate::Calendar; | ||
use chrono::{Duration, NaiveDate}; | ||
|
||
#[test] | ||
fn test_mexico_holiday() { | ||
// Test all results from 2023-01-01 to 2023-12-31 | ||
let expected_results_for_2023 = vec![ | ||
false, true, true, true, true, true, false, false, true, true, true, true, true, false, | ||
false, true, true, true, true, true, false, false, true, true, true, true, true, false, | ||
false, true, true, true, true, true, false, false, true, true, true, true, true, false, | ||
false, true, true, true, true, true, false, false, true, true, true, true, true, false, | ||
false, true, true, true, true, true, false, false, true, true, true, true, true, false, | ||
false, true, true, true, true, true, false, false, true, true, true, true, true, false, | ||
false, true, true, true, true, true, false, false, true, true, true, false, false, | ||
false, false, true, true, true, true, true, false, false, true, true, true, true, true, | ||
false, false, true, true, true, true, true, false, false, false, true, true, true, | ||
true, false, false, true, true, true, true, true, false, false, true, true, true, true, | ||
true, false, false, true, true, true, false, true, false, false, true, true, true, | ||
true, true, false, false, true, true, true, true, true, false, false, true, true, true, | ||
true, true, false, false, false, true, true, true, true, false, false, true, true, | ||
true, true, true, false, false, true, true, true, true, true, false, false, true, true, | ||
true, true, true, false, false, true, true, true, true, true, false, false, true, true, | ||
true, true, true, false, false, true, true, true, true, true, false, false, true, true, | ||
true, true, true, false, false, true, true, true, true, true, false, false, false, | ||
true, true, true, true, false, false, true, true, true, true, true, false, false, true, | ||
true, true, true, true, false, false, true, true, true, true, true, false, false, true, | ||
true, true, true, true, false, false, true, true, true, true, true, false, false, true, | ||
true, true, true, true, false, false, true, true, true, true, true, false, false, | ||
false, true, true, true, true, false, false, true, true, true, true, true, false, | ||
false, true, true, true, true, true, false, false, true, true, true, true, true, false, | ||
false, true, true, true, true, true, false, false, true, true, true, true, true, false, | ||
false, true, true, true, true, true, false, false, true, true, true, true, false, | ||
false, false, true, true, true, true, true, false, false, true, true, true, true, true, | ||
false, false, true, true, true, true, true, false, false, | ||
]; | ||
let first_date = NaiveDate::from_ymd_opt(2023, 1, 1).unwrap(); | ||
for n in 0i32..365 { | ||
let target_date = first_date + Duration::days(i64::from(n)); | ||
let expected = expected_results_for_2023[n as usize]; | ||
assert_eq!(Argentina.is_business_day(target_date), expected); | ||
} | ||
} | ||
} |
Oops, something went wrong.