qfinbox.tvm.loans

Loan calculations and amortization.

Functions

amortization_schedule(principal, ...[, ...])

Generate loan amortization schedule.

loan_balance(principal, annual_rate, years, ...)

Calculate remaining loan balance after specified payments.

loan_payment(principal, annual_rate, years)

Calculate periodic loan payment.

total_interest_paid(principal, annual_rate, ...)

Calculate total interest paid over the life of the loan.

validate_positive(value[, name])

Validate that a value is positive.

qfinbox.tvm.loans.loan_payment(principal: float, annual_rate: float, years: float, payments_per_year: int = 12) float[source]

Calculate periodic loan payment.

Parameters:
  • principal (float) – Loan principal amount.

  • annual_rate (float) – Annual interest rate (as decimal).

  • years (float) – Loan term in years.

  • payments_per_year (int, default 12) – Number of payments per year.

Returns:

Periodic payment amount.

Return type:

float

Examples

>>> loan_payment(300000, 0.05, 30)
1610.46
qfinbox.tvm.loans.loan_balance(principal: float, annual_rate: float, years: float, payments_made: int, payments_per_year: int = 12) float[source]

Calculate remaining loan balance after specified payments.

Parameters:
  • principal (float) – Original loan principal amount.

  • annual_rate (float) – Annual interest rate (as decimal).

  • years (float) – Loan term in years.

  • payments_made (int) – Number of payments already made.

  • payments_per_year (int, default 12) – Number of payments per year.

Returns:

Remaining loan balance.

Return type:

float

Examples

>>> loan_balance(300000, 0.05, 30, 120)
260108.58
qfinbox.tvm.loans.total_interest_paid(principal: float, annual_rate: float, years: float, payments_per_year: int = 12) float[source]

Calculate total interest paid over the life of the loan.

Parameters:
  • principal (float) – Loan principal amount.

  • annual_rate (float) – Annual interest rate (as decimal).

  • years (float) – Loan term in years.

  • payments_per_year (int, default 12) – Number of payments per year.

Returns:

Total interest paid.

Return type:

float

Examples

>>> total_interest_paid(300000, 0.05, 30)
279767.35
qfinbox.tvm.loans.amortization_schedule(principal: float, annual_rate: float, years: float, payments_per_year: int = 12) DataFrame[source]

Generate loan amortization schedule.

Parameters:
  • principal (float) – Loan principal amount.

  • annual_rate (float) – Annual interest rate (as decimal).

  • years (float) – Loan term in years.

  • payments_per_year (int, default 12) – Number of payments per year.

Returns:

Amortization schedule with columns: Payment, Interest, Principal, Balance.

Return type:

pd.DataFrame

Examples

>>> schedule = amortization_schedule(300000, 0.05, 30)
>>> schedule.head()
   Payment  Interest   Principal      Balance
0  1610.46   1250.00     360.46   299639.54
1  1610.46   1248.50     361.96   299277.58