loan_calculator.schedule package

Submodules

loan_calculator.schedule.base module

class loan_calculator.schedule.base.AmortizationScheduleType[source]

Bases: enum.Enum

An enumeration.

constant_amortization_schedule = 'constant-amortization-schedule'
progressive_price_schedule = 'progressive-price-schedule'
regressive_price_schedule = 'regressive-price-schedule'
class loan_calculator.schedule.base.BaseSchedule(principal, daily_interest_rate, return_days)[source]

Bases: object

Base amortization schedule.

Specific amortization schedules should subclass this class and implement the methods

  • calculate_due_payments
  • calculate_balance
  • calculate_interest_payments
  • calculate_amortizations

These methods do not receive any parameters and should be able to return based only on principal, daily_interest_rate and return_days.

principal: float, required
Loan’s principal.
daily_interest_rate: float, required
Loan’s daily interest rate.
return_days: list, required
List of integers representing the number of days since the loan was granted until the payments’ due dates.
calculate_amortizations()[source]
calculate_balance()[source]
calculate_due_payments()[source]
calculate_interest_payments()[source]
schedule_type = None
total_amortization
total_interest
total_paid

loan_calculator.schedule.constant module

class loan_calculator.schedule.constant.ConstantAmortizationSchedule(principal, daily_interest_rate, return_days)[source]

Bases: loan_calculator.schedule.base.BaseSchedule

Implement constant amortization schedule.

The constant amortization schedule is defined as the amortization schedule where all the amortizations have the same value, given as \(s/k\), where \(s\) is the principal and \(k\) is the number of due payments. Therefore, the due payments do not have all the same value, as in the French system, but differ according to how much interest was accumulated over time. If \(d\) is the daily interest rate, \(P_i\) is the \(i\)-th due payment, \(A_i\) and \(J_i\) are the associated amortization and interest, respectively, and \(b_i\) is the balance after the \(i\)-th payment, then

  • \(A_i = \frac{s}{k}\).
  • \(J_i = ((1+d)^{n_i} - (1+d)^{n_{i-1}}) (s - A\displaystyle\sum_{1\leq j\leq i-1}\frac{1}{(1+d)^{n_j}})\).
  • \(P_i = A + J_i\).
  • \(b_i = s - iA\).
calculate_amortizations()[source]

Calculate the amortizations by payments.

Since this is a constant amortization schedule, all amortizations have the same value, given by

