[][src]Function finance_solution::future_value_annuity

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

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

The future value annuity formula is:

future value ann = sum( cashflow * (1 + rate)period )

or

future value ann = Constant_Cashflow * ((1+periodic_rate)^n -1) / periodic_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.

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:

use finance_solution::*;
let (rate, periods, payment, due_at_beginning) = (0.034, 5, 500, false);
let my_annuity = future_value_annuity(rate, periods, payment, due_at_beginning);
assert_approx_equal!(my_annuity, -2_675.8789282); 

Or use the solution struct (recommended, more helpful to debugging and for student-learning)

use finance_solution::*;
let (rate, periods, pmt, due_at_beginning) = (0.034, 5, 500, false);
let my_annuity = future_value_annuity_solution(rate, periods, pmt, due_at_beginning);
dbg!(&my_annuity);

Outputs to terminal:

{
 calculated_field: FutureValueAnnuity,
 rate: 0.034,
 periods: 5,
 present_value: 2263.9340209510633,
 future_value: 2675.8789281680038,
 due_at_beginning: false,
 payment: 500.0,
 sum_of_payments: 2500.0,
 sum_of_interest: 7439.812949119067,
 formula: "500 * ((1. - (1. / (1. + 0.034)).powf(5)) / 0.034);",
 formula_symbolic: "annuity * ((1. - (1. / (1. + rate)).powf(periods)) / rate);",
}
// call the value as a method to get the solution value
let final_answer = my_annuity.future_value();

Another example: Future 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 future value.
let future_value_ann = future_value_annuity(rate, periods, cashflow, due_at_beginning);
dbg!(&future_value_ann);

// Confirm that the future value is correct to four decimal places (one hundredth of a cent).
// assert_approx_equal!( , future_value_ann);