Reference

Public API

class loan_calculator.loan.Loan(principal, annual_interest_rate, start_date, return_dates, year_size=<YearSizeType.commercial: 365>, grace_period=0, amortization_schedule_type='progressive-price-schedule')[source]

Loan.

principal : float, required
The loan’s principal.
annual_interest_rate : float, required
The loan’s annual interest rate.
start_date : date, required
The loan’s reference date. This date is usually the one when the borrower signed the loan’s contract.
return_dates : list, required
List of date objects with the expected return dates. These dates are usually contractually agreed.
year_size : int, optional
The reference year size for converting from annual to daily interest rates. (default 365)
grace_period : int, optional
The number of days for which the principal is not affected by the capitalization process. (default 0)
amortization_schedule_type : str, optional
A discriminator string indicating the amortization schedule to be adopted. The available schedules are progressive_price_schedule, regressive_price_schedule, constant_amortization_schedule. (default AmortizationScheduleType.progressive_price_schedule.value).
class loan_calculator.grossup.base.BaseGrossup(base_loan, reference_date, *args)[source]

Base class for grossup implementations.

This base class is meant to be subclassed to specific implementations of the grossup problem.

base_loan : Loan, required
Loan to be grossed up.
reference_date : date, required
Reference used to the gross up evaluation. It is usually the date of the associated taxable event.
args
Passed as args to grossup implementation.
base_principal

Principal of the base loan.

grossed_up_principal

Principal of the grossed up loan.

irr

Approximation for the IRR affecting the net principal.

class loan_calculator.grossup.base.GrossupType[source]

An enumeration.

class loan_calculator.grossup.iof.IofGrossup(base_loan, reference_date, daily_iof_aliquot=8.2e-05, complementary_iof_aliquot=0.0038, service_fee_aliquot=0.0)[source]

Implement grossup based on IOF tax and linear service fee.

The mathematical model for this grossup is given by

\[s - \sum_{i=1}^k A(n_i-n_d,d,s)\min((n_i-n_d)I^*,1\frac{1}{2}\%) - sI^{**} - gs = s_\circ\]

where

  • \(s\) is the grossed up principal,
  • \(s_\circ\) is the net principal,
  • \(d\) is the daily interest rate,
  • \(n_d\) is the number of days in the grace period,
  • \(n_i\) is the number of days since the contract start,
  • \(A(n_i,n_d,d,s)\) is the amortization for the given parameters,
  • \(I^{*}\) is the reduced IOF tax aliquot,
  • \(I^{**}\) is the complementary IOF tax aliquot, and
  • \(g\) is the service fee aliquot.
reference_date : date, required
The date the loan’s net principal is made available.
daily_iof_aliquot : float, optional
Reduced IOF tax aliquot. The amortizations are the tax calculation basis and the aliquot is incident in proportion to the number of days since the taxable event. The IOF taxes over the amortization are summed up this aggregated value is the due tax over the amortizations. (Default 0.000082)
complementary_iof_aliquot : float, optional
Complementary IOF tax aliquot. The tax calculation basis is the principal. (Default 0.0038)
service_fee_aliquot : float, optional
Aliquot applied over the principal and is meant to model the service fee. (Default 0.0)

pmt

loan_calculator.pmt.constant_return_pmt(principal, daily_interest_rate, return_days)[source]

Calculate the PMT (payment value) for the given parameters.

If \(s\) is the principal, \(d\) is the daily interest rate and \((n_1,\ldots,n_k)\) is the vector with the number of days since the start reference date, then the PMT is given by

\[\mathrm{PMT}\ (s, d, (n_1,\ldots,n_k)) = \frac{s}{\sum\frac{1}{(1+d)^{n_j}}},\]

where the sum is taken for \(j,1\leq j\leq k\).

principal : float, required
The value which should be fully paid by consecutive payments with value returned by this function.
daily_interest_rate : float, required
The daily rate at which the principal grows over time.
return_days : list, required
List of integers representing the numbers of days since the start reference date.

The required payment value for the given parameters.

interest_rate

class loan_calculator.interest_rate.InterestRateType[source]

An enumeration.

class loan_calculator.interest_rate.YearSizeType[source]

An enumeration.

loan_calculator.interest_rate.convert_to_daily_interest_rate(interest_rate_aliquot, interest_rate_type=<InterestRateType.daily: 'daily'>, year_size=<YearSizeType.commercial: 365>)[source]

“Convert aliquots from a given rate to a daily interest rate.

This function will convert an aliquot from a given rate (as in InterestRateType) to a daily interest rate, since “a day” is the default unit time adopted for financial modelling in this library. It is also important to note that the proper conversion of rates depends on the size of a year in days.

