[][src]Module finance_solution::payment

Payment calculations. What is the periodic payment needed for an amortized loan and how much of that is interest or principal?

For most common usages, we recommend the payment_solution function, which provides a better debugging experience and additional functionality.

Example

let (rate, periods, present_value, future_value, due_at_beginning) = (0.034, 10, 1000, 0, false);
let solution = finance_solution::payment_solution(rate, periods, present_value, future_value, due_at_beginning);
dbg!(&solution);

Outputs to terminal:

{
    calculated_field: Payment,
    rate: 0.034,
    periods: 10,
    present_value: 1000.0,
    future_value: 0.0,
    due_at_beginning: false,
    payment: -119.63608534268569,
    sum_of_payments: -1196.360853426857,
    sum_of_interest: -196.36085342685692,
    formula: "-119.6361 = ((1000.0000 * 1.034000^10) * -0.034000) / (1.034000^10 - 1)",
    symbolic_formula: "pmt = ((pv * (1 + r)^n) * -r) / ((1 + r)^n - 1)",
}
dbg!(solution.print_table());

Outputs to terminal:

period  payments_to_date  payments_remaining  principal  principal_to_date  principal_remaining  interest  interest_to_date  interest_remaining
------  ----------------  ------------------  ---------  -----------------  -------------------  --------  ----------------  ------------------
    1         -119.6361         -1_076.7248   -85.6361           -85.6361            -914.3639  -34.0000          -34.0000           -162.3609
    2         -239.2722           -957.0887   -88.5477          -174.1838            -825.8162  -31.0884          -65.0884           -131.2725
    3         -358.9083           -837.4526   -91.5583          -265.7421            -734.2579  -28.0778          -93.1661           -103.1947
    4         -478.5443           -717.8165   -94.6713          -360.4134            -639.5866  -24.9648         -118.1309            -78.2300
    5         -598.1804           -598.1804   -97.8901          -458.3036            -541.6964  -21.7459         -139.8768            -56.4840
    6         -717.8165           -478.5443  -101.2184          -559.5220            -440.4780  -18.4177         -158.2945            -38.0663
    7         -837.4526           -358.9083  -104.6598          -664.1818            -335.8182  -14.9763         -173.2708            -23.0901
    8         -957.0887           -239.2722  -108.2183          -772.4001            -227.5999  -11.4178         -184.6886            -11.6723
    9       -1_076.7248           -119.6361  -111.8977          -884.2978            -115.7022   -7.7384         -192.4270             -3.9339
    10      -1_196.3609             -0.0000  -115.7022          -999.0000              -0.0000   -3.9339         -196.3609              0.0000

Payment Due at the Beginning vs. the End of the Period

In a typical loan the payment is due at the end of each period. All other factors being equal, if the payment is instead due at the beginning of the period the payment amount will be slightly smaller. This is justified because it means the outstanding principal at any point during the loan will be slightly smaller since it was paid down one period earlier.

To make this concrete, suppose we have an amortized loan for $100,000 at 12% annual interest for ten years. We can run an A/B test where scenario A has the payments due at the end of the period and scenario B has them due at the beginning. We'll look at the details of the first five periods:

period  payment_a  payment_b  principal_a  principal_b  princ_remaining_a  princ_remaining_b
------  ---------  ---------  -----------  -----------  -----------------  -----------------
     1   1,434.71   1,420.50       434.71     1,420.50          99,565.29          98,579.50
     2   1,434.71   1,420.50       439.06       434.71          99,126.23          98,144.79
     3   1,434.71   1,420.50       443.45       439.06          98,682.79          97,705.73
     4   1,434.71   1,420.50       447.88       443.45          98,234.91          97,262.28
     5   1,434.71   1,420.50       452.36       447.88          97,782.54          96,814.40

For scenario A a payment of $1,434.71 is due at the end of the month and for scenario B a lower payment of $1,420.50 is due at the beginning of the month. Yet in both scenarios the loan is fully paid off by the end of the 120th period.

The reason is that the first monthly payment in the second case went entirely to paying down the principal, and from that point on the principal (the last two columns in this table) was slightly smaller at every point in time. Thus the amount of each payment that went toward the interest was smaller and the amount left to go to principal was larger.

The sum of the payments in the first case (due at the end) is $172,165.14 and the sum of the payments in the second case is $170,460.53, a difference of $1,704.61. The relationship between these sums (and the monthly payment amounts) is based on the interest rate. Specifically:

and indeed it turns out that:

which is a relief. By the way, A/B comparisons like the table above are built into the crate. See CashflowSolution::print_ab_comparison.

Positive and Negative Amounts

The example above was an amortized loan for $100,000 at 12% annual interest for ten years. Thus the present value (the original principal of the loan) was $10,000 and the future value (the amount still owed at the end) was zero. Also the rate was positive. In cases like this if the present value is entered as a positive number the payment will be negative, and vice versa:

use finance_solution::*;

let (rate, periods, present_value, due_at_beginning) = (0.01, 120, 100_000, false);

let pmt_positive_present_value = payment(rate, periods, present_value, 0.0, due_at_beginning);
assert_rounded_2!(-1_434.71, pmt_positive_present_value);

let pmt_negative_present_value = payment(rate, periods, -present_value, 0.0, due_at_beginning);
assert_rounded_2!(1_434.71, pmt_negative_present_value);

Either way is fine. It depends on whether we're thinking of the payment as a stream of money being paid out or coming in. In the period-by-period detail the principal and interest (and remaining principal and interest and so on) for each period will have the same sign as the payment.

Formulas

Present Value but no Future Value

In the typical case of an amortized loan the present value will be nonzero and the future value will be zero. This represents the loan being paid off by the end of the last period.

If the payment is due at the end of the period the calculation is:

or with some of the more commonly used variables:

Often the payment is shown as A and the present value is P for principal. In this crate we use the same symbols for present value, rate, etc. across all of the functions.

If the payment is due at the beginning of the period the only difference is that we have to divide the above payment by (1 + rate). So the formula is:

Future Value but no Present Value

If there's a future value and the present value is zero, and the payment is due at the end of the period, the formula is:

or:

If the payment is due at the beginning of the period it's:

Both Present Value and Future Value

If both present value and future value are nonzero the formula is:

or:

If the payment is due at the beginning of the period it's:

Structs

PaymentSeries
PaymentSolution

Functions

payment

Returns the payment needed at the end of every period for an amortized loan.

payment_solution

Calculates the payment needed for each period for an amortized loan and creates a struct showing the interest, the formula, and optionally the period-by-period values.