A commonly used calculator written by Typescript, including calculations related to finance, statistics, etc.
node:
$ npm install calculate-tool --save
# or
$ yarn add calculate-tool
# or
$ pnpm add calculate-tool
# or
$ bun add calculate-tool
ES6
import { fvInDfc } from 'calculate-tool';
fvInDfc({
n: 20,
pv: 0,
pmt: 1000,
rate: 8
});
// return: -45761.9643
CMD
const {fvInDfc} = require('calculate-tool');
fvInDfc({
n: 20,
pv: 0,
pmt: 1000,
rate: 8
});
Globals
calculatorTool.fvInDfc({
n: 20,
pv: 0,
pmt: 1000,
rate: 8
});
- methods
- fvInDfc
- pvInDfc
- rateInDfc
- pmtInDfc
- npv
- irr
- pmtInloan
- repaymentScheduleInLoan
- principalInLoan
- interestInLoan
- totalInterestInLoan
- mean
- variance
- stdDeviation
- varianceOfSample
- stdDeviationOfSample
- semiDeviation
- semiDeviation
- bankersRounding
- Includes a TypeScript declaration file: lib/index.d.ts
Get the future value of annuity in discounted cash flow model
import { fvInDfc } from 'calculate-tool';
fvInDfc({
n: 20,
pv: 0,
pmt: 1000,
rate: 8
});
// return: -45761.9643
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
n | Total Number of payment periods | Number | ||
pv | The present value | Number | ||
pmt | Payment per period | Number | ||
rate | The interest rate per period;If the real interest rate is 8%, the return is 8 | Number | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
isEnd | Prepaid Annuity or Ordinary Annuity;If true, it's Ordinary Annuity | Boolean | <optional> | true |
Type: Number
Get the present value of annuity in discounted cash flow model
import { pvInDfc } from 'calculate-tool';
pvInDfc({
n: 20,
fv: 50000,
pmt: 1000,
rate: 8
});
// return: -15465.56
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
n | Total Number of payment periods | Number | ||
fv | The future value | Number | ||
pmt | Payment per period | Number | ||
rate | The interest rate per period;If the real interest rate is 8%, the return is 8 | Number | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
isEnd | Prepaid Annuity or Ordinary Annuity;If true, it's Ordinary Annuity | Boolean | <optional> | true |
Type: Number
Get the payment of annuity in discounted cash flow model
import { pmtInDfc } from 'calculate-tool';
pmtInDfc({
n: 20,
fv: 50000,
pv: -15465.56
rate: 8
});
// return: 1000
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
n | Total Number of payment periods | Number | ||
fv | The future value | Number | ||
pv | The present value | Number | ||
rate | The interest rate per period;If the real interest rate is 8%, the return is 8 | Number | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
isEnd | Prepaid Annuity or Ordinary Annuity;If true, it's Ordinary Annuity | Boolean | <optional> | true |
Type: Number
Get the interest rate per period in discounted cash flow model.If the return is 8, the real interest rate is 8%.
import { rateInDfc } from 'calculate-tool';
rateInDfc({
n: 20,
fv: 50000,
pv: -15465.56,
pmt: 1000
});
// return: 8
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
n | Total Number of payment periods | Number | ||
fv | The future value | Number | ||
pv | The present value | Number | ||
pmt | Payment per period | Number | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
isEnd | Prepaid Annuity or Ordinary Annuity;If true, it's Ordinary Annuity | Boolean | <optional> | true |
Type: Number
Get the Net Present Value in discounted cash flow model.
import { npv } from 'calculate-tool';
npv({
initCf: -1000,
cfList: [500, 500, 500],
rate: 336.506
});
// return: 8
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
initCf | The initial cash flow | Number | ||
cfList | Cash flow list | Array<Number> | ||
rate | The interest rate per period | Number | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
Get the Internal Rate of Return in discounted cash flow model.
import { irr } from 'calculate-tool';
irr({
initCf: -5000,
cfList: [1000, 3000, 1500]
});
// return: 4.687
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
initCf | The initial cash flow | Number | ||
cfList | Cash flow list | Array<Number> | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
Get the payment per period of the loan.
If you secure a loan of $3,000,000 with a 30-year term, a monthly repayment schedule, an annual interest rate of 5%, and a repayment method of equal repayment, you will be required to make a monthly repayment of $16,104.65.
import { pmtInloan } from 'calculate-tool';
pmtInloan({
principal: 3000000,
rate: 5/12,
periods: 30 * 12,
isEqualPayment: true,
decimal: 2
})
// return: 16104.65
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
principal | The Principle of the loan | Number | ||
rate | The interst rate of every period; | Number | ||
periods | Number of loan terms | Number | ||
currentPeriod | The current period of the loan, If isEqualPayment is false, the currentPeriod is required | Number | <optional> | |
isEqualPayment | The repayment method;If true, it's Fixed Repayment Loan; If false, it's Equal Principal Payment Loan | Boolean | <optional> | true |
decimal | Reserved decimal places for results | Number | <optional> | 4 |
notes
Fixed Repayment Loan: The repayment amount is the same for each term Equal Principal Payment Loan: The principal is the same for each term
Type: Number
Get the repayment schedule in the loan
If you secure a loan of $30,000 with a 4-month term, a monthly repayment schedule, an annual interest rate of 5%, and a repayment method of equal repayment, the following is your repayment plan list
import { repaymentScheduleInLoan } from 'calculate-tool';
repaymentScheduleInLoan({
principal: 30000,
rate: 0.6,
periods: 4,
isEqualPayment: true,
decimal: 2
});
// return:
/** [
{"currentPeriod":1,"principal":7432.84,"interest":180,"repayment":7612.84},
{"currentPeriod":2,"principal":7477.44,"interest":135.4,"repayment":7612.84},
{"currentPeriod":3,"principal":7522.3,"interest":90.54,"repayment":7612.84},
{"currentPeriod":4,"principal":7567.44,"interest":45.4,"repayment":7612.84}]
**/
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
principal | The Principle of the loan | Number | ||
rate | The interst rate of every period; | Number | ||
periods | Number of loan terms | Number | ||
isEqualPayment | The repayment method;If true, it's Fixed Repayment Loan; If false, it's Equal Principal Payment Loan | Boolean | <optional> | true |
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Array<Object>
Name | Description | Type |
---|---|---|
currentPeriod | The current period of the loan | Number |
repayment | The Repayment amount for the current period of the loan | Number |
principal | The Principal for the current period of the loan | Number |
interest | The Interest for the current period of the loan | Number |
Get the Princial for the current period of the loan
import { principalInLoan } from 'calculate-tool';
principalInLoan({
principal: 30000,
rate: 0.6,
periods: 4,
currentPeriod: 2,
isEqualPayment: true,
decimal: 2
});
// return: 7477.44
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
principal | The Principle of the loan | Number | ||
rate | The interst rate of every period; | Number | ||
periods | Number of loan terms | Number | ||
currentPeriod | The current period of the loan | Number | ||
isEqualPayment | The repayment method;If true, it's Fixed Repayment Loan; If false, it's Equal Principal Payment Loan | Boolean | <optional> | true |
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
Get the Interest for the current period of the loan
import { interestInLoan } from 'calculate-tool';
interestInLoan({
principal: 30000,
rate: 0.6,
periods: 4,
currentPeriod: 2,
isEqualPayment: true,
decimal: 2
});
// return: 135.4
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
principal | The Principle of the loan | Number | ||
rate | The interst rate of every period; | Number | ||
periods | Number of loan terms | Number | ||
currentPeriod | The current period of the loan | Number | ||
isEqualPayment | The repayment method;If true, it's Fixed Repayment Loan; If false, it's Equal Principal Payment Loan | Boolean | <optional> | true |
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
Get the total interest amount of the loan
import { totalInterestInLoan } from 'calculate-tool';
totalInterestInLoan({
principal: 30000,
rate: 0.6,
periods: 4,
isEqualPayment: true,
decimal: 2
});
// return: 451.36
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
principal | The Principle of the loan | Number | ||
rate | The interst rate of every period; | Number | ||
periods | Number of loan terms | Number | ||
isEqualPayment | The repayment method;If true, it's Fixed Repayment Loan; If false, it's Equal Principal Payment Loan | Boolean | <optional> | true |
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
Get the mean of a list of number
import { mean } from 'calculate-tool';
mean(
[1,2,3,4,5,6,7,8,9,10],
2
);
// return: 5.5
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
data | A list of number | Array<Number> | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
Get the variance of a list of number
import { variance } from 'calculate-tool';
variance(
[1,2,3,4,5,6,7,8,9,10],
2
);
// return: 8.25
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
data | A list of number | Array<Number> | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
Get the standard deviation of population
import { stdDeviation } from 'calculate-tool';
stdDeviation(
[1,2,3,4,5,6,7,8,9,10],
2
);
// return: 2.87
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
data | A list of number | Array<Number> | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
Get the variance of sample
import { varianceOfSample } from 'calculate-tool';
varianceOfSample(
[1,2,3,4,5,6,7,8,9,10],
2
);
// return: 9.17
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
data | A list of number | Array<Number> | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
Get the standard deviation of sample
import { stdDeviationOfSample } from 'calculate-tool';
stdDeviationOfSample(
[1,2,3,4,5,6,7,8,9,10],
2
);
// return: 3.03
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
data | A list of number | Array<Number> | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
Get the target/down deviation of sample
import { semiDeviation } from 'calculate-tool';
semiDeviation(
[1,2,3,4,5,6,7,8,9,10],
3,
2
);
// return: 4.01
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
data | A list of number | Array<Number> | ||
target | The target for the list | Number | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
Get the standard normal distribution value by z-score
import { stdNormalDistributionValue } from 'calculate-tool';
stdNormalDistributionValue(1.24); // 0.89251
stdNormalDistributionValue(-1.24); // 0.10749
stdNormalDistributionValue(0);// 0.5
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
zScore | z-score | Number |
Type: Number
get the value by banker's rounding method
rules How to round numbers with banker's rounding With the banker's rounding, when the number to be rounded (the rounding digit) is followed by 1, 2, 3, and 4, round the number down; when followed by 6, 7, 8, and 9, round the number up. However, for numbers followed by 5, the rounding direction is determined according to the number after 5:
When there is a number after 5, round up. When there is no number after 5: If it is an odd number before 5, round up. If it is an even number before 5, round down.
Learn more 👉🏻 banker's rounding
import { bankersRounding } from 'calculate-tool';
calculatejs.bankersRounding(5.234, 2); // 5.23
calculatejs.bankersRounding(5.235, 2); // 5.24
calculatejs.bankersRounding(5.245, 2); // 5.24
calculatejs.bankersRounding(5.2352, 2); // 5.24
Name | Description | Type | Attributes | Default |
---|---|---|---|---|
number | The number to be rounded | Number | ||
decimal | Reserved decimal places for results | Number | <optional> | 4 |
Type: Number
To run the tests using Node.js from the root directory:
npm run test