Function future_value

Source
pub fn future_value<T>(
    rate: f64,
    periods: u32,
    present_value: T,
    continuous_compounding: bool,
) -> f64
where T: Into<f64> + Copy,
Expand description

Returns the value of an investment after it has grown or shrunk over time, using a fixed rate.

See the future_value module page for the formulas.

Related functions:

§Arguments

  • rate - The rate at which the investment grows or shrinks per period, expressed as a floating point number. For instance 0.05 would mean 5% growth. Often appears as r or i in formulas.
  • periods - The number of periods such as quarters or periods. Often appears as n or t.
  • present_value - The starting value of the investment. May appear as pv in formulas, or C for cash flow or P for principal.
  • continuous_compounding - True for continuous compounding, false for simple compounding.

§Panics

The call will fail if rate is less than -1.0 as this would mean the investment is losing more than its full value every period.

§Examples

Investment that grows quarter by quarter.

use finance_solution::*;

// The investment grows by 3.4% per quarter.
let rate = 0.034;

// The investment will grow for 5 quarters.
let periods = 5;

// The initial investment is $250,000.
let present_value = -250_000;

let continuous_compounding = false;

let future_value = future_value(rate, periods, present_value, continuous_compounding);
// Confirm that the future value is correct to four decimal places (one
// hundredth of a cent).
assert_rounded_4(295_489.9418, future_value);

Investment that loses money each year.

// The investment loses 5% per year.
let rate = -0.05;

// The investment will shrink for 6 periods.
let periods = 6;

// The initial investment is $10,000.75.
let present_value = -10_000.75;

let continuous_compounding = false;

let future_value = future_value(rate, periods, present_value, continuous_compounding);
// Confirm that the future value is correct to the penny.
assert_rounded_2(7351.47, future_value);

Error case: The investment loses 105% per year. There’s no way to work out what this means so the call will panic.

let (rate, periods, present_value, continuous_compounding) = (-1.05, 6, 10_000.75, false);
let future_value = future_value(rate, periods, present_value, continuous_compounding);