Skip to main content

Crate findates

Crate findates 

Source
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

§Features

  • serde (optional) — derives Serialize and Deserialize for DayCount, AdjustRule, Frequency, and Calendar. Enable in Cargo.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.