Skip to main content

regit_daycount/
lib.rs

1// Copyright 2026 Regit.io — Nicolas Koenig
2// SPDX-License-Identifier: Apache-2.0
3
4//! Day-count fractions and business-day calendars in pure Rust —
5//! `#![no_std]`, no `alloc`, zero dependencies.
6//!
7//! `regit-daycount` computes the year fraction between two dates under every
8//! common day-count convention (Act/360, Act/365F, `ActAct` ISDA, `ActAct`
9//! ICMA, 30/360 `BondBasis`, 30E/360, 30E/360 ISDA, Act/365L, NL/365, Bus/252,
10//! 1/1), adjusts a date under every common date-roll convention (Unadjusted,
11//! Following, `ModifiedFollowing`, Preceding, `ModifiedPreceding`, Nearest,
12//! `EndOfMonth`), and classifies dates against the major holiday calendars
13//! (TARGET2, US, UK, JP, CH, HK, SG, plus composite and joint-business
14//! combinations).
15//!
16//! A coupon is paid on a date, an accrued-interest amount is settled to a
17//! date, and a swap leg is discounted from a date — every one of those
18//! operations is parameterised by a day-count convention and a holiday
19//! calendar, and a wrong choice silently produces a wrong cashflow. This
20//! crate's first duty is therefore to compute every convention exactly as
21//! its governing standard prescribes — never to guess, never to round
22//! silently, never to interpolate where the standard splits.
23//!
24//! The crate is `#![no_std]` and allocation-free: dates are 32-bit `Copy`
25//! triples, every algorithm is hand-rolled integer arithmetic, holiday
26//! tables are static sorted arrays, and there is no runtime dependency. The
27//! same audited logic runs in a backend service, a WASM bundle, or on an
28//! embedded device.
29//!
30//! # Architecture
31//!
32//! ```text
33//! errors       typed errors — ValidationError
34//! date         Gregorian Date primitive — leap years, weekday, arithmetic
35//! roll         date-roll conventions — Unadjusted, Following, ...
36//!
37//! day_count    catalogue of day-count fractions and their dispatcher
38//!              (Act/360, Act/365F, ActAct ISDA, ActAct ICMA, 30/360, ...)
39//!
40//! calendar     catalogue of holiday calendars and their dispatcher
41//!              (TARGET2 fixed rule; US / UK / JP / CH / HK / SG snapshots)
42//! ```
43//!
44//! Every rule is traced to a citable standard — ISDA 2006 Definitions §4.16,
45//! ICMA Rule 251, ISO 8601, the ECB TARGET2 closing-days regulation, and the
46//! published calendars of NYSE, the Bank of England, JPX, SIX, HKEX, and
47//! SGX — in the doc comment of the module that implements it.
48//!
49//! Part of [Regit OS](https://www.regit.io) — the operating system for
50//! investment products. From Luxembourg.
51
52#![no_std]
53#![forbid(unsafe_code)]
54
55#[cfg(test)]
56mod test_support;
57
58pub mod date;
59pub mod day_count;
60pub mod errors;
61pub mod roll;
62
63/// Holiday calendars and their dispatcher. Behind the default `calendars`
64/// feature so a minimal build (`cargo build --no-default-features`) drops
65/// the embedded snapshot tables and exposes only the date primitives,
66/// day-count fractions, and date-roll conventions.
67#[cfg(feature = "calendars")]
68pub mod calendar;
69
70pub use date::{Date, Weekday};
71pub use day_count::DayCount;
72pub use errors::ValidationError;
73pub use roll::Roll;
74
75#[cfg(feature = "calendars")]
76pub use calendar::Calendar;