Finance.js

A JavaScript library for common financial calculations

Introduction

Finance.js makes it easy to incorporate common financial calculations into your application. The library is built on pure JavaScript without any dependencies.

This project is hosted on GitHub. You can report bugs and discuss features on the GitHub issues page. Finance.js is available for use under the MIT software license.

Getting Started

npm install financejs --save

or

  • Download or fork the repository from GitHub.
  • Extract the file finance.js from the project and include it in your application on the client side.

Example Usage

var Finance = require('financejs');
var finance = new Finance();
// To calculate Amortization
finance.AM(20000, 7.5, 5, 0);
// => 400.76

Typescript

import { Finance } from 'financejs'
let finance = new Finance();
// To calculate Amortization
finance.AM(20000, 7.5, 5, 0);
// => 400.76

Tests

npm test

Available Methods

Amortization

finance.AM(principal, rate, total number of payments, [type]);

Amortization is the paying off of debt with a fixed repayment schedule in regular installments over a period of time.1

For total number of payments which are entered as years, [type] takes a 0, whereas for months [type] takes a 1.

#Total Number of Payments Type = Years
 // e.g., If principal is $20,000, rate is 7.5%, total number of payments is 5, and payment type is 0 (years), monthly payment is $400.76.

 finance.AM(20000, 7.5, 5, 0);
 => 400.76

 #Total Number of Payments Type = Months
 // e.g.,If principal is $20,000, rate is 7.5%, total number of payments is 60, and payment type is 1 (months), monthly payment is $400.76.

 finance.AM(20000, 7.5, 60, 1);
 => 400.76

Compound Annual Growth Rate (CAGR)

finance.CAGR(beginning value, ending value, number of periods);

Compound Annual Growth Rate (CAGR) is the year-over-year growth rate of an investment over a specified period of time.2

// e.g., If the beginning value is $10,000, the ending value is $19,500, and the number of periods is 3, the CAGR is 24.93%.

 finance.CAGR(10000, 19500, 3);
 => 24.93

Compound Interest (CI)

finance.CI(rate, compoundings per period, principal, number of periods);

Compound Interest is the interest calculated on the initial principal and also on the accumulated interest of previous periods of a deposit or loan.3

// e.g., If rate is 4.3%, the compoundings per period is 4, the principal is $1,500, and the number of periods is 6, the compound interest is $1,938.84.

 finance.CI(4.3, 4, 1500, 6 );
 => 1938.84

Discount Factor (DF)

finance.DF(rate, number of periods);

The Discount Factor (DF) is the factor by which a future cash flow must be multiplied in order to obtain the present value.4

// e.g., If rate is 10% and the number of periods is 6, the result is an array of discount factors: [1, 0.91, 0.827, 0.752, 0.684].

 finance.DF(10, 6);
 => [1, 0.91, 0.827, 0.752, 0.684]

Future Value (FV)

finance.FV(rate, cash flow, number of periods);

Future Value (FV) is the value of an asset or cash at a specified date in the future that is equivalent in value to a specified sum today5

// e.g., If rate is 0.5%, cash flow is $1,000, and the number of periods is 12, the FV is $1,061.68.

 finance.FV(0.5, 1000, 12);
 => 1061.68

Subscribe to the Newsletter

Get our latest news,tutorials,guides,tips & deals delivered to your inbox.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

shares