Have ideas to improve npm?Join in the discussion! »

balance-growth

2.1.1 • Public • Published

balance-growth

Build Status Coverage Status Latest Stable Version

Calculate monthly balance growth over time.

Installation

npm install balance-growth

Getting start-of-month and end-of-month balances

Transaction amounts are added after the last day of the month and before the first day of the following month.

import {MonthlyBalanceAdjuster} from 'balance-growth';
 
const adjuster = new MonthlyBalanceAdjuster();
const balances = adjuster.getMonthlyBalances({
  balances: [
    { date: '2016-11-01', balance: 100 },
    { date: '2016-11-15', balance: 328 },
    { date: '2016-12-03', balance: 564 }
  ],
  transactions: [
    { date: '2016-11-02', amount: 200 },
    { date: '2016-12-02', amount: 200 }
  ],
  maxDate: '2017-01-01'
});
console.log(balances);
[
  { "month": "2016-11", "balance": 100, "eomBalance": 160 },
  { "month": "2016-12", "balance": 360, "eomBalance": 364 }
]

Getting balance growth (%) per month

import {BalanceGrowth} from 'balance-growth';
 
const calculator = new BalanceGrowth();
const growth = calculator.getGrowth({
  balances: [
    { date: '2016-11-01', balance: 100 },
    { date: '2016-11-15', balance: 328 },
    { date: '2016-12-03', balance: 564 }
  ],
  transactions: [
    { date: '2016-11-02', amount: 200 },
    { date: '2016-12-02', amount: 200 }
  ],
  maxDate: '2017-01-01'
});
console.log(growth);
[
  { "month": "2016-11", "balance": 100, "eomBalance": 160, "growth": 60 },
  { "month": "2016-12", "balance": 360, "eomBalance": 364, "growth": 1 }
]

60% growth in november and 1% growth in december

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Install

npm i balance-growth

DownloadsWeekly Downloads

9

Version

2.1.1

License

MIT

Last publish

Collaborators

  • avatar