1.0.1 • Published 3 years ago

basicinterest v1.0.1

Weekly downloads
2
License
AGPLv3
Repository
-
Last release
3 years ago

Install

npm install basicinterest

Methods

interest()

Calculates the unaccumulated interest percentage on an amount using the interest rated provided, from from to to.

Usage:

interest (amount, percentage, from, to)

Takes the following parameters:

  • amount is the base amount to calculate the interest for.
  • percentage is the yearly interest rate in %.
  • from is the starting date in yyyy-mm-dd format for the calculation.
  • to is the ending date in yyyy-mm-dd format for the calculation.

Returns an int or float on success, or false on error.

Example:

> interest(100, 25, '2020-05-01', '2022-01-01')
141.78082191780823

accinterest()

Calculates the accumulated interest percentage on an amount using the interest rated provided, from from to to. Note that interest accumulation is performed every cycle of 365 days (not necessarily calendar year).

Usage:

accinterest (amount, percentage, from, to)

Takes the following parameters:

  • amount is the base amount to calculate the interest for.
  • percentage is the yearly interest rate in %.
  • from is the starting date in yyyy-mm-dd format for the calculation.
  • to is the ending date in yyyy-mm-dd format for the calculation.

Returns an int or float on success, or false on error.

Example:

> accinterest(100, 25, '2020-05-01', '2022-01-01')
145.97602739726028

howlong()

Calculates the amount of time it'll take amount to become goal at a yearly unaccumulated interest of percentage.

Usage:

howlong (amount, percentage, goal, returnyears)

Takes the following parameters:

  • amount is the base amount to calculate the interest for.
  • percentage is the yearly interest rate in %.
  • goal is the goal to reach.
  • returnyears is an optional boolean defining whether to return years instead of days.

Returns an int (days) or float (years) on success, or false on error.

Example:

> howlong(100, 25, 200, false)
1134
> howlong(100, 25, 200, true)
3.10628371950539

howmuchinterest()

Calculates the unaccumulated interest required for amount to become goal, within the time period of from and to.

Usage:

howmuchinterest (amount, goal, from, to)

Takes the following parameters:

  • amount is the base amount to calculate the interest for.
  • goal is the goal to reach.
  • from is the starting date in yyyy-mm-dd format for the calculation.
  • to is the ending date in yyyy-mm-dd format for the calculation.

Returns an int (days) or float (years) on success, or false on error.

Example:

> howmuchinterest(100, 200, '2020-05-01', '2022-01-01')
1.5139952255590707

tests()

Runs all functions with predefined arguments to make sure the code works as expected (manual unit testing :D). The output below is expected to be the same every time.

The output of tests() should be as such:

141.78082191780823
145.97602739726028
3.10628371950539 years
1134 days
1.5139952255590707

Known culprits

  1. Only common sense sanity checks are performed on the input. Non-existing dates that would synthetically make sense are accepted, e.g. 2020-02-30, but aren't handled.

Disclaimer

This is a school project. You shouldn't rely on this package or the output of its methods for anything of importance.

License

AGPLv3.

1.0.1

3 years ago

1.0.0

3 years ago