interest_rate_aliquot: float, required
Aliquot to be converted to a daily interest rate aliquot.
interest_rate_type: InterestRateType, optional
The type of rate in which the input aliquot is capitalized (default: InterestRateType.daily).
year_size: YearSizeType, optional
A year size is necessary since monthly, quarterly and semiannual rates are relative to an annum (default YearSizeType.commercial).
float
Aliquot as a daily interest rate.
TypeError
If the interest_rate_type is none one of the enumerated in InterestRateType.

grossup.functions

Provide functions implementation of different grossup cases.

The grossup of a net principal is an augmented principal value whose net value corresponds to the given net principal. The net value of a principal is the one obtained after subtracting due taxes and service fees according to very specific mathematical rule.

loan_calculator.grossup.functions.br_iof_constant_amortization_grossup(net_principal, daily_interest_rate, daily_iof_fee, complementary_iof_fee, return_days, service_fee)[source]

Calculate the grossup of the principal and given parameters.

This implements a grossup for which

  • the principal is amortized according to a constant amortization schedule
  • the principal and the payments are taxed with IOF,
  • a service fee is applied over the principal.

If \(s\) is the principal, \(d\) is the daily interest rate, \(I^*\) is the daily IOF fee, \(I^{**}\) is the complementary IOF fee, \(g\) is the service fee and \((n_1,n_2,\ldots,n_k)\) is the vector with the return dates, then the grossup is given by

\[\mathrm{GROSSUP}(s, d, I^*, I^{**}, (n_1,\ldots,n_k), g) = \frac{s} {1 - \alpha - I^{**} - g},\]

where

\[\alpha := \frac{1}{k} \frac{\displaystyle\sum_{j=1}^k \min(n_j\ I^*, 0.015)} {\displaystyle\sum_{j=1}^k\frac{1}{(1+d)^{n_j}}}.\]
loan_calculator.grossup.functions.br_iof_progressive_price_grossup(net_principal, daily_interest_rate, daily_iof_fee, complementary_iof_fee, return_days, service_fee)[source]

Calculate the grossup of the principal for the given parameters.

This implements a grossup for which

  • the principal is amortized according to a progressive Price schedule,
  • the principal is taxed, as well as its payments, by IOF
  • a fee is applied over the principal

If \(s\) is the principal, \(d\) is the daily interest rate, \(I^*\) is the daily IOF fee, \(I^{**}\) is the complementary IOF fee, \(g\) is the service fee and \((n_1,n_2,\ldots,n_k)\) is the vector with the return dates, then the grossup is given by

\[\mathrm{GROSSUP}(s, d, I^*, I^{**}, (n_1,\ldots,n_k), g) = \frac{s}{1 - \alpha - I^{**} - g },\]

where

\[\alpha := \frac { \displaystyle \sum_{j=1}^k\frac{\min(n_j\ I^*, 0.015)}{(1+d)^{n_j}}} { \displaystyle\sum_{j=1}^k\frac{1}{(1+d)^{n_j}}}.\]
net_principal : float, required
The principal to be “grossed up”.
daily_interest_rate : float, required
The rate at which the principal grows over time.
daily_iof_fee : float, required
Daily tax due to brazilian tax IOF.
complementary_iof_fee : float, required
Complementary tax due to brazilian tax IOF.
return_days : list, required
List containing the number of days since the start reference date.
service_fee : float, optional
Eventual service fee. It is assumed to be an aliquot applied on the principal

The grossed up principal.

loan_calculator.grossup.functions.br_iof_regressive_price_grossup(net_principal, daily_interest_rate, daily_iof_fee, complementary_iof_fee, return_days, service_fee)[source]

Calculate the grossup of the given principal.

This function implements a grossup for which - the principal is amortized according to a regressive Price schedule, - the principal and the payments are taxed by IOF, - a fee is calculated over the principal.

If \(s\) is the principal, \(d\) is the daily interest rate, \(I^*\) is the daily IOF fee, \(I^{**}\) is the complementary IOF fee, \(g\) is the service fee and \((n_1,n_2,\ldots,n_k)\) is the vector with the return dates, then the grossup is given by

\[\mathrm{GROSSUP}\ (s, d, I^*, I^{**}, (n_1,\ldots,n_k), g) =\frac{s}{1 - \alpha - I^{**} - g},\]

where

\[\alpha := \frac{ \displaystyle\sum_{j=1}^k\frac{\min(n_{k-j+1}\ I^*, 0.015)} {(1+d)^{n_j}}} {\displaystyle\sum_{j=1}^k\frac{1}{(1+d)^{n_j}}}.\]
net_principal : float, required
The principal to be “grossed up”.
daily_interest_rate : float, required
The rate at which the principal grows over time.
daily_iof_fee : float, required
Daily tax due to brazilian tax IOF.
complementary_iof_fee : float, required
Complementary tax due to brazilian tax IOF.
return_days : list, required
List containing the number of days since the start reference date.
service_fee : float, optional
Eventual service fee. It is assumed to be an aliquot applied on the principal

The grossed up principal.

grossup.iof_tax

Calculate the Brazilian IOF tax on loan operations.

The IOF tax (Imposto sobre Operações de Crédito, Câmbio e Seguro ou relativas a Títulos ou Valores Mobiliários) is a Brazilian tax incident over many financial operations. In particular, they apply on loan operations, the borrower being either a legal or natural person. It is institutionalized by the law-decree Nº 6.306, from December 14th, 2007, as in its text.

This tax is composed by two parts: the tax over the principal and the tax over the amortizations.

The IOF aliquot over amortizations is
  • in proportion to the number of days since the loan was granted,
  • in proportion to a fixed reduced aliquot with its value defined by law,
  • limited to 1.5%.

The IOF aliquot over the principal, called the complementary IOF aliquot, is a fixed aliquot with its value defined by law.

loan_calculator.grossup.iof_tax.amortization_iof(amortization, num_days, daily_iof_aliquot=8.2e-05)[source]

IOF tax over amortization.

If \(A\) is the amortization, \(I^*\) is the daily IOF fee and \(n\) is the number of days since taxable event, then the due IOF tax over the amortization is

\[A\ \min(nI^*, 0.015).\]
amortization: float, required
The amortization, i.e., principal payment, which is the basis for the amortization IOF tax.
daily_iof_aliquot: float, required
Aliquot applied over the amortization with its value define by law.
num_days: int, required
Number of days since the taxable event.
loan_calculator.grossup.iof_tax.amortization_schedule_iof(amortizations, return_days, daily_iof_aliquot=8.2e-05)[source]

IOF tax over an amortization schedule.

If \(A_1,A_2\ldots,A_k\) are the amortizations, \(n_1,n_2,\ldots,n_k\) the return days and \(I^*\) the daily IOF aliquot, then the due IOF tax is

\[\sum_{i=1}^k A_i \min(n_i I^*, 0.015).\]
amortizations: list, required
Sequence of amortizations.
return_days: list, required
Sequence of assumed return days.
daily_iof_aliquot: float, required
The daily IOF aliquot, defined by law.
The due IOF tax on the amortizations in the given days.
loan_calculator.grossup.iof_tax.complementary_iof(principal, complementary_iof_fee=0.0038)[source]

Complementary IOF tax over the principal.

If \(s\) is the principal and \(I^{**}\) is the complementary IOF fee, then the due complementary IOF tax over the principal is

\[s\ I^{**}.\]
principal: float, required
The loan principal, which is the basis for the complementary IOF tax.
complementary_iof_fee: float, required
Aliquot applied over the principal. Its value is defined by law.
loan_calculator.grossup.iof_tax.loan_iof(principal, amortizations, return_days, daily_iof_aliquot, complementary_iof_aliquot)[source]

The total IOF of a loan.

If \(s\) is the principal, \(A_i\) is the \(i\)-th amortization, \(n_1,\ldots,n_k\) are the return days, \(I^*\) is the daily IOF aliquot and \(I^{**}\) is the complementary IOF aliquot, then the loan IOF tax amount is

\[\mathrm{IOF}(s, I^*, I^{**}, (A_1,\ldots,A_k),(n_1,\ldots,n_k)) = sI^{**} + \sum_{i=1}^k A_i \min(n_i I^*,0.015)\]
principal: float, required
Loan principal.
amortizations: list, required
List of floats providing the amortization due to each payment.
return_days: list, required
List of integers with the numbers of days since the loan was granted.
daily_iof_aliquot: float, required
Daily IOF aliquot. Its value is defined by law.
complementary_iof_aliquot: float, required
Complementary IOF aliquot. Its value is defined by law.

grossup.service_fee

loan_calculator.grossup.service_fee.linear_service_fee(principal, fee=0.0)[source]

Calculate service fee proportional to the principal.

If \(S\) is the principal and \(g\) is the fee aliquot, then the fee is given by \(gS\).

schedule.base

class loan_calculator.schedule.base.AmortizationScheduleType[source]

An enumeration.

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

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.

schedule.constant

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

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.price

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

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]

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.

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

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))\)

irr

loan_calculator.irr.approximate_irr(net_principal, returns, return_days, daily_interest_rate)[source]

