Function present_value_annuity_solution

Source
pub fn present_value_annuity_solution<T>(
    rate: f64,
    periods: u32,
    cashflow: T,
    due_at_beginning: bool,
) -> CashflowSolution
where T: Into<f64> + Copy,
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).
  • 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.

§Examples

Present value of a $500 annuity (a series of $500 cashflows).

// The rate is 3.4% per month.
let rate = 0.034;

// The annuity will provide yearly payments for 10 years.
let periods = 10;

// The cashflow will be $500.
let cashflow = 500;

let due_at_beginning = false;

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

Outputs to terminal:

 {
     calculated_field: PresentValueAnnuity,
     rate: 0.034,
     periods: 10,
     present_value: -4179.341028819192,
     future_value: -5838.660162934531,
     due_at_beginning: false,
     payment: 500.0,
     sum_of_payments: 5000.0,
     sum_of_interest: -5018.001191753723,
     formula: "-500 * ((1. - (1. / (1. + 0.034)).powf(10)) / 0.034) * (1 + (0.034 * 0));",
     symbolic_formula: "-annuity * ((1. - (1. / (1. + rate)).powf(periods)) / rate) * (1. + (rate * due));",
 }