Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/RustQuant_time/src/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ pub enum Market {
UnitedStates,
/// Switzerland national calendar.
Switzerland,
/// Turkey national calendar.
Turkey,
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// MARKETS / EXCHANGES
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -435,6 +437,7 @@ impl Calendar {
Market::UnitedKingdom => is_holiday_impl_united_kingdom(date),
Market::UnitedStates => is_holiday_impl_united_states(date),
Market::Switzerland => is_holiday_impl_switzerland(date),
Market::Turkey => is_holiday_impl_turkey(date),
// Special case markets:
Market::None => false,
Market::Weekends => false,
Expand Down
4 changes: 4 additions & 0 deletions crates/RustQuant_time/src/countries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ pub(crate) use united_states::*;
/// Switzerland holidays and calendars.
pub mod switzerland;
pub(crate) use switzerland::*;

/// Turkey holidays and calendars.
pub(crate) mod turkey;
pub(crate) use turkey::*;
66 changes: 66 additions & 0 deletions crates/RustQuant_time/src/countries/turkey.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

use crate::utilities::unpack_date;
use time::{Date, Month};

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// IMPLEMENTATIONS, METHODS
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// Turkey calendar.
pub(crate) fn is_holiday_impl_turkey(date: Date) -> bool {
let (_y, m, d, _wd, _yd, _em) = unpack_date(date, false);

// Borsa Istanbul (BIST) Holiday Calendar
// Source: Official Public Holidays in Turkey

// Fixed Public Holidays (Gregorian Calendar)
if (d == 1 && m == Month::January) // New Year's Day
|| (d == 23 && m == Month::April) // National Sovereignty and Children's Day
|| (d == 1 && m == Month::May) // Labor and Solidarity Day
|| (d == 19 && m == Month::May) // Commemoration of Atatürk, Youth and Sports Day
|| (d == 15 && m == Month::July) // Democracy and National Unity Day
|| (d == 30 && m == Month::August) // Victory Day
|| (d == 29 && m == Month::October)
// Republic Day
{
return true;
}

false
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// UNIT TESTS
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#[cfg(test)]
mod tests {
use super::*;
use crate::calendar::{Calendar, Market};
use time::macros::date;

#[test]
fn test_turkey_holidays() {
let calendar = Calendar::new(Market::Turkey);

// Republic Day
assert!(calendar.is_holiday(date!(2024 - 10 - 29)));

// Victory Day
assert!(calendar.is_holiday(date!(2024 - 08 - 30)));

// Regular business day
assert!(calendar.is_business_day(date!(2024 - 01 - 02)));

// Weekend check (Example: Jan 6, 2024 was Saturday)
assert!(calendar.is_weekend(date!(2024 - 01 - 06)));
}
}