Skip to main content

AmortizationSolution

Struct AmortizationSolution 

Source
pub struct AmortizationSolution { /* private fields */ }
Expand description

Full amortization setup: inputs, level payment, formulas, and access to a period series.

Create with amortization_solution (returns FinanceResult).

§Examples

use finance_solution::*;

let s = amortization_solution(0.08 / 12.0, 12, 10_000.0, 0.0, false).unwrap();
println!("{}", s.formula());
println!("{}", s.symbolic_formula());
assert_eq!(s.periods(), 12);
s.print_table();

print_table() is sugar for series().print_table(true, true) and looks like:

period    payment  principal  interest     balance  ...  payments_remaining
------  ---------  ---------  --------  ----------  ...  ------------------
     1  -869.8843  -803.2176  -66.6667  9_196.7824  ...         -9_568.7272
     2  -869.8843  -808.5724  -61.3119  8_388.2100  ...         -8_698.8429
   ...
    12  -869.8843  -864.1235   -5.7608     -0.0000  ...              0.0000

Implementations§

Source§

impl AmortizationSolution

Source

pub fn rate(&self) -> f64

Periodic rate.

Source

pub fn periods(&self) -> u32

Total number of periods.

Source

pub fn present_value(&self) -> f64

Present value (principal).

Source

pub fn future_value(&self) -> f64

Future value (balloon / residual).

Source

pub fn due_at_beginning(&self) -> bool

Whether payment is due at the beginning of each period.

Source

pub fn payment(&self) -> f64

Level payment each period (Excel PMT).

Source

pub fn sum_of_payments(&self) -> f64

payment * periods.

Source

pub fn sum_of_interest(&self) -> f64

Total interest over the full term (sum_of_payments + present_value + future_value).

Source

pub fn formula(&self) -> &str

Concrete formula string with substituted values.

Source

pub fn symbolic_formula(&self) -> &str

Symbolic formula (e.g. pmt = ...).

Source

pub fn ipmt(&self, period: u32) -> FinanceResult<f64>

Interest portion for a 1-based period (Excel IPMT).

§Errors

FinanceError::InvalidPeriod if period is not in 1..=periods.

Source

pub fn ppmt(&self, period: u32) -> FinanceResult<f64>

Principal portion for a 1-based period (Excel PPMT).

§Errors

FinanceError::InvalidPeriod if period is not in 1..=periods.

Source

pub fn cumipmt(&self, start_period: u32, end_period: u32) -> FinanceResult<f64>

Cumulative interest from start_period..=end_period (1-based, inclusive).

§Errors

FinanceError::InvalidPeriod if the range is empty, inverted, or outside 1..=periods.

Source

pub fn cumprinc(&self, start_period: u32, end_period: u32) -> FinanceResult<f64>

Cumulative principal from start_period..=end_period (1-based, inclusive).

§Errors

FinanceError::InvalidPeriod if the range is empty, inverted, or outside 1..=periods.

Source

pub fn series(&self) -> AmortizationSeries

Period-by-period amortization schedule.

§Examples
use finance_solution::*;

let series = amortization_solution(0.08 / 12.0, 12, 10_000.0, 0.0, false)
    .unwrap()
    .series();
for row in series.iter() {
    assert_approx_equal!(row.principal() + row.interest(), row.payment());
}
series.print_table(true, true);

Example terminal output (first/last rows; full 12-period table in the module docs):

period    payment  principal  interest     balance  principal_to_date  ...
------  ---------  ---------  --------  ----------  -----------------  ...
     1  -869.8843  -803.2176  -66.6667  9_196.7824          -803.2176  ...
   ...
    12  -869.8843  -864.1235   -5.7608     -0.0000       -10_000.0000  ...
Source

pub fn print_table(&self)

Print the full schedule with running totals and remaining amounts.

Source

pub fn print_table_locale(&self, locale: &Locale, precision: usize)

Locale-aware table (thousands separators, decimal places).

Trait Implementations§

Source§

impl Clone for AmortizationSolution

Source§

fn clone(&self) -> AmortizationSolution

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AmortizationSolution

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.