Approximate the internal return rate of a series of returns.

Use a Newton-Raphson solver implementation to approximate the IRR for the given loan parameters.

Let \(s_\circ\) be a net principal (i.e., a principal with eventual taxes and fees properly deduced), \(r_1,r_2\ldots,r_k\) a sequence of returns and \(n_1,n_2,\ldots,n_k\) the due days for these returns. The internal return rate \(c\) is then defined as the least positive root of the polynomial

\[f(X) = s_\circ X^{n_k} - r_1 X^{n_k-n_1} - \cdots - r_{k-1} X^{n_k-n_{k-1}} - r_k\]

on the real unknown

\[X = 1 + c.\]

The derivative of \(f\) is given by

\[f^\prime (X) = n_k s_\circ X^{n_k - 1} - \sum_{i=1}^{k-1} (n_k - n_i) r_i X^{n_k - n_i - 1}.\]

The polynomial \(f\) and its derivative derivative \(f^\prime\) are implemented as Python callables and passed to the Newton-Raphson search implementation with the daily interest rate as initial approximation for the IRR.

net_principal: float, required
The principal used as reference to evaluate the irr, i.e., this is the amount of money which is, from the perspective of the borrower, affected by the irr.
returns: list, required
List of expected returns or due payments.
return_days: list, required
List of number of days since the loan was granted until each expected return.
daily_interest_rate: float, required
Loan’s daily interest rate (for the grossed up principal), used as the start point for the approximation of the IRR.
loan_calculator.irr.newton_raphson_solver(target_function, target_function_derivative, initial_point, maximum_relative_error=1e-10, max_iterations=100)[source]

Numerical solver based on Newton-Raphson approximation method.

The Newton-Raphson method allows algorithmic approximation for the root of a differentiable function, given its derivative and an initial point at which this derivative does not vanish.

Let \(f:\left[a,b\right]\longrightarrow\mathbb{R}\) a differentiable function, \(f^{\prime}\) its derivative function and \(x_0\in\left[a,b\right]\). A root of \(f\) is then iteratively approximated by the recurrence

\[x_n := x_{n-1} - \frac{f(x_{n-1})}{f^{\prime}(x_{n-1})}, n\geq 1.\]

The relative error associated with the \(n\)-th iteration of the recurrence above is defined as

\[e_n := | \frac{x_n - x_{n-1}}{x_{n-1}} |, n \geq 1.\]

The approximation stops if either \(e_n\) > maximum_relative_error or \(n\) > max_iterations.

loan_calculator.irr.return_polynomial_derivative_factory(net_principal, returns, return_days)[source]

Factory for a callable implementing point evaluation of the derivative of the return polynomial for the given parameters.

The return polynomial for a loan with net principal \(s_\circ\), returns \(r_1,r_2,\ldots,r_k\) to be paid \(n_1,n_2,\ldots,n_k\) days after the loan is granted, respectively, is given by

\[f(c) = s_\circ (1 + c)^{n_k} - r_1 (1 + c)^{n_k-n_1} - \cdots - r_{k-1} (1 + c)^{n_k-n_{k-1}} - r_k.\]

Therefore, the derivative of \(f(c)\) is given by

\[f^\prime (c) = n_k s_\circ (1 + c)^{n_k - 1} - \sum_{i=1}^{k-1} (n_k - n_i) r_i (1 + c)^{n_k - n_i - 1}.\]
net_principal : float, required
The net principal of a grossed up loan.
returns : list of floats, required
Due payments that completely pay off the grossed up principal when respectively applied for the given return days.
return_days : list of ints, required
List with the number of days since the taxable event (which is usually a “loan granted” event) happened.
Callable
Python callable implementing the return polynomial for the given parameters
loan_calculator.irr.return_polynomial_factory(net_principal, returns, return_days)[source]

Factory for a callable with point evaluation of the return polynomial.

The return polynomial for a loan with net principal \(s_\circ\), returns \(r_1,r_2,\ldots,r_k\) to be paid \(n_1,n_2,\ldots,n_k\) days after the loan is granted, respectively, is given by

\[f(c) = s_\circ (1 + c)^{n_k} - r_1 (1 + c)^{n_k-n_1} - \cdots - r_{k-1} (1 + c)^{n_k-n_{k-1}} - r_k.\]

This function builds and returns a callable implementing such polynomial.

net_principal : float, required
The net principal of a grossed up loan.
returns : list of floats, required
Due payments that completely pay off the grossed up principal when respectively applied for the given return days.
return_days : list of ints, required
List with the number of days since the taxable event (which is usually a “loan granted” event) happened.
Callable
Python callable implementing the return polynomial for the given parameters