Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Avhz RustQuant Calendar

From Leeroopedia


Knowledge Sources
Domains Calendar, Time_Value_of_Money
Last Updated 2026-02-07 19:00 GMT

Overview

Concrete tool for representing market calendars and performing business day arithmetic provided by the RustQuant library.

Description

The Calendar module defines two core types: the Market enum and the Calendar struct. The Market enum identifies a market calendar by country (or special marker such as None or Weekends), covering 27 countries including Argentina, Australia, Austria, Botswana, Brazil, Canada, Chile, China, Czech Republic, Denmark, Finland, France, Germany, Hong Kong, Hungary, Iceland, India, Indonesia, Israel, Italy, Mexico, Netherlands, New Zealand, Singapore, United Kingdom, United States, and Switzerland. The market identifiers follow the MIC (ISO 10383) standard.

The Calendar struct holds a Market variant and an optional BTreeSet<Date> of extra user-defined holidays. It provides methods for:

  • Holiday detection -- is_holiday dispatches to the country-specific holiday implementation function for the configured market, and also checks user-added extra holidays.
  • Weekend detection -- is_weekend returns true if the date falls on a weekend (Saturday/Sunday for most markets, Friday/Saturday for Israel).
  • Business day detection -- is_business_day returns true if the date is neither a weekend nor a holiday.
  • Date rolling -- roll_date and roll_dates adjust dates that fall on non-business days according to a specified DateRollingConvention (Actual, Following, ModifiedFollowing, Preceding, ModifiedPreceding, ModifiedRolling).
  • Day counting -- calendar_day_count, business_day_count, and day_count_factor compute calendar days, business days, and year fractions between two dates. Batch versions (calendar_day_counts, business_day_counts, day_count_factors) operate on vectors of dates using sliding windows.
  • Schedule generation -- generate_schedule_from_dates rolls a vector of dates and computes day count factors to produce a Schedule.

Both Market and Calendar are annotated with #[pyclass] and #[pymethods] for Python interoperability via PyO3.

Usage

Use this when you need to determine whether a given date is a business day in a particular market, adjust payment or settlement dates to valid business days, compute accrued interest day counts, or generate payment schedules for fixed-income instruments.

Code Reference

Source Location

Signature

#[derive(Debug, Clone, Copy)]
#[pyclass]
pub enum Market {
    None,
    Weekends,
    Argentina,
    Australia,
    // ... 25 more country variants ...
    Switzerland,
}

#[derive(Debug, Clone)]
#[pyclass]
pub struct Calendar {
    pub market: Market,
    extra: BTreeSet<Date>,
}

impl Calendar {
    pub const fn new(market: Market) -> Self;
    pub fn market(&self) -> Market;
    pub fn add_holiday(&mut self, date: Date);
    pub fn add_holidays(&mut self, dates: Vec<Date>);
    pub fn extra_holidays(&self) -> &BTreeSet<Date>;
    pub fn is_business_day(&self, date: Date) -> bool;
    pub fn is_weekend(&self, date: Date) -> bool;
    pub fn is_holiday(&self, date: Date) -> bool;
    pub fn roll_date(&self, date: Date, convention: DateRollingConvention) -> Date;
    pub fn roll_dates(&self, dates: Vec<Date>, convention: DateRollingConvention) -> Vec<Date>;
    pub fn calendar_day_count(&self, date1: Date, date2: Date) -> i64;
    pub fn business_day_count(&self, date1: Date, date2: Date) -> i64;
    pub fn day_count_factor(&self, date1: Date, date2: Date, convention: DayCountConvention) -> f64;
    pub fn calendar_day_counts(&self, dates: Vec<Date>) -> Vec<i64>;
    pub fn business_day_counts(&self, dates: Vec<Date>) -> Vec<i64>;
    pub fn day_count_factors(&self, dates: Vec<Date>, convention: DayCountConvention) -> Vec<f64>;
    pub fn generate_schedule_from_dates(
        &self,
        dates: Vec<Date>,
        date_rolling_convention: DateRollingConvention,
        day_counting_convention: DayCountConvention,
    ) -> Schedule;
}

Import

use RustQuant::time::calendar::{Calendar, Market};

I/O Contract

Inputs

Name Type Required Description
market Market Yes The market/country whose holiday calendar to use
date Date Yes (for single-date methods) The date to check or roll
dates Vec<Date> Yes (for batch methods) A vector of dates to process
convention DateRollingConvention Yes (for rolling methods) The business day rolling convention to apply
convention DayCountConvention Yes (for day count methods) The day count convention to use for year fraction calculation

Outputs

Name Type Description
Calendar Calendar A new calendar instance bound to the specified market
bool bool Result of is_business_day, is_weekend, is_holiday checks
i64 i64 Calendar day count or business day count between two dates
f64 f64 Day count factor (year fraction) between two dates
Vec<Date> Vec<Date> Rolled dates after applying the date rolling convention
Schedule Schedule Generated schedule with rolled dates and day count factors

Usage Examples

use time::macros::date;
use RustQuant::time::calendar::{Calendar, Market};
use RustQuant::time::day_counting::DayCountConvention;
use RustQuant::time::date_rolling::DateRollingConvention;

// Create a calendar for the Australian market.
let calendar = Calendar::new(Market::Australia);

// Check if a date is a business day.
let date1 = date!(2023-01-01);
assert!(!calendar.is_business_day(date1)); // New Year's Day is a holiday

// Compute business days between two dates.
let date2 = date!(2023-02-01);
assert_eq!(calendar.business_day_count(date1, date2), 21);

// Compute a day count factor.
let date3 = date!(2024-01-01);
let convention = DayCountConvention::Actual_365_Actual;
let dcf = calendar.day_count_factor(date1, date3, convention);

// Add a custom holiday.
let mut custom_calendar = Calendar::new(Market::None);
custom_calendar.add_holiday(date!(2024-06-15));
assert!(!custom_calendar.is_business_day(date!(2024-06-15)));

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment