A simple collection of financial equations for Node.js and the browser.
https://gibme-npm.github.io/finance/
npm install @gibme/finance
yarn add @gibme/finance
import {
calculate_amortization_loan,
calculate_compound_interest,
calculate_apy,
calculate_sma
} from '@gibme/finance';
// 30-year mortgage at 6% with $200 extra/month starting month 1
const loan = calculate_amortization_loan(200000, 0.06, 360, [
{ month: 1, amount: 200, fill: true }
]);
console.log(loan.payment); // monthly payment
console.log(loan.months_saved); // months saved by extra payments
console.log(loan.interest_saved); // interest saved by extra payments
// Compound interest: $10,000 at 5% compounded monthly for 5 years
const futureValue = calculate_compound_interest(10000, 0.05, 'monthly', 60);
console.log(futureValue);
// APY for 5% compounded daily
const apy = calculate_apy(0.05, 'daily');
console.log(apy);
// Simple moving average with a 3-period window
const sma = calculate_sma([10, 20, 30, 40, 50], 3);
console.log(sma); // [20, 30, 40]
The following compounding periods are supported wherever a CompoundPeriod is accepted:
daily | weekly | biweekly | semimonthly | monthly | bimonthly | quarterly | semiannually | annually | biannually
Functions that accept an apr parameter will automatically convert values greater than 1 to a decimal (e.g. 5 becomes 0.05). You can pass either form.
MIT