pub fn future_value_schedule<T>(
rates: &[f64],
present_value: T,
) -> FinanceResult<f64>Expand description
Calculates a future value based on rates that change for each period.
Related functions:
- To calculate the future value with varying rates and return a struct that can produce the
period-by-period values use
future_value_schedule_solution. - If there is a single fixed rate use [
future_value] orfuture_value_solution.
§Arguments
rates- A collection of rates, one for each period.present_value- The starting 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.
§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).unwrap();
dbg!(&future_value);
assert_rounded_4(78_178.0458, future_value);Error case: One of the rates shows a drop of over 100%.
let rates = [0.116, -100.134, -0.09, 0.086];
let present_value = -4_000.00;
let err = future_value_schedule(&rates, present_value).unwrap_err();
assert!(matches!(err, FinanceError::InvalidRate { .. }));§Errors
Returns FinanceError::InvalidRate if any rate is out of domain, or
FinanceError::NonFinite for non-finite inputs/results.
An empty rates slice is valid and means zero periods (returns -present_value).