Expand description
§findates — Financial date arithmetic for Rust
Any meaningful financial calculation requires a precise notion of time. While there is extensive literature on pricing models and financial theory, much less attention is given to the practical task of constructing the time inputs those models depend on.
findates focuses on this layer: generating correct schedules, applying
conventions, and computing date fractions consistently.
§Modules
calendar—Calendarstruct: weekends and holiday sets, set operationsconventions—DayCount,AdjustRule,Frequencyenumsalgebra— core functions: business day checks, adjustment, day count fractions, schedule countingschedule—Scheduleand lazyScheduleIteratorerror—DayCountErrorreturned by fallible functions
§Features
serde(optional) — derivesSerializeandDeserializeforDayCount,AdjustRule,Frequency, andCalendar. Enable inCargo.toml:[dependencies] findates = { version = "0.1", features = ["serde"] }
§Date Types
findates uses chrono::NaiveDate as its date representation throughout.
All public functions accept and return NaiveDate (aliased as
FinDate for convenience). Timezone-aware dates are not supported —
financial date arithmetic operates on calendar dates without reference
to time of day or timezone.
If your codebase uses the time crate, you will
need to convert to NaiveDate at the boundary. Broader date type
interoperability is planned for a future release.
§Quick start
use chrono::NaiveDate;
use findates::calendar::basic_calendar;
use findates::conventions::{AdjustRule, DayCount, Frequency};
use findates::schedule::Schedule;
use findates::algebra;
// Build a calendar with standard Sat/Sun weekend
let cal = basic_calendar();
// Adjust a Saturday to the next business day (Monday)
let saturday = NaiveDate::from_ymd_opt(2024, 3, 16).unwrap();
let adj = algebra::adjust(&saturday, Some(&cal), Some(AdjustRule::Following));
assert_eq!(adj, NaiveDate::from_ymd_opt(2024, 3, 18).unwrap());
// Generate a semi-annual schedule (2023 is not a leap year: exactly 365 days)
let anchor = NaiveDate::from_ymd_opt(2023, 1, 1).unwrap();
let end = NaiveDate::from_ymd_opt(2024, 1, 1).unwrap();
let sched = Schedule::new(Frequency::Semiannual, None, None);
let dates = sched.generate(&anchor, &end).unwrap();
assert_eq!(dates.len(), 3); // 2023-01-01, 2023-07-01, 2024-01-01
// Act/365 over 365 days = exactly 1.0
let dcf = algebra::day_count_fraction(
&anchor, &end, DayCount::Act365, None, None,
).unwrap();
assert!((dcf - 1.0).abs() < 1e-9);Re-exports§
pub use error::DayCountError;
Modules§
- algebra
- Core financial date functions.
- calendar
- Holiday calendars — the set of dates that are not business days.
- conventions
- Enumerations for the standard financial market conventions.
- error
- Error types returned by fallible findates functions.
- schedule
- Frequency-based date schedule generation.
Type Aliases§
- FinDate
- Type alias for the date type used throughout the library.