[][src]Function finance_solution::present_value_schedule_solution

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

Calculates a present value based on rates that change for each period and returns a struct with the inputs and the calculated value.

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 value of an investment whose rates vary by year, then view only those periods where the rate is negative.

use finance_solution::*;

// The quarterly rate varies from -0.5% to 4%.
let rates = [0.04, 0.008, 0.0122, -0.005];

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

// Calculate the present value and keep track of the inputs and the formula
// in a struct.
let solution = present_value_schedule_solution(&rates, future_value);
dbg!(&solution);

let present_value = solution.present_value();
assert_rounded_4(present_value, -23_678.6383);

// Calculate the value for each period.
let series = solution.series();
dbg!(&series);