pub fn ipmt<P, F, T>(
rate: f64,
period: u32,
periods: u32,
present_value: P,
future_value: F,
timing: T,
) -> FinanceResult<f64>Expand description
Interest portion of the payment for a single period (Excel IPMT).
§Arguments
rate– periodic rateperiod– 1-based period index (1..=periods)periods– total number of periodspresent_value– principal / PVfuture_value– residual value at end (often 0)timing– [PaymentTiming] orbool(false= end of period / Exceltype=0)
§Errors
Propagates construction errors from amortization_solution and
FinanceError::InvalidPeriod when period is out of range.
§Examples
use finance_solution::*;
let interest = ipmt(0.01, 1, 12, 10_000.0, 0.0, false).unwrap();
assert!(interest < 0.0); // opposite sign of positive principal
assert_rounded_2!(interest, -100.0);For schedules and tables, prefer amortization_solution:
use finance_solution::*;
let s = amortization_solution(0.01, 12, 10_000.0, 0.0, false).unwrap();
assert_approx_equal!(
s.ipmt(1).unwrap(),
ipmt(0.01, 1, 12, 10_000.0, 0.0, false).unwrap()
);Out-of-range period:
use finance_solution::{ipmt, FinanceError};
match ipmt(0.01, 1, 12, 10_000.0, 0.0, false) {
Ok(interest) => assert!(interest < 0.0),
Err(FinanceError::InvalidPeriod { period, periods, .. }) => {
panic!("period {period} not in 1..={periods}");
}
Err(e) => panic!("{e}"),
}
assert!(matches!(
ipmt(0.01, 0, 12, 10_000.0, 0.0, false),
Err(FinanceError::InvalidPeriod { .. })
));