npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

amortizejs

v1.0.3

Published

Loan calculation and amortization schedule utility with support for multiple amortization methods.

Downloads

1,442

Readme

AmortizeJS

Website Version npm license

Loan calculation and amortization schedule utility with support for custom amortization methods, available for node and browser.

AmortizeJS.calculate({
    method:   'mortgage', 
    apr:      3.5, 
    balance:  280350, 
    loanTerm: 60,
    startDate: new Date('December 24 2017')
});

Table of Contents

  1. Features
  2. Installation
  3. Quickstart
  4. API Docs
  5. Formatting of results in examples
  6. Contributing

Features

  • Periodic payment calculation
  • Total interest calculation
  • Total payment calculation
  • Calculate a payment's interest amount, principal amount and remaining balance
  • Amortization schedule creation with optional payment date support
  • Easily customize and create new amortization methods

Supported amortization methods

  • Mortgage-Style/Constant-Payment method

Installation

Using Bower:

$ bower install amortizejs

<script src="./bower_components/AmortizeJS/dist/web/bundle.js"></script>

Using npm:

$ npm install amortizejs

Usage

In Browser: AmortizeJS class is available on the window object.

In Node.js

var AmortizeJS = require('amortizejs').Calculator;

Quickstart

To calculate a mortgage amortization schedule including payment dates:

var mortgage = AmortizeJS.calculate({
    method:   'mortgage',
    apr:      3.5, 
    balance:  280350,    
    loanTerm: 60,         
    startDate: new Date('December 24 2017')
});

console.log( mortgage.periodicPayment );    // 5100.06
console.log( mortgage.periodicInterest );   // 0.00292
console.log( mortgage.totalInterest );      // 25653.34
console.log( mortgage.totalPayment );       // 306003.34
console.log( mortgage.endDate );            // Sat Dec 24 2022 00:00:00 GMT-0500 (EST)
console.log( mortgage.schedule );           // [{"interest": 817.69, "principal": 4282.37, "remainingBalance": 276067.63, "date":"2017-12-24T05:00:00.000Z"} ...]

To retrieve list of available amortization methods:

AmortizeJS.availableMethods(); // ['mortgage']

API Docs

AmortizeJS

| Command | Params | Return | Description | | --- | --- | --- | --- | | calculate(config) | calculatorConfig | AmortizationMethod | Calculates amortization details and schedule. | | availableMethods() | none | string[] | Returns the amortization methods that are available. |

CalculatorConfig

An object conforming to the CalculatorConfig Interface is required when calling AmortizeJS.calculate(config), the following options are available:

| Attribute | Type | Description | | --- | --- | --- | | method | string | function | A string identifying the amortization method to use, or a custom amortization function. | balance | number | The loan amount. | loanTerm | number | Loan term in month. | apr | number | The Anual Percentage Rate (ex: 3.5%) | startDate | Date (Optional) | Optional start date, will cause monthly payments to have dates attached to them.

AmortizationMethod

An object conforming to the AmortizationMethod Interface is returned when calling AmortizeJS.calculate(config), the following attributes are available on it:

| Attribute | Type | Description | | --- | --- | --- | | balance | number | The loan amount. | | periods | number | The total number of periods. | | periodicInterest | number | The interest payed per period, if the period is month then the APR will be divided by 12 (ex: APR = 3.5%, i = 0.035/12). | | periodicPayment | number | The total payment that needs to be made per period. | | schedule | Payment[] | Array of payments required to pay off the balance. | | totalPayment | number | The total amount of all payments over the term. | | totalInterest | number | The total amount of interest spend over the term. | | startDate | Date (Optional) | The start date of the loan. | | endDate | Date (Optional) | The pay off date (Will only be calculated if startDate was given). |

Payment

A payment for the loan, will include the following:

| Attribute | Type | Description | | --- | --- | --- | | interest | number | Portion of the payment that goes to interest. | principal | number | Portion of the payment that goes to principal. | remainingBalance | number | Remaining balance after this payment. | date | Date | The date of the payment.

Formatting of results in examples

Results are not truncated or formatted in any way, the results in the examples are truncated for clarity.

Contributing

It is easy to extend AmortizeJS with custom amortization methods, all you need to do is create a javascript class or function that can be initiated via the new operator. This constructor will be supplied the following arguments in order:

| Argument | Type | Description | | --- | --- | --- | | balance | number | The loan amount. | periodicInterest | number | The interest payed per period. | periods | number | The total number of periods. | startDate | Date (Optional) | The start date of the loan.

The constructor should return an object that conforms to the AmortizationMethod interface.

Using a custom method

function customFunction(balance, periodicInterest, loanTerm, startDate){
    //Your custom amortization algorithm here
    return arguments;
}

var mortgage = Calculator.calculate({
    method:   customFunction,
    apr:      3.5, 
    balance:  280350, 
    loanTerm: 60,
    startDate: new Date('December 24 2017')
});

console.log(mortgage); //{"0": 280350, "1": 0.00292, "2": 60, "3": "2017-12-24T05:00:00.000Z"}

Using a custom class

class CustomMethod{
    constructor(balance, periodicInterest, loanTerm, startDate){
        //Your custom amortization algorithm here
        return arguments;
    }
}

var mortgage = Calculator.calculate({
    method:   CustomMethod,
    apr:      3.5, 
    balance:  280350, 
    loanTerm: 60,
    startDate: new Date('December 24 2017')
});

console.log(mortgage); //{"0": 280350, "1": 0.00292, "2": 60, "3": "2017-12-24T05:00:00.000Z"}