Skip to main content

present_value_annuity

Function present_value_annuity 

Source
pub fn present_value_annuity<T, D>(
    rate: f64,
    periods: u32,
    annuity: T,
    timing: D,
) -> FinanceResult<f64>
where T: Into<f64> + Copy, D: Into<PaymentTiming>,
Expand description

Returns the present value of an annuity (series of constant cashflows) at a constant rate. Returns f64.

The present value annuity formula is (both yield the same result):

present_value = sum( cashflow / (1 + rate)period )

or

present value = annuity * ((1. - (1. / (1. + rate)).powf(periods)) / rate)

§Arguments

  • rate - The rate at which the investment grows or shrinks per period, expressed as a floating point number. For instance 0.05 would mean 5%. Often appears as r or i in formulas.
  • periods - The number of periods such as quarters or years. Often appears as n or t.
  • cashflow - The value of the constant cashflow (aka payment, or annuity).
  • timing - PaymentTiming or bool (false = end of period / Excel type=0).

§Errors

Returns crate::FinanceError if rate is less than or equal to -1.0, money is non-finite, or periods is zero.

§Examples

Solution API with spreadsheet-style bool:

let my_annuity = present_value_annuity_solution(0.034, 10, 21_000, false).unwrap();
assert!(my_annuity.present_value().is_finite());

Scalar PV of twelve $2,000 cashflows at 2.1% monthly:

let present_value_ann = present_value_annuity(0.021, 12, 2_000, false).unwrap();
assert_approx_equal!(-21021.368565, present_value_ann);

Annuity due with the enum:

let due = present_value_annuity(0.034, 10, 500, PaymentTiming::BeginningOfPeriod).unwrap();
let ordinary = present_value_annuity(0.034, 10, 500, PaymentTiming::EndOfPeriod).unwrap();
assert!(due.abs() > ordinary.abs());