[−][src]Function financial::xirr
pub fn xirr<T: TimeZone>(
values: &[f64],
dates: &[DateTime<T>],
guess: Option<f64>
) -> Result<f64, &'static str>
Returns the internal rate of return for a schedule of cash flows that is not necessarily periodic
Example
use chrono::{NaiveDate, DateTime, Utc}; let cf = [-379., 100., 100., 100., 100., 100.]; let dates = [ DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2016, 7, 8).and_hms(0, 0, 0), Utc), DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2017, 7, 8).and_hms(0, 0, 0), Utc), DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2018, 7, 8).and_hms(0, 0, 0), Utc), DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2019, 7, 8).and_hms(0, 0, 0), Utc), DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2020, 7, 8).and_hms(0, 0, 0), Utc), DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2021, 7, 8).and_hms(0, 0, 0), Utc), ]; assert!((financial::xirr(&cf, &dates, None).unwrap() - 0.10004608364).abs() < 1e-7);