[][src]Function finance_solution::future_value_schedule

pub fn future_value_schedule<T>(rates: &[f64], present_value: T) -> f64 where
    T: Into<f64> + Copy

Calculates a future value based on rates that change for each period.

Related functions:

Arguments

  • rates - A collection of rates, one for each period.
  • present_value - The starting value of the investment.

Panics

The call will fail if any of the rates is less than -1.0 as this would mean the investment is losing more than its full value.

Examples

Calculate the value of an investment whose rates vary by year.

use finance_solution::*;
// The rates vary by year: 4% followed by -3.9%, 10.6%, and -5.7%.
let rates = [0.04, -0.039, 0.106, -0.057];

// The initial investment is $75,000.
let present_value = -75_000.00;

let future_value = future_value_schedule(&rates, present_value);
dbg!(&future_value);
assert_rounded_4(78_178.0458, future_value);

Error case: One of the rates shows a drop of over 100%. There's no way to work out what this means so the call will panic.

let rates = [0.116, -100.134, -0.09, 0.086];
let present_value = -4_000.00;
let schedule = future_value_schedule(&rates, present_value);