tvm-calculator
Introduction
The tvm-calculator package is a library of time value of money calculations that you would find on a financial calculator. This includes functions to find present value, future value, payment amount, number of payments, and interest rate given a set of input parameters.
Installation
Using npm:
$ npm i tvm-calculator
Note: add --save if you are using npm < 5.0.0
or
- Download or fork the repository from GitHub.
- Extract the file tvm-calculator from the project and include it in your application on the client side.
Example Usage
var tvmCalculator = ; // Specify params as objectconst tvmParams = pv: -100000 fv: 0 nper: 30 rate: 4 ; // Calculate payment amount of a loanconst periodicPayment = tvmCalculator; // Log calculated result (3508.33)console;
Parameters
Parameters are listed below. When solving for a value such as PMT, that parameter can be omitted. Parameters specified as "Optional" will default to the values described below. All parameters should be passed in as a single object.
rate, // Number: Interest Rate as whole number nper, // Number: Number of Periods in term pmt, // Number: Payment Amount pv, // Number: Present Value (should be entered as negative) fv, // Number: Future Value isBeginning, // Boolean: Is payment made at the BEGINNING of period? (Optional: defaults to false) isDiscrete, // Boolean: Is compounding DISCRETE? (Optional: defaults to true) cf, // Number: Compounding Frequency (Optional: defaults to 12 for monthly) pf, // Number: Payment Frequency (Optional: defaults to 12 for monthly)
Available Methods
Example method calls listed below. Further details to come.
calcNper
Calculate number of periods. Required params: rate, pmt, pv, fv.
const numberPeriods = tvmCalculator;console; // 30.00
calcInterestRate
Calculate interest rate. Required params: nper, pmt, pv, fv.
const interestRate = tvmCalculator;console; // 3.993
calcPV
Calculate present value. Required params: nper, pmt, fv, rate.
const presentValue = tvmCalculator;console; // -99990.73
calcPMT
Calculate payment amount. Required params: nper, pv, fv, rate.
const paymentAmount = tvmCalculator;console; // 3508.33
calcFV
Calculate future value. Required params: nper, pv, pmt, rate.
const futureValue = tvmCalculator;console; // 10.24
Full Params Example:
const tvmParams = pv: -100000 fv: 0 nper: 30 rate: 4 isBeginning: false isDiscrete: true cf: 1 pf: 1;const periodicPayment = tvmCalculator; console; // 5783.01
To Do
- Add unit testing
- Improve documentation