#irr #money #npv

financial

A collection of finance calculations mimicking some of Excel Financial Functions interface

8 stable releases

1.1.5 Feb 17, 2023
1.1.3 Oct 13, 2021
1.1.2 Aug 5, 2020
1.1.1 Jul 23, 2020

#57 in Finance

Download history 5/week @ 2024-08-10 6/week @ 2024-08-17 9/week @ 2024-08-24 15/week @ 2024-08-31 26/week @ 2024-09-07 14/week @ 2024-09-14 36/week @ 2024-09-21 31/week @ 2024-09-28 27/week @ 2024-10-05 23/week @ 2024-10-12 23/week @ 2024-10-19 84/week @ 2024-10-26 81/week @ 2024-11-02 67/week @ 2024-11-09 68/week @ 2024-11-16

303 downloads per month

MIT/Apache

83KB
665 lines

Financial

GitHub CircleCI crates.io docs.rs

Financial is a Rust crate that contains collection of finance calculations mimicking some of Excel Financial Functions interface. you can find the crate here

Usage

use financial;

let npv = financial::npv(0.1, &[-1000., 500., 500., 500.]);
assert_eq!(npv, 221.29635953828267);

What makes this crate different

It supports both periodic and scheduled computation for IRR and NPV.

IRR and NPV functions are faster since powers are pre-computed iteratively instead of using power function multiple times. Take this with a grain of salt since no benches tests are offered at the moment.

Supported Functions

  • FV(Rate, Nper, Pmt, Pv, Pmt_is_due)
  • PV(Rate, Nper, Pmt, Fv, Pmt_is_due)
  • NPV(Rate, values)
  • XNPV(Rate, values, dates)
  • IRR(values)
  • XIRR(values, dates)
  • MIRR(values, finance_rate, reinvest_rate)

NaiveDate Interface

  • financial::naive_date::xirr() and financial::naive_date::xnpv() provide same functionalities as financial::xirr() and financial::xnpv(), except that the former supports NaiveDate as the input date type while the latter uses DateTime<T>.

Future Work

  • Add bench tests
  • Add More Functions (NPER, PMT, Rate, effect)

Testing

  • This crate has over 180 test case, most of them are compared to Excel outputs.
  • XIRR is not compared against Excel, since Excel XIRR doesn't always converge to the correct answer and often produce the wrong answer of 0.000000002980. Instead XIRR are tested by using the XIRR to produce a zero XNPV value.
  • Note that the precision used for equality of floating points is 1e-7

Contribution

  • Using the crate and providing feedback or pointing out any issues.
  • Adding more test cases is encouraged.
  • Any contribution that serves the crate is welcome.

Buy Me A Coffee

Dependencies

~1MB
~18K SLoC