pub fn future_value_schedule_solution<T>(
rates: &[f64],
present_value: T,
) -> TvmScheduleSolutionExpand description
Calculates a future value based on rates that change for each period, returning a struct with all of the inputs and results.
Related functions:
- For simply calculating a single future value using a fixed rate use [
future_value]. - To calculate a future value with a fixed rate and return a struct that shows the formula and
optionally produces the the period-by-period values use
future_value_solution. - To calculate the future value if the rates vary by period use
future_value_schedule.
§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: 8.1% followed by 11%, 4%, and -2.3%.
let rates = [0.081, 0.11, 0.04, -0.023];
// The initial investment is $10,000.
let present_value = -10_000.00;
let solution = future_value_schedule_solution(&rates, present_value);
dbg!(&solution);
let future_value = solution.future_value();
dbg!(&future_value);
assert_rounded_4(future_value, 12_192.0455);
// Calculate the value for each period.
let series = solution.series();
dbg!(&series);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);