\[A_i := \frac{s}{k},\mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(s\) is the principal and \(k\) is the number of instalments.

calculate_balance()[source]

Calculate the balance after each payment.

The balance after each payment is given by

\[b_i := s(1 - \frac{i}{k}), \ \mathrm{for\ all}\ i,0\leq i\leq k,\]

where \(s\) is the principal and \(k\) is the number of instalments.

calculate_due_payments()[source]

Calculate the due payments.

In the constant amortization schedule, the instalment value is not fixed as in Price type schedules but depends on how much interest is due for each period and the amortization, which is constant. The payments are then given by

\[P_i = b_{i-1}((1+d)^{n_i-n_{i-1}}-1) + \frac{S}{k}, \ \mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(b_{i-1}\) is the \((i-1)\)-th balance, \(d\) is the daily interest rate, \(S\) is the principal and \(n_1,\ldots,n_k\) are the return days.

calculate_interest()[source]

Calculate the interest in each payment.

The interest is calculated over the last balance and is given by

\[J_i := b_{i-1}((1+d)^{n_i-n_{i-1}}-1) \ \mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(b_{i-1}\) is the \((i-1)\)-th balance, \(d\) is the daily interest rate and \(n_1,\ldots,n_k\) are the return days.

schedule_type = 'constant-amortization-schedule'

loan_calculator.schedule.price module

class loan_calculator.schedule.price.BasePriceSchedule(principal, daily_interest_rate, return_days)[source]

Bases: loan_calculator.schedule.base.BaseSchedule

Base class for Price type amortization schedules.

Price amortization schedules are characterized by the payment value, which is the same for all instalments. The distributions of amortization and interest in each payment are given by either a increasing or decreasing rule over the amortizations. Both are implemented as subclasses of this.

calculate_balance()[source]

Calculate the balance after each payment.

Implements the balance as defined by

\[b_i := s(1+d)^{n_i}(1 - \frac{\sum_{j=1}^i\frac{1}{(1+d)^{n_j}}} {\sum_{j=1}^k\frac{1}{(1+d)^{n_j}}}), \mathrm{for}\ i,0\leq i\leq k\]

where \(s\) is the principal, \(d\) is the daily interest rate and \(n_1,\ldots,n_k\) are the return days.

This equation can be directly deduced from the recursive definition of the balance given by

\[\begin{split}b_i = \left\{ \begin{aligned} b_{i-1}(1+d)^{n_i-n_{i-1}} - P, &\ \mathrm{if}\ i,1\leq i\leq k \\ s, &\ \mathrm{if}\ i = 0 \end{aligned} \right.,\end{split}\]

where \(P = \mathrm{PMT}(s,d,(n_1,\ldots,n_k))\).

calculate_due_payments()[source]

Calculate due payments.

Since this is a Price schedule, all due payments have the same value.

class loan_calculator.schedule.price.ProgressivePriceSchedule(principal, daily_interest_rate, return_days)[source]

Bases: loan_calculator.schedule.price.BasePriceSchedule

Implement progressive Price amortization schedule.

The progressive Price amortization schedule, or French amortization system, defines a schedule where all instalments have the same value and the amortizations and interest are calculated based on the principal, return days and daily interest rate.

The amortizations are defined as the leftover after interest payment, i.e., it is first calculated how much interest should be paid over the last balance, and the exceeding payment is used as amortization.

In this schedule, the amortization values increase over time, hence the name progressive.

If we denote by \(P\) the instalment value, \(s\) the principal, \(d\) the daily interest rate, \(n_i\) the number of days since the beginning of the operation until the \(i\)-th due date, \(A_i\) the \(i\)-th amortization and \(J_i\) the \(i\)-th interest paid and \(b_i\) the balance after the \(i\)-th payment, then

  • \(P=\mathrm{PMT}(s,d,(n_1,\ldots,n_k))\).
  • \(b_i = b_{i-1}(1+d)^{n_i-n_{i-1}} - P\).
  • \(J_i = P - b_{i-1}((1+d)^{n_i-n_{i-1}}-1)\).
  • \(A_i = P - J_i\).
calculate_amortizations()[source]

Calculate the principal amortization due to each payment.

Calculate the principal amortization as defined by

\[A_i := \frac{P}{(1+d)^{n_{k-i+1}}}, \mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(d\) is the daily interest rate, \(n_1,\ldots,n_k\) are the return days and \(P=\mathrm{PMT}(s,d,(n_1,\ldots,n_k))\).

calculate_interest()[source]

Calculate interest in each payment.

Calculate the interest as defined by

\[J_i = \frac{P}{(1+d)^{n_{k-i+1}}}, \mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(d\) is the daily interest rate, \(P\) is the PMT, and \(n_1,\ldots,n_k\) are the return days.

schedule_type = 'progressive-price-schedule'
class loan_calculator.schedule.price.RegressivePriceSchedule(principal, daily_interest_rate, return_days)[source]

Bases: loan_calculator.schedule.price.BasePriceSchedule

Implement regressive Price amortization schedule.

The regressive Price amortization schedule defines a schedule where all instalments have the same value and the amortization and interest distribution is calculated based on the principal, daily interest rate and return days.

The amortizations are defined as the present value of each payment. The interest is then defined as the remaining instalment value after amortization.

In this schedule, the amortization values decrease over time, hence the name regressive.

If we denote by \(P\) the instalment value, \(S\) the principal, \(d\) the daily interest rate, \(n_i\) the number of days since the beginning of the operation until the \(i\)-th due date, \(A_i\) the \(i\)-th amortization and \(J_i\) the \(i\)-th interest paid and \(b_i\) the balance after the \(i\)-th payment, then

  • \(P=\mathrm{PMT}(s,d,(n_1,\ldots,n_k))\).
  • \(b_i = b_{i-1}(1+d)^{n_i-n_{i-1}} - P\).
  • \(A_i = \displaystyle\frac{P}{(1+d)^{n_i}}\).
  • \(J_i = P(1 - \displaystyle\frac{P}{(1+d)^{n_i}})\).
calculate_amortizations()[source]

Calculate the amortization due to each payment.

The amortization is considered to be the present value of each payment, therefore is given by

\[A_i := \frac{P}{(1+d)^{n_i}} \ \mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(d\) is the daily interest rate, \(n_i\) is the \(i\)-th return date and \(P = \mathrm{PMT}(s,d,(n_1,\ldots,n_k))\)

calculate_interest()[source]

Calculate the interest in each payment.

The interest is defined as the leftover after the present value of the payment is used as a principal amortization, i.e., defined by

\[J_i := P (1-\frac{1}{(1+d)^{n_i}}), \mathrm{for\ all}\ i,1\leq i\leq n,\]

where \(d\) is the daily interest rate, \(n_i\) is the \(i\)-th return date and \(P = \mathrm{PMT}(s,d,(n_1,\ldots,n_k))\)

schedule_type = 'regressive-price-schedule'

Module contents

class loan_calculator.schedule.ProgressivePriceSchedule(principal, daily_interest_rate, return_days)[source]

Bases: loan_calculator.schedule.price.BasePriceSchedule

Implement progressive Price amortization schedule.

The progressive Price amortization schedule, or French amortization system, defines a schedule where all instalments have the same value and the amortizations and interest are calculated based on the principal, return days and daily interest rate.

The amortizations are defined as the leftover after interest payment, i.e., it is first calculated how much interest should be paid over the last balance, and the exceeding payment is used as amortization.

In this schedule, the amortization values increase over time, hence the name progressive.

If we denote by \(P\) the instalment value, \(s\) the principal, \(d\) the daily interest rate, \(n_i\) the number of days since the beginning of the operation until the \(i\)-th due date, \(A_i\) the \(i\)-th amortization and \(J_i\) the \(i\)-th interest paid and \(b_i\) the balance after the \(i\)-th payment, then

  • \(P=\mathrm{PMT}(s,d,(n_1,\ldots,n_k))\).
  • \(b_i = b_{i-1}(1+d)^{n_i-n_{i-1}} - P\).
  • \(J_i = P - b_{i-1}((1+d)^{n_i-n_{i-1}}-1)\).
  • \(A_i = P - J_i\).
calculate_amortizations()[source]

Calculate the principal amortization due to each payment.

Calculate the principal amortization as defined by

\[A_i := \frac{P}{(1+d)^{n_{k-i+1}}}, \mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(d\) is the daily interest rate, \(n_1,\ldots,n_k\) are the return days and \(P=\mathrm{PMT}(s,d,(n_1,\ldots,n_k))\).

calculate_interest()[source]

Calculate interest in each payment.

Calculate the interest as defined by

\[J_i = \frac{P}{(1+d)^{n_{k-i+1}}}, \mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(d\) is the daily interest rate, \(P\) is the PMT, and \(n_1,\ldots,n_k\) are the return days.

schedule_type = 'progressive-price-schedule'
class loan_calculator.schedule.RegressivePriceSchedule(principal, daily_interest_rate, return_days)[source]

Bases: loan_calculator.schedule.price.BasePriceSchedule

Implement regressive Price amortization schedule.

The regressive Price amortization schedule defines a schedule where all instalments have the same value and the amortization and interest distribution is calculated based on the principal, daily interest rate and return days.

The amortizations are defined as the present value of each payment. The interest is then defined as the remaining instalment value after amortization.

In this schedule, the amortization values decrease over time, hence the name regressive.

If we denote by \(P\) the instalment value, \(S\) the principal, \(d\) the daily interest rate, \(n_i\) the number of days since the beginning of the operation until the \(i\)-th due date, \(A_i\) the \(i\)-th amortization and \(J_i\) the \(i\)-th interest paid and \(b_i\) the balance after the \(i\)-th payment, then

  • \(P=\mathrm{PMT}(s,d,(n_1,\ldots,n_k))\).
  • \(b_i = b_{i-1}(1+d)^{n_i-n_{i-1}} - P\).
  • \(A_i = \displaystyle\frac{P}{(1+d)^{n_i}}\).
  • \(J_i = P(1 - \displaystyle\frac{P}{(1+d)^{n_i}})\).
calculate_amortizations()[source]

Calculate the amortization due to each payment.

The amortization is considered to be the present value of each payment, therefore is given by

\[A_i := \frac{P}{(1+d)^{n_i}} \ \mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(d\) is the daily interest rate, \(n_i\) is the \(i\)-th return date and \(P = \mathrm{PMT}(s,d,(n_1,\ldots,n_k))\)

calculate_interest()[source]

Calculate the interest in each payment.

The interest is defined as the leftover after the present value of the payment is used as a principal amortization, i.e., defined by

\[J_i := P (1-\frac{1}{(1+d)^{n_i}}), \mathrm{for\ all}\ i,1\leq i\leq n,\]

where \(d\) is the daily interest rate, \(n_i\) is the \(i\)-th return date and \(P = \mathrm{PMT}(s,d,(n_1,\ldots,n_k))\)

schedule_type = 'regressive-price-schedule'
class loan_calculator.schedule.ConstantAmortizationSchedule(principal, daily_interest_rate, return_days)[source]

Bases: loan_calculator.schedule.base.BaseSchedule

Implement constant amortization schedule.

The constant amortization schedule is defined as the amortization schedule where all the amortizations have the same value, given as \(s/k\), where \(s\) is the principal and \(k\) is the number of due payments. Therefore, the due payments do not have all the same value, as in the French system, but differ according to how much interest was accumulated over time. If \(d\) is the daily interest rate, \(P_i\) is the \(i\)-th due payment, \(A_i\) and \(J_i\) are the associated amortization and interest, respectively, and \(b_i\) is the balance after the \(i\)-th payment, then

  • \(A_i = \frac{s}{k}\).
  • \(J_i = ((1+d)^{n_i} - (1+d)^{n_{i-1}}) (s - A\displaystyle\sum_{1\leq j\leq i-1}\frac{1}{(1+d)^{n_j}})\).
  • \(P_i = A + J_i\).
  • \(b_i = s - iA\).
calculate_amortizations()[source]

Calculate the amortizations by payments.

Since this is a constant amortization schedule, all amortizations have the same value, given by

\[A_i := \frac{s}{k},\mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(s\) is the principal and \(k\) is the number of instalments.

calculate_balance()[source]

Calculate the balance after each payment.

The balance after each payment is given by

\[b_i := s(1 - \frac{i}{k}), \ \mathrm{for\ all}\ i,0\leq i\leq k,\]

where \(s\) is the principal and \(k\) is the number of instalments.

calculate_due_payments()[source]

Calculate the due payments.

In the constant amortization schedule, the instalment value is not fixed as in Price type schedules but depends on how much interest is due for each period and the amortization, which is constant. The payments are then given by

\[P_i = b_{i-1}((1+d)^{n_i-n_{i-1}}-1) + \frac{S}{k}, \ \mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(b_{i-1}\) is the \((i-1)\)-th balance, \(d\) is the daily interest rate, \(S\) is the principal and \(n_1,\ldots,n_k\) are the return days.

calculate_interest()[source]

Calculate the interest in each payment.

The interest is calculated over the last balance and is given by

\[J_i := b_{i-1}((1+d)^{n_i-n_{i-1}}-1) \ \mathrm{for\ all}\ i,1\leq i\leq k,\]

where \(b_{i-1}\) is the \((i-1)\)-th balance, \(d\) is the daily interest rate and \(n_1,\ldots,n_k\) are the return days.

schedule_type = 'constant-amortization-schedule'