[][src]Function finance_solution::present_value_schedule

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

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

Related functions:

Arguments

  • rates - A collection of rates, one for each period.
  • future_value - The ending 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 every period. It will fail also if the future value is zero as in this case there's no way to determine the present value.

Examples

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

// The annual rate varies from -3.4% to 12.9%.
let rates = [0.04, -0.034, 0.0122, 0.129, 8.5];

// The value of the investment after applying all of these periodic rates
// will be $30_000.
let future_value = 30_000.00;

// Calculate the present value.
let present_value = finance_solution::present_value_schedule(&rates, future_value);
dbg!(&present_value);