[−][src]Function financial::xnpv
pub fn xnpv<T: TimeZone>(
rate: f64,
values: &[f64],
dates: &[DateTime<T>]
) -> Result<f64, &'static str>
Returns the net present value for a schedule of cash flows that is not necessarily periodic.
Example
use chrono::{NaiveDate, DateTime, Utc, Duration}; let cf = [-500., 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_eq!(financial::xnpv(0.1, &cf, &dates).unwrap(), -120.9553674519204);