9 releases

0.2.0 May 7, 2023
0.1.7 Apr 28, 2023
0.1.6 Jan 14, 2023
0.1.4 Nov 3, 2022
0.1.1 Apr 22, 2022

#117 in Date and time

Download history 16/week @ 2023-02-13 22/week @ 2023-02-20 14/week @ 2023-02-27 57/week @ 2023-03-06 66/week @ 2023-03-13 19/week @ 2023-03-20 23/week @ 2023-03-27 10/week @ 2023-04-10 46/week @ 2023-04-17 41/week @ 2023-04-24 13/week @ 2023-05-01 33/week @ 2023-05-08 3/week @ 2023-05-15 11/week @ 2023-05-29

58 downloads per month

MIT/Apache

15KB
221 lines

yearfrac: Year Fruction for Rust

It was tested to match Excel's YEARFRAC function and with time go beyond. We support all 5 Excel's methodologies: nasd360 act/act act360 act365 eur360

Usage

Put this in your Cargo.toml:

[dependencies]
yearfrac = {version="*", features=['serde', 'openapi']}

Examples

use yearfrac::DayCountConvention;
use chrono::{NaiveDate, Datelike};
let start = NaiveDate::from_ymd(1978, 2, 28);
let end = NaiveDate::from_ymd(2020, 5, 17);
let yf = DayCountConvention::from_int(0).unwrap()
               .yearfrac(start, end);
assert!((yf - 42.21388888889).abs() < 1e-9);

let yf = DayCountConvention::from_str("act/act").unwrap()
            .yearfrac(start, end);
assert!((yf - 42.21424933147).abs() < 1e-9);

use yearfrac::is_leap_year;
assert_eq!(is_leap_year(start.year()) as i32, 0)

let yf = DayCountConvention::US30360.yearfrac_signed(end, start);
assert!((yf + 42.21388888889).abs() < 1e-9);

Acknowledgements

Ultima

Python FRTB User Guide

Dependencies

~1.3–2.2MB
~43K SLoC