pub fn present_value_schedule<T>(
rates: &[f64],
future_value: T,
) -> FinanceResult<f64>Expand description
Calculates a present value based on rates that change for each period.
Related functions:
- To calculate the present value with varying rates and return a struct that can produce the
period-by-period values use
present_value_schedule_solution. - If there is a single fixed rate use present_value or present_value_solution.
§Arguments
rates- A collection of rates, one for each period.future_value- The ending value of the investment.
§Errors
The call returns FinanceError 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 returns an error 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).unwrap();
dbg!(&present_value);