[−][src]Function finance_solution::rate_solution
pub fn rate_solution<P, F>(
periods: u32,
present_value: P,
future_value: F,
continuous_compounding: bool
) -> TvmSolution 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 returning an f64 value instead of solution object, use
rate
.
Arguments
periods
- The number of periods such as quarters or periods. Often appears asn
ort
.present_value
- The starting value of the investment. May appear aspv
in formulas, orC
for cash flow orP
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
Calculate a periodic rate and examine the period-by-period values.
use finance_solution::*; // The interest will compound for ten periods. // The starting value is $10,000. // The ending value is $15,000. let periods = 10; let present_value = -10_000.00; let future_value = 15_000.00; let continuous_compounding = false; /// // Calculate the periodic rate and create a struct with a record of the // inputs, a description of the formula, and an option to calculate the // period-by-period values. let solution = rate_solution(periods, present_value, future_value, continuous_compounding); dbg!(&solution); let rate = solution.rate(); dbg!(&rate); // The rate is 4.138% per period. assert_rounded_6(0.041380, rate); // Examine the formulas. let formula = solution.formula(); dbg!(&formula); assert_eq!("0.041380 = ((-15000.0000 / -10000.0000) ^ (1 / 10)) - 1", formula); let symbolic_formula = solution.symbolic_formula(); dbg!(&symbolic_formula); assert_eq!("r = ((-fv / pv) ^ (1 / n)) - 1", symbolic_formula); // Calculate the period-by-period values. let series = solution.series(); dbg!(&series);