[][src]Function finance_solution::rate

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

Returns the periodic rate of an investment given the number of periods along with the present and future values.

See the rate module page for the formulas.

Related functions:

  • To calculate a periodic rate and return a struct that shows the formula and optionally produces the the period-by-period values use rate_solution.

Arguments

  • 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.
  • future_value - The final value of the investment.
  • continuous_compounding - True for continuous compounding, false for simple compounding.

If present_value and future_value are both zero then any rate will work so the function returns zero.

Panics

The call will fail if the present value is zero and the future value is nonzero or vice versa. It will also fail if the number of periods is zero and the present value is not equal to the future value. In both cases this is because there's no periodic rate that could make that work.

Examples

use finance_solution::*;

// The interest will compound for 365 days.
let periods = 365;

// The starting value is $10,000.
let present_value = -10_000.00;

// The ending value is $11,000.
let future_value = 11_000.00;

let continuous_compounding = false;

// Calculate the periodic rate needed.
let rate = rate(periods, present_value, future_value, continuous_compounding);
dbg!(&rate);
// The rate is 0.0261% per day.
assert_rounded_6(0.000261, rate);