1.1.1 • Published 2 months ago

installment-js v1.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

Installment JS

a fast module to calculate loan/installment in js (browser/node.js) for Outstanding debt gradually decreases or Principal and interest divided equally installments, the sum of interest, detail of payment period, etc

Getting Started

Install with:

npm install installment-js

Calculating Installment:

  const { calculateInstallment } = require("installment-js");

  const result = calculateInstallment(
    500000000, //amount
    60, // total of months Installment
    7, // annual interest rate
    [installmentType?], //(optional) installment type InstallmentType.ODGE for Outstanding debt gradually decreases and InstallmentType.PIDE for Principal and interest divided equally
    [rounding?] // (optional) rounding for amount, you can pass the number or use the constant Rounding.ZERO, Rounding.ONE, Rounding.TWO,...
  );

/*
  returns
  {
    loanAmount: 500000000,
    totalLoanAndInterest: 588953250,
    totalInterest: 88953250,
    details: [
      {
        loanBeginingPeriod: 500000000,
        originLoanPaid: 6899388,
        interest: 2916500,
        totalPaid: 9815888,
        loanEndingPeriod: 493100612,
        month: 1
      },
      {
        loanBeginingPeriod: 493100612,
        originLoanPaid: 6947996,
        interest: 2867892,
        totalPaid: 9815888,
        loanEndingPeriod: 486152616,
        month: 2
      },
      ...
    ]
  }
*/

Documentation

Installment

calculateInstallment(amount, months, rate, installmentType?, rounding?)

Arguments

ArgumenttypedefaultDescription
amountnumber*requiredfull amount of Loan
monthsnumber*requiredhow many installments will be (in months)
ratenumber*requiredannual interest rate in percent (ex. 3.5)
installmentTypeInstallmentTypeInstallmentType.ODGDkind of Installment
roundingnumber or RoundingRounding.ZERORounding for the money

InstallmentType Constant

ConstantValueDescription
ODGD0Outstanding debt gradually decreases
PIDE1Principal and interest divided equally
  • Outstanding debt gradually decreases(ODGD) image

  • Principal and interest divided equally (PIDE) image

Rounding Constant

ConstantValueDescription
ZERO0No Rounding
ONE1Round to 1 decimal places (5.123 -> 5.1)
TWO2Round to 2 decimal places (5.123 -> 5.12)
THREE3Round to 3 decimal places (5.123 -> 5.123)

Returns

{
  loanAmount: 500000000,
  totalLoanAndInterest: 588953250,
  totalInterest: 88953250,
  details: [
    {
      loanBeginingPeriod: 500000000,
      originLoanPaid: 6899388,
      interest: 2916500,
      totalPaid: 9815888,
      loanEndingPeriod: 493100612,
      month: 1
    },
    {
      loanBeginingPeriod: 493100612,
      originLoanPaid: 6947996,
      interest: 2867892,
      totalPaid: 9815888,
      loanEndingPeriod: 486152616,
      month: 2
    },
    {
      loanBeginingPeriod: 486152616,
      originLoanPaid: 6996605,
      interest: 2819283,
      totalPaid: 9815888,
      loanEndingPeriod: 479156011,
      month: 3
    },
    ...
  ]
}

Examples

import {
  calculateInstallment,
  InstallmentType,
  Rounding,
} from "installment-js";

const result = calculateInstallment(500, 12, 7.5);

const result1 = calculateInstallment(500, 12, 7.5, InstallmentType.PIDE);

const result1 = calculateInstallment(
  500,
  12,
  7.5,
  InstallmentType.PIDE,
  Rounding.TWO
);

Contributing

Im open for contributors :).

Release History

2024-03-04 v1.1.0

  • Updated the formula for Principal and interest divided equally. The formula for calculating the monthly payment for a loan in the annuity method is as follows:

    PMT = (P * r * (1 + r)^n) / ((1 + r)^n - 1)

    Where:

    • PMT is the monthly payment.
    • P is the initial loan amount (principal).
    • r is the monthly interest rate (usually expressed as a decimal and calculated by dividing the annual interest rate by 12).
    • n is the total number of payment periods (months).
1.1.1

2 months ago

1.1.0

2 months ago

1.0.9

2 months ago

1.0.8

2 months ago

1.0.7

2 months ago

1.0.6

2 months ago

1.0.5

2 months ago

1.0.4

2 months ago

1.0.3

2 months ago

1.0.2

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago