Skip to content

Commit

Permalink
v1.0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
LesterLyu committed Nov 26, 2020
1 parent 905c17e commit cdd001b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
58 changes: 58 additions & 0 deletions formulas/functions/financial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const FormulaError = require('../error');
const {FormulaHelpers: H, Types} = require('../helpers');
const {DATEVALUE, YEARFRAC} = require('./date');

const FinancialFunctions = {
/**
* https://support.microsoft.com/en-us/office/accrint-function-fe45d089-6722-4fb3-9379-e1f911d8dc74
*/
ACCRINT: (issue, firstInterest, settlement, rate, par, frequency, basis, calcMethod) => {
issue = H.accept(issue);
firstInterest = H.accept(firstInterest);
settlement = H.accept(settlement);

// Parse date string to serial
if (typeof issue === "string") {
firstInterest = DATEVALUE(firstInterest);
}
if (typeof issue === "string") {
issue = DATEVALUE(issue);
}
if (typeof issue === "string") {
settlement = DATEVALUE(settlement);
}

rate = H.accept(rate, Types.NUMBER);
par = H.accept(par, Types.NUMBER);
frequency = H.accept(frequency, Types.NUMBER);
basis = H.accept(basis, Types.NUMBER, 0);
calcMethod = H.accept(calcMethod, Types.BOOLEAN, true);

// Issue, first_interest, settlement, frequency, and basis are truncated to integers
issue = Math.trunc(issue);
firstInterest = Math.trunc(firstInterest);
settlement = Math.trunc(settlement);
frequency = Math.trunc(frequency);
basis = Math.trunc(basis);

// If rate ≤ 0 or if par ≤ 0, ACCRINT returns the #NUM! error value.
if (rate <= 0 || par <= 0 )
return FormulaError.NUM;

// If frequency is any number other than 1, 2, or 4, ACCRINT returns the #NUM! error value.
if (frequency !== 1 && frequency !== 2 && frequency !== 4)
return FormulaError.NUM;

// If basis < 0 or if basis > 4, ACCRINT returns the #NUM! error value.
if (basis < 0 || basis > 4)
return FormulaError.NUM;

// If issue ≥ settlement, ACCRINT returns the #NUM! error value.
if (issue >= settlement)
return FormulaError.NUM;




}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fast-formula-parser",
"version": "1.0.18",
"version": "1.0.19",
"description": "fast excel formula parser",
"repository": "https://github.com/LesterLyu/fast-formula-parser",
"main": "index.js",
Expand Down

0 comments on commit cdd001b

Please sign in to comment.