Skip to main content

present_value_annuity_solution

Function present_value_annuity_solution 

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

Returns the present value of a future series of constant cashflows and constant rate. Returns custom solution type with additional information and functionality.

Related functions:

  • To calculate a present value returning an f64, use [present_value_annuity].
  • To calculate a present value with a varying rate or varying cashflow or both, use [present_value_annuity_schedule].

The present value annuity formula is:

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).
  • timing - PaymentTiming or bool (false = end of period).

§Errors

Same domain failures as [present_value_annuity].

§Examples

Present value of a $500 annuity for 10 periods at 3.4%:

let present_value_ann = present_value_annuity_solution(
    0.034, 10, 500, PaymentTiming::EndOfPeriod
).unwrap();
assert!(present_value_ann.present_value().abs() > 4_000.0);
assert!(!present_value_ann.due_at_beginning());

Annuity due solution:

let due = present_value_annuity_solution(
    0.034, 10, 500, PaymentTiming::BeginningOfPeriod
).unwrap();
assert!(due.due_at_beginning());