pub fn nper<C, P, F>(
periodic_rate: f64,
payment: C,
present_value: P,
future_value: F,
) -> FinanceResult<f64>Expand description
Returns the number of periods for an annuity (payments) to reach a future value.
Related functions:
nper_solution– same calculation with a solution structnper_due– payments due at the beginning of each period
Formula (end-of-period payments):
n = ln( (pmt - fv * r) / (pmt + pv * r) ) / ln(1 + r)§Arguments
periodic_rate– growth rate per period (e.g.0.05for 5%)payment– payment per period; must be negative (Excel convention) when PV/FV are ≥ 0present_value– present value (≥ 0 in the Excel-style sign convention used here)future_value– future value (≥ 0); at least one of PV/FV must be nonzero
§Errors
Returns FinanceError when rate/payment/PV/FV cannot produce a finite period count.
§Examples
use finance_solution::{nper, FinanceError};
let n = nper(0.034, -500.0, 1000.0, 20_000.0).unwrap();
assert!((n - 27.7879559).abs() < 1e-4);
assert!(matches!(
nper(0.05, 100.0, 0.0, 1000.0),
Err(FinanceError::InvalidCashflow { .. })
));