From 00d82135b19c20cd46bde179055af10566f50af5 Mon Sep 17 00:00:00 2001 From: avhz Date: Sat, 23 Nov 2024 00:54:38 +0100 Subject: [PATCH] docs: fix ISO 10383 constants docs --- Cargo.toml | 1 + crates/RustQuant_iso/src/iso_10383.rs | 7 +- crates/RustQuant_time/src/calendar.rs | 56 +------ .../{south_america => }/argentina.rs | 4 + .../src/countries/{oceania => }/australia.rs | 11 ++ .../src/countries/{europe => }/austria.rs | 4 + .../src/countries/{africa => }/botswana.rs | 4 + .../countries/{south_america => }/brazil.rs | 4 + .../countries/{north_america => }/canada.rs | 4 + .../countries/{south_america => }/chile.rs | 4 + .../src/countries/{asia => }/china.rs | 4 + .../countries/{europe => }/czech_republic.rs | 4 + .../src/countries/{europe => }/denmark.rs | 4 + .../src/countries/{europe => }/finland.rs | 4 + .../src/countries/{europe => }/france.rs | 4 + .../src/countries/{europe => }/germany.rs | 4 + .../src/countries/{asia => }/hong_kong.rs | 4 + .../src/countries/{europe => }/hungary.rs | 4 + .../src/countries/{europe => }/iceland.rs | 4 + .../src/countries/{asia => }/india.rs | 4 + .../src/countries/{asia => }/indonesia.rs | 4 + .../src/countries/{middle_east => }/israel.rs | 4 + crates/RustQuant_time/src/countries/mexico.rs | 136 ++++++++++++++++ crates/RustQuant_time/src/countries/mod.rs | 152 +++++++++--------- .../src/countries/{europe => }/netherlands.rs | 4 + .../countries/{oceania => }/new_zealand.rs | 4 + .../src/countries/north_america/mexico.rs | 132 --------------- .../src/countries/{asia => }/singapore.rs | 4 + .../countries/{europe => }/united_kingdom.rs | 4 + .../{north_america => }/united_states.rs | 4 + examples/examples/curves_discount.rs | 5 +- examples/examples/curves_spot.rs | 4 +- examples/examples/market_data.rs | 4 +- examples/examples/schedule.rs | 5 +- 34 files changed, 334 insertions(+), 271 deletions(-) rename crates/RustQuant_time/src/countries/{south_america => }/argentina.rs (98%) rename crates/RustQuant_time/src/countries/{oceania => }/australia.rs (96%) rename crates/RustQuant_time/src/countries/{europe => }/austria.rs (99%) rename crates/RustQuant_time/src/countries/{africa => }/botswana.rs (98%) rename crates/RustQuant_time/src/countries/{south_america => }/brazil.rs (98%) rename crates/RustQuant_time/src/countries/{north_america => }/canada.rs (99%) rename crates/RustQuant_time/src/countries/{south_america => }/chile.rs (98%) rename crates/RustQuant_time/src/countries/{asia => }/china.rs (99%) rename crates/RustQuant_time/src/countries/{europe => }/czech_republic.rs (98%) rename crates/RustQuant_time/src/countries/{europe => }/denmark.rs (99%) rename crates/RustQuant_time/src/countries/{europe => }/finland.rs (98%) rename crates/RustQuant_time/src/countries/{europe => }/france.rs (98%) rename crates/RustQuant_time/src/countries/{europe => }/germany.rs (98%) rename crates/RustQuant_time/src/countries/{asia => }/hong_kong.rs (99%) rename crates/RustQuant_time/src/countries/{europe => }/hungary.rs (99%) rename crates/RustQuant_time/src/countries/{europe => }/iceland.rs (99%) rename crates/RustQuant_time/src/countries/{asia => }/india.rs (99%) rename crates/RustQuant_time/src/countries/{asia => }/indonesia.rs (99%) rename crates/RustQuant_time/src/countries/{middle_east => }/israel.rs (99%) create mode 100644 crates/RustQuant_time/src/countries/mexico.rs rename crates/RustQuant_time/src/countries/{europe => }/netherlands.rs (99%) rename crates/RustQuant_time/src/countries/{oceania => }/new_zealand.rs (98%) delete mode 100644 crates/RustQuant_time/src/countries/north_america/mexico.rs rename crates/RustQuant_time/src/countries/{asia => }/singapore.rs (99%) rename crates/RustQuant_time/src/countries/{europe => }/united_kingdom.rs (99%) rename crates/RustQuant_time/src/countries/{north_america => }/united_states.rs (99%) diff --git a/Cargo.toml b/Cargo.toml index 2ebbe108..fcd49035 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,6 +86,7 @@ derive_builder = "0.20.0" # https://docs.rs/derive_builder/latest/derive_build errorfunctions = "0.2.0" # https://docs.rs/errorfunctions/latest/errorfunctions/ finitediff = "0.1.4" # https://docs.rs/finitediff/latest/finitediff/ icu = "1.5.0" # https://docs.rs/icu/latest/icu/ +log = "0.4.22" # https://docs.rs/log/latest/log/ nalgebra = "0.33.0" # https://docs.rs/nalgebra/latest/nalgebra/ ndrustfft = "0.5.0" # https://docs.rs/ndrustfft/latest/ndrustfft/ ndarray-rand = "0.15.0" # https://docs.rs/ndarray-rand/latest/ndarray_rand/ diff --git a/crates/RustQuant_iso/src/iso_10383.rs b/crates/RustQuant_iso/src/iso_10383.rs index 91af43b3..4cf64aed 100644 --- a/crates/RustQuant_iso/src/iso_10383.rs +++ b/crates/RustQuant_iso/src/iso_10383.rs @@ -72,7 +72,12 @@ macro_rules! iso_10383 { $description:literal, )*) => { $( - /// $description + #[doc = concat!( + "**MIC: ", stringify!($mic), "** (Operating MIC: ", $operating_mic, ")\n\n", + "* Country Code: ", $iso_3166, "\n", + "* City: ", $city, "\n", + "* Status: ", stringify!($status) + )] pub const $mic: ISO_10383 = ISO_10383 { operating_mic: $operating_mic, country_code: $iso_3166, diff --git a/crates/RustQuant_time/src/calendar.rs b/crates/RustQuant_time/src/calendar.rs index 544af64a..d045e1ba 100644 --- a/crates/RustQuant_time/src/calendar.rs +++ b/crates/RustQuant_time/src/calendar.rs @@ -11,23 +11,13 @@ use crate::utilities::is_weekend; use time::Date; -use RustQuant_iso::{ISO_10383, ISO_3166}; - -/// Calendar metadata struct. -pub struct CalendarMetadata { - /// Name of the calendar, typically the country name, but could also be - /// a region/subdivision or a special calendar, such as a financial calendar (e.g. NYSE). - pub name: &'static str, - - /// ISO 3166-1 country code. - pub country_code: ISO_3166, - - /// ISO 10383 market identifier code. - pub market_identifier_code: ISO_10383, -} +use RustQuant_iso::*; /// Calendar trait. pub trait Calendar { + /// Create a new instance of the calendar. + fn new() -> Self; + /// Name of the calendar, typically the country name, but could also be /// a region/subdivision or a special calendar, such as a financial calendar (e.g. NYSE). fn name(&self) -> &'static str; @@ -50,7 +40,7 @@ pub trait Calendar { /// Function to list all holidays for a given range of `Date`s. fn all_holidays_between(&self, start_date: Date, end_date: Date) -> Vec { - let mut holidays = Vec::new(); + let mut holidays = Vec::with_capacity((end_date - start_date).whole_days() as usize); let mut temp_date = start_date; @@ -69,7 +59,7 @@ pub trait Calendar { /// Function to list all business days for a given range of `Date`s. fn all_business_days_between(&self, start_date: Date, end_date: Date) -> Vec { - let mut business_days = Vec::new(); + let mut business_days = Vec::with_capacity((end_date - start_date).whole_days() as usize); let mut temp_date = start_date; @@ -86,37 +76,3 @@ pub trait Calendar { business_days } } - -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// IMPLEMENTATIONS -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -impl CalendarMetadata { - /// New calendar metadata. - pub fn new( - name: &'static str, - country_code: ISO_3166, - market_identifier_code: ISO_10383, - ) -> Self { - Self { - name, - country_code, - market_identifier_code, - } - } - - /// Returns the name of the calendar. - pub fn name(&self) -> &'static str { - self.name - } - - /// Returns the ISO 3166-1 country code. - pub fn country_code(&self) -> ISO_3166 { - self.country_code - } - - /// Returns the ISO 10383 market identifier code. - pub fn market_identifier_code(&self) -> ISO_10383 { - self.market_identifier_code - } -} diff --git a/crates/RustQuant_time/src/countries/south_america/argentina.rs b/crates/RustQuant_time/src/countries/argentina.rs similarity index 98% rename from crates/RustQuant_time/src/countries/south_america/argentina.rs rename to crates/RustQuant_time/src/countries/argentina.rs index 483aa186..581921bd 100644 --- a/crates/RustQuant_time/src/countries/south_america/argentina.rs +++ b/crates/RustQuant_time/src/countries/argentina.rs @@ -28,6 +28,10 @@ pub struct ArgentinaCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for ArgentinaCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Argentina" } diff --git a/crates/RustQuant_time/src/countries/oceania/australia.rs b/crates/RustQuant_time/src/countries/australia.rs similarity index 96% rename from crates/RustQuant_time/src/countries/oceania/australia.rs rename to crates/RustQuant_time/src/countries/australia.rs index 56a7340a..b8cba69a 100644 --- a/crates/RustQuant_time/src/countries/oceania/australia.rs +++ b/crates/RustQuant_time/src/countries/australia.rs @@ -18,7 +18,18 @@ use RustQuant_iso::*; #[derive(Debug, Clone, Copy)] pub struct AustraliaCalendar; +impl AustraliaCalendar { + /// Creates a new instance of the Australian calendar. + pub fn new() -> Self { + Self + } +} + impl Calendar for AustraliaCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Australia" } diff --git a/crates/RustQuant_time/src/countries/europe/austria.rs b/crates/RustQuant_time/src/countries/austria.rs similarity index 99% rename from crates/RustQuant_time/src/countries/europe/austria.rs rename to crates/RustQuant_time/src/countries/austria.rs index cd625501..074f96f3 100644 --- a/crates/RustQuant_time/src/countries/europe/austria.rs +++ b/crates/RustQuant_time/src/countries/austria.rs @@ -28,6 +28,10 @@ pub struct AustriaCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for AustriaCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Austria" } diff --git a/crates/RustQuant_time/src/countries/africa/botswana.rs b/crates/RustQuant_time/src/countries/botswana.rs similarity index 98% rename from crates/RustQuant_time/src/countries/africa/botswana.rs rename to crates/RustQuant_time/src/countries/botswana.rs index d832d6d6..27e2c03a 100644 --- a/crates/RustQuant_time/src/countries/africa/botswana.rs +++ b/crates/RustQuant_time/src/countries/botswana.rs @@ -30,6 +30,10 @@ pub struct BotswanaCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for BotswanaCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Botswana" } diff --git a/crates/RustQuant_time/src/countries/south_america/brazil.rs b/crates/RustQuant_time/src/countries/brazil.rs similarity index 98% rename from crates/RustQuant_time/src/countries/south_america/brazil.rs rename to crates/RustQuant_time/src/countries/brazil.rs index 6716873e..228acc8c 100644 --- a/crates/RustQuant_time/src/countries/south_america/brazil.rs +++ b/crates/RustQuant_time/src/countries/brazil.rs @@ -28,6 +28,10 @@ pub struct BrazilCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for BrazilCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Brazil" } diff --git a/crates/RustQuant_time/src/countries/north_america/canada.rs b/crates/RustQuant_time/src/countries/canada.rs similarity index 99% rename from crates/RustQuant_time/src/countries/north_america/canada.rs rename to crates/RustQuant_time/src/countries/canada.rs index eee841e7..7f2e7103 100644 --- a/crates/RustQuant_time/src/countries/north_america/canada.rs +++ b/crates/RustQuant_time/src/countries/canada.rs @@ -28,6 +28,10 @@ pub struct CanadaCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for CanadaCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Canada" } diff --git a/crates/RustQuant_time/src/countries/south_america/chile.rs b/crates/RustQuant_time/src/countries/chile.rs similarity index 98% rename from crates/RustQuant_time/src/countries/south_america/chile.rs rename to crates/RustQuant_time/src/countries/chile.rs index 51ddb846..cd370d68 100644 --- a/crates/RustQuant_time/src/countries/south_america/chile.rs +++ b/crates/RustQuant_time/src/countries/chile.rs @@ -28,6 +28,10 @@ pub struct ChileCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for ChileCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Chile" } diff --git a/crates/RustQuant_time/src/countries/asia/china.rs b/crates/RustQuant_time/src/countries/china.rs similarity index 99% rename from crates/RustQuant_time/src/countries/asia/china.rs rename to crates/RustQuant_time/src/countries/china.rs index ea49ce56..bfb227ee 100644 --- a/crates/RustQuant_time/src/countries/asia/china.rs +++ b/crates/RustQuant_time/src/countries/china.rs @@ -30,6 +30,10 @@ pub struct ChinaCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for ChinaCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "China" } diff --git a/crates/RustQuant_time/src/countries/europe/czech_republic.rs b/crates/RustQuant_time/src/countries/czech_republic.rs similarity index 98% rename from crates/RustQuant_time/src/countries/europe/czech_republic.rs rename to crates/RustQuant_time/src/countries/czech_republic.rs index 82e2c3d9..86f7f4cf 100644 --- a/crates/RustQuant_time/src/countries/europe/czech_republic.rs +++ b/crates/RustQuant_time/src/countries/czech_republic.rs @@ -28,6 +28,10 @@ pub struct CzechRepublicCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for CzechRepublicCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Czech Republic" } diff --git a/crates/RustQuant_time/src/countries/europe/denmark.rs b/crates/RustQuant_time/src/countries/denmark.rs similarity index 99% rename from crates/RustQuant_time/src/countries/europe/denmark.rs rename to crates/RustQuant_time/src/countries/denmark.rs index 8cfa5ce9..4b781b4b 100644 --- a/crates/RustQuant_time/src/countries/europe/denmark.rs +++ b/crates/RustQuant_time/src/countries/denmark.rs @@ -28,6 +28,10 @@ pub struct DenmarkCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for DenmarkCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Denmark" } diff --git a/crates/RustQuant_time/src/countries/europe/finland.rs b/crates/RustQuant_time/src/countries/finland.rs similarity index 98% rename from crates/RustQuant_time/src/countries/europe/finland.rs rename to crates/RustQuant_time/src/countries/finland.rs index 278b30eb..c88701a2 100644 --- a/crates/RustQuant_time/src/countries/europe/finland.rs +++ b/crates/RustQuant_time/src/countries/finland.rs @@ -28,6 +28,10 @@ pub struct FinlandCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for FinlandCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Finland" } diff --git a/crates/RustQuant_time/src/countries/europe/france.rs b/crates/RustQuant_time/src/countries/france.rs similarity index 98% rename from crates/RustQuant_time/src/countries/europe/france.rs rename to crates/RustQuant_time/src/countries/france.rs index 76c2e1ea..4fc7917b 100644 --- a/crates/RustQuant_time/src/countries/europe/france.rs +++ b/crates/RustQuant_time/src/countries/france.rs @@ -28,6 +28,10 @@ pub struct FranceCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for FranceCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "France" } diff --git a/crates/RustQuant_time/src/countries/europe/germany.rs b/crates/RustQuant_time/src/countries/germany.rs similarity index 98% rename from crates/RustQuant_time/src/countries/europe/germany.rs rename to crates/RustQuant_time/src/countries/germany.rs index d0909c8a..8a21dbe6 100644 --- a/crates/RustQuant_time/src/countries/europe/germany.rs +++ b/crates/RustQuant_time/src/countries/germany.rs @@ -28,6 +28,10 @@ pub struct GermanyCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for GermanyCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Germany" } diff --git a/crates/RustQuant_time/src/countries/asia/hong_kong.rs b/crates/RustQuant_time/src/countries/hong_kong.rs similarity index 99% rename from crates/RustQuant_time/src/countries/asia/hong_kong.rs rename to crates/RustQuant_time/src/countries/hong_kong.rs index 91f6dc0c..62560c8d 100644 --- a/crates/RustQuant_time/src/countries/asia/hong_kong.rs +++ b/crates/RustQuant_time/src/countries/hong_kong.rs @@ -28,6 +28,10 @@ pub struct HongKongCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for HongKongCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Hong Kong" } diff --git a/crates/RustQuant_time/src/countries/europe/hungary.rs b/crates/RustQuant_time/src/countries/hungary.rs similarity index 99% rename from crates/RustQuant_time/src/countries/europe/hungary.rs rename to crates/RustQuant_time/src/countries/hungary.rs index 88ef3cd1..704fb1ca 100644 --- a/crates/RustQuant_time/src/countries/europe/hungary.rs +++ b/crates/RustQuant_time/src/countries/hungary.rs @@ -28,6 +28,10 @@ pub struct HungaryCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for HungaryCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Hungary" } diff --git a/crates/RustQuant_time/src/countries/europe/iceland.rs b/crates/RustQuant_time/src/countries/iceland.rs similarity index 99% rename from crates/RustQuant_time/src/countries/europe/iceland.rs rename to crates/RustQuant_time/src/countries/iceland.rs index f9b6ab2f..c9aa6cc7 100644 --- a/crates/RustQuant_time/src/countries/europe/iceland.rs +++ b/crates/RustQuant_time/src/countries/iceland.rs @@ -28,6 +28,10 @@ pub struct IcelandCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for IcelandCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Iceland" } diff --git a/crates/RustQuant_time/src/countries/asia/india.rs b/crates/RustQuant_time/src/countries/india.rs similarity index 99% rename from crates/RustQuant_time/src/countries/asia/india.rs rename to crates/RustQuant_time/src/countries/india.rs index 96ee61f5..cf4806a7 100644 --- a/crates/RustQuant_time/src/countries/asia/india.rs +++ b/crates/RustQuant_time/src/countries/india.rs @@ -28,6 +28,10 @@ pub struct IndiaCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for IndiaCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "India" } diff --git a/crates/RustQuant_time/src/countries/asia/indonesia.rs b/crates/RustQuant_time/src/countries/indonesia.rs similarity index 99% rename from crates/RustQuant_time/src/countries/asia/indonesia.rs rename to crates/RustQuant_time/src/countries/indonesia.rs index aab1c12a..f81c46b9 100644 --- a/crates/RustQuant_time/src/countries/asia/indonesia.rs +++ b/crates/RustQuant_time/src/countries/indonesia.rs @@ -28,6 +28,10 @@ pub struct IndonesiaCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for IndonesiaCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Indonesia" } diff --git a/crates/RustQuant_time/src/countries/middle_east/israel.rs b/crates/RustQuant_time/src/countries/israel.rs similarity index 99% rename from crates/RustQuant_time/src/countries/middle_east/israel.rs rename to crates/RustQuant_time/src/countries/israel.rs index 90573197..1b4653f7 100644 --- a/crates/RustQuant_time/src/countries/middle_east/israel.rs +++ b/crates/RustQuant_time/src/countries/israel.rs @@ -57,6 +57,10 @@ impl IsraelCalendar { } impl Calendar for IsraelCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Israel" } diff --git a/crates/RustQuant_time/src/countries/mexico.rs b/crates/RustQuant_time/src/countries/mexico.rs new file mode 100644 index 00000000..195ff1a4 --- /dev/null +++ b/crates/RustQuant_time/src/countries/mexico.rs @@ -0,0 +1,136 @@ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// RustQuant: A Rust library for quantitative finance tools. +// Copyright (C) 2022-2024 https://github.com/avhz +// Dual licensed under Apache 2.0 and MIT. +// See: +// - LICENSE-APACHE.md +// - LICENSE-MIT.md +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// IMPORTS +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +use crate::calendar::Calendar; +use crate::utilities::unpack_date; +use time::{Date, Month, Weekday}; +use RustQuant_iso::*; + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// STRUCTS, ENUMS, TRAITS +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +/// Mexico national holiday calendar. +pub struct MexicoCalendar; + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// IMPLEMENTATIONS, METHODS +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +impl Calendar for MexicoCalendar { + fn new() -> Self { + Self + } + + fn name(&self) -> &'static str { + "Mexico" + } + + fn is_holiday(&self, date: Date) -> bool { + let (y, m, d, wd, _, _) = unpack_date(date, false); + + if + // New Year's Day + (d == 1 && m == Month::January) + // Constitution day (first Monday in February) + || (d <= 7 && m == Month::February && wd == Weekday::Monday) + // Benito Juárez Birthday (third Monday in March) + || (m == Month::March && (15..=21).contains(&d) && wd == Weekday::Monday) + // Labour Day + || (d == 1 && m == Month::May) + // Independence day + || (d == 16 && m == Month::September) + // Revolution Day (third Monday in November) + || ((15..=21).contains(&d) && wd == Weekday::Monday && m == Month::November) + // President transition every 6 years (2018, 2024, 2030, ....) + || (d == 1 && m == Month::October && (y - 2018) % 6 == 0) + // Christmas Eve + || (d == 25 && m == Month::December) + { + return true; + } + + false + } + + fn country_code(&self) -> ISO_3166 { + MEXICO + } + + fn market_identifier_code(&self) -> ISO_10383 { + XMEX + } +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// UNIT TESTS +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +#[cfg(test)] +mod test_mexico_calendar { + use super::*; + use time::macros::date; + + // Test to verify the name() method. + #[test] + fn test_name() { + let calendar = MexicoCalendar; + assert_eq!(calendar.name(), "Mexico"); + } + + // Test to verify if weekends are not considered business days. + #[test] + fn test_is_weekend() { + let calendar = MexicoCalendar; + let sat = date!(2023 - 08 - 26); + let sun = date!(2023 - 08 - 27); + assert!(!calendar.is_business_day(sat)); + assert!(!calendar.is_business_day(sun)); + } + + // Test to verify if the is_business_day() method properly accounts for public holidays. + #[test] + fn test_is_public_holiday() { + let calendar = MexicoCalendar; + let new_years_day = date!(2024 - 01 - 01); + let constitution_day = date!(2024 - 02 - 05); // First Monday of February + let benito_juarez_day = date!(2024 - 03 - 18); // Third Monday of March + let labour_day = date!(2024 - 05 - 01); + let independence_day = date!(2024 - 09 - 16); + let revolution_day = date!(2024 - 11 - 18); // Third Monday in November + let presidential_transition_day = date!(2030 - 10 - 01); // This might need adjustment + let christmas = date!(2023 - 12 - 25); + + assert!(!calendar.is_business_day(new_years_day)); + assert!(!calendar.is_business_day(constitution_day)); + assert!(!calendar.is_business_day(benito_juarez_day)); + assert!(!calendar.is_business_day(labour_day)); + assert!(!calendar.is_business_day(independence_day)); + assert!(!calendar.is_business_day(revolution_day)); + assert!(!calendar.is_business_day(presidential_transition_day)); + assert!(!calendar.is_business_day(christmas)); + } + + // Test to verify if the is_business_day() method properly accounts for regular business days. + #[test] + fn test_is_regular_business_day() { + let calendar = MexicoCalendar; + let regular_day1 = date!(2023 - 03 - 15); + let regular_day2 = date!(2023 - 08 - 15); + let regular_day3 = date!(2023 - 10 - 25); + + assert!(calendar.is_business_day(regular_day1)); + assert!(calendar.is_business_day(regular_day2)); + assert!(calendar.is_business_day(regular_day3)); + } +} diff --git a/crates/RustQuant_time/src/countries/mod.rs b/crates/RustQuant_time/src/countries/mod.rs index 8615816d..31201a84 100644 --- a/crates/RustQuant_time/src/countries/mod.rs +++ b/crates/RustQuant_time/src/countries/mod.rs @@ -9,80 +9,78 @@ //! calendars and holidays for different countries. -/// Calendars implemented for African countries. -pub mod africa { - /// Botswana holidays and calendars. - pub mod botswana; -} - -/// Calendars implemented for Asian countries. -pub mod asia { - /// China holidays and calendars. - pub mod china; - /// Hong Kong holidays and calendars. - pub mod hong_kong; - /// India holidays and calendars. - pub mod india; - /// Indonesia holidays and calendars. - pub mod indonesia; - /// Singapore holidays and calendars. - pub mod singapore; -} - -/// Calendars implemented for European countries. -pub mod europe { - /// Austria holidays and calendars. - pub mod austria; - /// Czech Republic holidays and calendars. - pub mod czech_republic; - /// Denmark holidays and calendars. - pub mod denmark; - /// Finland holidays and calendars. - pub mod finland; - /// France holidays and calendars. - pub mod france; - /// Germany holidays and calendars. - pub mod germany; - /// Hungary holidays and calendars. - pub mod hungary; - /// Iceland holidays and calendars. - pub mod iceland; - /// Netherlands holidays and calendars. - pub mod netherlands; - /// United Kingdom holidays and calendars. - pub mod united_kingdom; -} - -/// Calendars implemented for North American countries. -pub mod north_america { - /// Canada holidays and calendars. - pub mod canada; - /// United States holidays and calendars. - pub mod united_states; - /// Mexico holidays and calendars - pub mod mexico; -} - -/// Calendars implemented for Oceanian countries. -pub mod oceania { - /// Australia holidays and calendars. - pub mod australia; - /// New Zealand holidays and calendars. - pub mod new_zealand; -} - -/// Calendars implemented for South American countries. -pub mod south_america { - /// Argentina holidays and calendars. - pub mod argentina; - /// Brazil holidays and calendars. - pub mod brazil; - /// Chile holidays and calendars. - pub mod chile; -} - -/// Calanders implemented for Middle Eastern countries. -pub mod middle_east { - /// Israeli (Jewish) holidays and calander, implemented with an external API. - pub mod israel; -} \ No newline at end of file +/// Argentina holidays and calendars. +pub mod argentina; +pub use argentina::*; +/// Australia holidays and calendars. +pub mod australia; +pub use australia::*; +/// Austria holidays and calendars. +pub mod austria; +pub use austria::*; +/// Botswana holidays and calendars. +pub mod botswana; +pub use botswana::*; +/// Brazil holidays and calendars. +pub mod brazil; +pub use brazil::*; +/// Canada holidays and calendars. +pub mod canada; +pub use canada::*; +/// Chile holidays and calendars. +pub mod chile; +pub use chile::*; +/// China holidays and calendars. +pub mod china; +pub use china::*; +/// Czech Republic holidays and calendars. +pub mod czech_republic; +pub use czech_republic::*; +/// Denmark holidays and calendars. +pub mod denmark; +pub use denmark::*; +/// Finland holidays and calendars. +pub mod finland; +pub use finland::*; +/// France holidays and calendars. +pub mod france; +pub use france::*; +/// Germany holidays and calendars. +pub mod germany; +pub use germany::*; +/// Hong Kong holidays and calendars. +pub mod hong_kong; +pub use hong_kong::*; +/// Hungary holidays and calendars. +pub mod hungary; +pub use hungary::*; +/// Iceland holidays and calendars. +pub mod iceland; +pub use iceland::*; +/// India holidays and calendars. +pub mod india; +pub use india::*; +/// Indonesia holidays and calendars. +pub mod indonesia; +pub use indonesia::*; +/// Israeli (Jewish) holidays and calander, implemented with an external API. +pub mod israel; +pub use israel::*; +/// Mexico holidays and calendars +pub mod mexico; +pub use mexico::*; +/// Netherlands holidays and calendars. +pub mod netherlands; +pub use netherlands::*; +/// New Zealand holidays and calendars. +pub mod new_zealand; +pub use new_zealand::*; +/// Singapore holidays and calendars. +pub mod singapore; +pub use singapore::*; +/// United Kingdom holidays and calendars. +pub mod united_kingdom; +pub use united_kingdom::*; +/// United States holidays and calendars. +pub mod united_states; +pub use united_states::*; diff --git a/crates/RustQuant_time/src/countries/europe/netherlands.rs b/crates/RustQuant_time/src/countries/netherlands.rs similarity index 99% rename from crates/RustQuant_time/src/countries/europe/netherlands.rs rename to crates/RustQuant_time/src/countries/netherlands.rs index bedc428a..140681be 100644 --- a/crates/RustQuant_time/src/countries/europe/netherlands.rs +++ b/crates/RustQuant_time/src/countries/netherlands.rs @@ -28,6 +28,10 @@ pub struct NetherlandsCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for NetherlandsCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Netherlands" } diff --git a/crates/RustQuant_time/src/countries/oceania/new_zealand.rs b/crates/RustQuant_time/src/countries/new_zealand.rs similarity index 98% rename from crates/RustQuant_time/src/countries/oceania/new_zealand.rs rename to crates/RustQuant_time/src/countries/new_zealand.rs index 44c8cee1..3bf9ae9a 100644 --- a/crates/RustQuant_time/src/countries/oceania/new_zealand.rs +++ b/crates/RustQuant_time/src/countries/new_zealand.rs @@ -18,6 +18,10 @@ use RustQuant_iso::*; pub struct NewZealandCalendar; impl Calendar for NewZealandCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "New Zealand" } diff --git a/crates/RustQuant_time/src/countries/north_america/mexico.rs b/crates/RustQuant_time/src/countries/north_america/mexico.rs deleted file mode 100644 index c907732c..00000000 --- a/crates/RustQuant_time/src/countries/north_america/mexico.rs +++ /dev/null @@ -1,132 +0,0 @@ -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// RustQuant: A Rust library for quantitative finance tools. -// Copyright (C) 2022-2024 https://github.com/avhz -// Dual licensed under Apache 2.0 and MIT. -// See: -// - LICENSE-APACHE.md -// - LICENSE-MIT.md -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// IMPORTS -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -use crate::calendar::Calendar; -use crate::utilities::unpack_date; -use time::{Date, Month, Weekday}; -use RustQuant_iso::*; - -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// STRUCTS, ENUMS, TRAITS -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -/// Mexico national holiday calendar. -pub struct MexicoCalendar; - -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// IMPLEMENTATIONS, METHODS -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -impl Calendar for MexicoCalendar { - fn name(&self) -> &'static str { - "Mexico" - } - - fn is_holiday(&self, date: Date) -> bool { - let (y, m, d, wd, _, _) = unpack_date(date, false); - - if - // New Year's Day - (d == 1 && m == Month::January) - // Constitution day (first Monday in February) - || (d <= 7 && m == Month::February && wd == Weekday::Monday) - // Benito Juárez Birthday (third Monday in March) - || (m == Month::March && (15..=21).contains(&d) && wd == Weekday::Monday) - // Labour Day - || (d == 1 && m == Month::May) - // Independence day - || (d == 16 && m == Month::September) - // Revolution Day (third Monday in November) - || ((15..=21).contains(&d) && wd == Weekday::Monday && m == Month::November) - // President transition every 6 years (2018, 2024, 2030, ....) - || (d == 1 && m == Month::October && (y - 2018) % 6 == 0) - // Christmas Eve - || (d == 25 && m == Month::December) - { - return true; - } - - false - } - - fn country_code(&self) -> ISO_3166 { - MEXICO - } - - fn market_identifier_code(&self) -> ISO_10383 { - XMEX - } -} - -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// UNIT TESTS -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -#[cfg(test)] -mod test_mexico_calendar { - use super::*; - use time::macros::date; - - // Test to verify the name() method. - #[test] - fn test_name() { - let calendar = MexicoCalendar; - assert_eq!(calendar.name(), "Mexico"); - } - - // Test to verify if weekends are not considered business days. - #[test] - fn test_is_weekend() { - let calendar = MexicoCalendar; - let sat = date!(2023 - 08 - 26); - let sun = date!(2023 - 08 - 27); - assert!(!calendar.is_business_day(sat)); - assert!(!calendar.is_business_day(sun)); - } - - // Test to verify if the is_business_day() method properly accounts for public holidays. - #[test] - fn test_is_public_holiday() { - let calendar = MexicoCalendar; - let new_years_day = date!(2024 - 01 - 01); - let constitution_day = date!(2024 - 02 - 05); // First Monday of February - let benito_juarez_day = date!(2024 - 03 - 18); // Third Monday of March - let labour_day = date!(2024 - 05 - 01); - let independence_day = date!(2024 - 09 - 16); - let revolution_day = date!(2024 - 11 - 18); // Third Monday in November - let presidential_transition_day = date!(2030 - 10 - 01); // This might need adjustment - let christmas = date!(2023 - 12 - 25); - - assert!(!calendar.is_business_day(new_years_day)); - assert!(!calendar.is_business_day(constitution_day)); - assert!(!calendar.is_business_day(benito_juarez_day)); - assert!(!calendar.is_business_day(labour_day)); - assert!(!calendar.is_business_day(independence_day)); - assert!(!calendar.is_business_day(revolution_day)); - assert!(!calendar.is_business_day(presidential_transition_day)); - assert!(!calendar.is_business_day(christmas)); - } - - // Test to verify if the is_business_day() method properly accounts for regular business days. - #[test] - fn test_is_regular_business_day() { - let calendar = MexicoCalendar; - let regular_day1 = date!(2023 - 03 - 15); - let regular_day2 = date!(2023 - 08 - 15); - let regular_day3 = date!(2023 - 10 - 25); - - assert!(calendar.is_business_day(regular_day1)); - assert!(calendar.is_business_day(regular_day2)); - assert!(calendar.is_business_day(regular_day3)); - } -} diff --git a/crates/RustQuant_time/src/countries/asia/singapore.rs b/crates/RustQuant_time/src/countries/singapore.rs similarity index 99% rename from crates/RustQuant_time/src/countries/asia/singapore.rs rename to crates/RustQuant_time/src/countries/singapore.rs index 24c23195..4b33cca2 100644 --- a/crates/RustQuant_time/src/countries/asia/singapore.rs +++ b/crates/RustQuant_time/src/countries/singapore.rs @@ -28,6 +28,10 @@ pub struct SingaporeCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for SingaporeCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "Singapore" } diff --git a/crates/RustQuant_time/src/countries/europe/united_kingdom.rs b/crates/RustQuant_time/src/countries/united_kingdom.rs similarity index 99% rename from crates/RustQuant_time/src/countries/europe/united_kingdom.rs rename to crates/RustQuant_time/src/countries/united_kingdom.rs index 9691e83d..3cff3c53 100644 --- a/crates/RustQuant_time/src/countries/europe/united_kingdom.rs +++ b/crates/RustQuant_time/src/countries/united_kingdom.rs @@ -28,6 +28,10 @@ pub struct UnitedKingdomCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for UnitedKingdomCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "United Kingdom" } diff --git a/crates/RustQuant_time/src/countries/north_america/united_states.rs b/crates/RustQuant_time/src/countries/united_states.rs similarity index 99% rename from crates/RustQuant_time/src/countries/north_america/united_states.rs rename to crates/RustQuant_time/src/countries/united_states.rs index dc624aeb..a3bbd6d3 100644 --- a/crates/RustQuant_time/src/countries/north_america/united_states.rs +++ b/crates/RustQuant_time/src/countries/united_states.rs @@ -28,6 +28,10 @@ pub struct UnitedStatesCalendar; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ impl Calendar for UnitedStatesCalendar { + fn new() -> Self { + Self + } + fn name(&self) -> &'static str { "United States of America" } diff --git a/examples/examples/curves_discount.rs b/examples/examples/curves_discount.rs index 457c3de2..fb5fe3c3 100644 --- a/examples/examples/curves_discount.rs +++ b/examples/examples/curves_discount.rs @@ -1,8 +1,7 @@ use time::macros::date; use time::Date; -use RustQuant::data::Curves; -use RustQuant::data::{Curve, DiscountCurve}; -use RustQuant::time::oceania::australia::AustraliaCalendar; +use RustQuant::data::*; +use RustQuant::time::*; fn main() { let _cal = AustraliaCalendar; diff --git a/examples/examples/curves_spot.rs b/examples/examples/curves_spot.rs index 1f6a6e2e..aa393aaa 100644 --- a/examples/examples/curves_spot.rs +++ b/examples/examples/curves_spot.rs @@ -1,6 +1,6 @@ use time::{macros::date, Date}; -use RustQuant::data::{Curves, SpotCurve}; -use RustQuant::time::oceania::australia::AustraliaCalendar; +use RustQuant::data::*; +use RustQuant::time::*; fn main() { let mut spot_curve = SpotCurve::::new(&DATES, &RATES); diff --git a/examples/examples/market_data.rs b/examples/examples/market_data.rs index 1ca8eb85..02d3b28c 100644 --- a/examples/examples/market_data.rs +++ b/examples/examples/market_data.rs @@ -1,5 +1,5 @@ -use RustQuant::data::{MarketData, MarketDataBuilder}; -use RustQuant::time::oceania::australia::AustraliaCalendar; +use RustQuant::data::*; +use RustQuant::time::*; fn main() { let market_data: MarketData = MarketDataBuilder::default() diff --git a/examples/examples/schedule.rs b/examples/examples/schedule.rs index 83780ecf..45445c32 100644 --- a/examples/examples/schedule.rs +++ b/examples/examples/schedule.rs @@ -8,10 +8,7 @@ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ use time::macros::date; -use RustQuant::time::{ - countries::oceania::australia::AustraliaCalendar, DateRollingConvention, DayCountConvention, - Scheduler, -}; +use RustQuant::time::*; fn main() { let cal = AustraliaCalendar;