[][src]Function finance_solution::present_value_annuity

pub fn present_value_annuity<T>(
    rate: f64,
    periods: u32,
    annuity: T,
    due_at_beginning: bool
) -> f64 where
    T: Into<f64> + Copy

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).
  • due_at_beginning - True if the payment is due at the beginning of the period. Typically the payment will be due at the end of the period so this will be false.

Panics

The call will fail if rate is less than -1.0 as this would mean the investment is losing more than its full value every period.

Examples

Quick glance, how to use:

let (rate, periods, annuity, due_at_beginning)  = (0.034, 10, 21_000, false);
let my_annuity = present_value_annuity_solution(rate, periods, annuity, due_at_beginning);
dbg!(my_annuity);

Present value of a series of $2000 cashflows.

// The rate is 2.1% per month.
let rate = 0.021;

// The investment will grow for 12 months.
let periods = 12;

// The cashflow will be $2,000.
let cashflow = 2_000;

let due_at_beginning = false;

// Find the current value.
let present_value_ann = present_value_annuity(rate, periods, cashflow, due_at_beginning);
dbg!(&present_value_ann);

// Confirm that the present value is correct to four decimal places (one hundredth of a cent).
assert_approx_equal!(-21021.368565, present_value_ann);