[][src]Function finance_solution::present_value

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

Returns the current value of a future amount using a fixed rate.

Related functions:

See the present_value module page for the formulas.

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 years. Often appears as n or t.
  • future_value - The final value of the investment.
  • 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. It will fail also if the future value is zero as in this case there's no way to determine the present value.

Examples

Investment that grows month by month.

use finance_solution::*;

// The investment will grow by 1.1% per month.
let rate = 0.011;

// The investment will grow for 12 months.
let periods = 12;

// The final value will be $50,000.
let future_value = 50_000;

let continuous_compounding = false;

// Find the current value.
let present_value = present_value(rate, periods, future_value, continuous_compounding);
dbg!(&present_value);

// Confirm that the present value is correct to four decimal places (one hundredth of a cent).
assert_rounded_4(-43_848.6409, present_value);

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

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