Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(formula): add some financial function (#2868)

wpxp1234562e475b32767a
diff --git a/packages/engine-formula/src/basics/date.ts b/packages/engine-formula/src/basics/date.ts
index 175ae2255f..597fd95be5 100644
--- a/packages/engine-formula/src/basics/date.ts
+++ b/packages/engine-formula/src/basics/date.ts
@@ -346,3 +346,153 @@ export function getWeekDayByDateSerialNumber(dateSerialNumber: number): number {
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())).getUTCDay();
}
+
+export function getTwoDateDaysByBasis(startDateSerialNumber: number, endDateSerialNumber: number, basis: number) {
+ switch (basis) {
+ case 0:
+ // U.S. (NASD) method 30/360.
+ return getDaysByNASD(startDateSerialNumber, endDateSerialNumber);
+ case 1:
+ // Actual/actual
+ return getDaysByActual(startDateSerialNumber, endDateSerialNumber);
+ case 2:
+ // Actual/360
+ return {
+ days: Math.abs(endDateSerialNumber - startDateSerialNumber),
+ yearDays: 360,
+ };
+ case 3:
+ // Actual/365
+ return {
+ days: Math.abs(endDateSerialNumber - startDateSerialNumber),
+ yearDays: 365,
+ };
+ case 4:
+ // European method 30/360.
+ return getDaysByEuropean(startDateSerialNumber, endDateSerialNumber);
+ default:
+ return {
+ days: Math.abs(endDateSerialNumber - startDateSerialNumber),
+ yearDays: 365,
+ };
+ }
+}
+
+function getDaysByNASD(startDateSerialNumber: number, endDateSerialNumber: number) {
+ const startDateDate = excelSerialToDate(startDateSerialNumber);
+ const startYear = startDateSerialNumber > 0 ? startDateDate.getUTCFullYear() : 1900;
+ const startMonth = startDateSerialNumber > 0 ? startDateDate.getUTCMonth() + 1 : 1;
+ let startDay = startDateSerialNumber > 0 ? startDateDate.getUTCDate() : 0;
+
+ let endDateDate = excelSerialToDate(endDateSerialNumber);
+ let endYear = endDateSerialNumber > 0 ? endDateDate.getUTCFullYear() : 1900;
+ let endMonth = endDateSerialNumber > 0 ? endDateDate.getUTCMonth() + 1 : 1;
+ let endDay = endDateSerialNumber > 0 ? endDateDate.getUTCDate() : 0;
+
+ // If the starting date is the last day of a month, it becomes equal to the 30th day of the same month.
+ // If the ending date is the last day of a month and the starting date is earlier than the 30th day of a month, the ending date becomes equal to the 1st day of the next month; otherwise the ending date becomes equal to the 30th day of the same month.
+ if (startMonth === 2) {
+ const startDateAfterDay = excelSerialToDate(startDateSerialNumber + 1);
+
+ if (startDateAfterDay.getUTCMonth() + 1 === 3) {
+ startDay = 30;
+ }
+ } else if (startDay === 31) {
+ startDay = 30;
+ }
+
+ if (endDay === 31) {
+ if (startDay < 30) {
+ endDateDate = excelSerialToDate(endDateSerialNumber + 1);
+ endYear = endDateDate.getUTCFullYear();
+ endMonth = endDateDate.getUTCMonth() + 1;
+ endDay = endDateDate.getUTCDate();
+ } else {
+ endDay = 30;
+ }
+ }
+
+ const daysInYears = (endYear - startYear) * 360;
+ const daysInStartMonth = endDateSerialNumber >= startDateSerialNumber ? 30 - startDay : -startDay;
+ const daysInEndMonth = endDateSerialNumber >= startDateSerialNumber ? endDay : endDay - 30;
+ const daysInMidMonths = (endDateSerialNumber >= startDateSerialNumber ? (endMonth - startMonth - 1) : (endMonth - startMonth + 1)) * 30;
+ const totalDays = Math.abs(daysInYears + daysInStartMonth + daysInEndMonth + daysInMidMonths);
+
+ return {
+ days: totalDays,
+ yearDays: 360,
+ };
+}
+
+function getDaysByActual(startDateSerialNumber: number, endDateSerialNumber: number) {
+ const startDateDate = excelSerialToDate(startDateSerialNumber);
+ const startYear = startDateSerialNumber > 0 ? startDateDate.getUTCFullYear() : 1900;
+
+ const endDateDate = excelSerialToDate(endDateSerialNumber);
+ const endYear = endDateSerialNumber > 0 ? endDateDate.getUTCFullYear() : 1900;
+
+ const totalDays = Math.abs(endDateSerialNumber - startDateSerialNumber);
+ const totalYear = Math.abs(endYear - startYear) + 1;
+
+ let startYearFirstDaySerialNumber;
+ let endYearLastDaySerialNumber;
+
+ if (endYear < startYear) {
+ const startYearFirstDay = new Date(Date.UTC(endYear, 0, 1));
+ const endYearLastDay = new Date(Date.UTC(startYear, 11, 31));
+
+ startYearFirstDaySerialNumber = excelDateSerial(startYearFirstDay);
+ endYearLastDaySerialNumber = excelDateSerial(endYearLastDay);
+
+ if (endYear === 1900) { // Special handle. excel 1900 days = 365, 1900/12/31 SerialNumber = 366. so start add 1
+ startYearFirstDaySerialNumber += 1;
+ }
+ } else {
+ const startYearFirstDay = new Date(Date.UTC(startYear, 0, 1));
+ const endYearLastDay = new Date(Date.UTC(endYear, 11, 31));
+
+ startYearFirstDaySerialNumber = excelDateSerial(startYearFirstDay);
+ endYearLastDaySerialNumber = excelDateSerial(endYearLastDay);
+
+ if (startYear === 1900) { // Special handle. excel 1900 days = 365, 1900/12/31 SerialNumber = 366. so start add 1
+ startYearFirstDaySerialNumber += 1;
+ }
+ }
+
+ return {
+ days: totalDays,
+ yearDays: (endYearLastDaySerialNumber - startYearFirstDaySerialNumber + 1) / totalYear,
+ };
+}
+
+function getDaysByEuropean(startDateSerialNumber: number, endDateSerialNumber: number) {
+ const startDateDate = excelSerialToDate(startDateSerialNumber);
+ const startYear = startDateSerialNumber > 0 ? startDateDate.getUTCFullYear() : 1900;
+ const startMonth = startDateSerialNumber > 0 ? startDateDate.getUTCMonth() + 1 : 1;
+ let startDay = startDateSerialNumber > 0 ? startDateDate.getUTCDate() : 0;
+
+ const endDateDate = excelSerialToDate(endDateSerialNumber);
+ const endYear = endDateSerialNumber > 0 ? endDateDate.getUTCFullYear() : 1900;
+ const endMonth = endDateSerialNumber > 0 ? endDateDate.getUTCMonth() + 1 : 1;
+ let endDay = endDateSerialNumber > 0 ? endDateDate.getUTCDate() : 0;
+
+ // Starting dates and ending dates that occur on the 31st day of a month become equal to the 30th day of the same month.
+ if (startDay === 31) {
+ startDay = 30;
+ }
+
+ if (endDay === 31) {
+ endDay = 30;
+ }
+
+ const daysInYears = (endYear - startYear) * 360;
+ const daysInStartMonth = endDateSerialNumber >= startDateSerialNumber ? 30 - startDay : -startDay;
+ const daysInEndMonth = endDateSerialNumber >= startDateSerialNumber ? endDay : endDay - 30;
+ const daysInMidMonths = (endDateSerialNumber >= startDateSerialNumber ? (endMonth - startMonth - 1) : (endMonth - startMonth + 1)) * 30;
+ const totalDays = Math.abs(daysInYears + daysInStartMonth + daysInEndMonth + daysInMidMonths);
+
+ return {
+ days: totalDays,
+ yearDays: 360,
+ };
+}
diff --git a/packages/engine-formula/src/basics/engineering.ts b/packages/engine-formula/src/basics/engineering.ts
index 325b998790..11fc73cab2 100644
--- a/packages/engine-formula/src/basics/engineering.ts
+++ b/packages/engine-formula/src/basics/engineering.ts
@@ -14,52 +14,6 @@
* limitations under the License.
*/
-import type { ArrayValueObject } from '../engine/value-object/array-value-object';
-import type { BaseValueObject } from '../engine/value-object/base-value-object';
-import { ErrorValueObject } from '../engine/value-object/base-value-object';
-import { ErrorType } from './error-type';
-
-export function checkVariantsErrorIsArrayOrBoolean(...variants: BaseValueObject[]) {
- for (let i = 0; i < variants.length; i++) {
- let variant = variants[i];
-
- if (variant.isArray()) {
- const rowCount = (variant as ArrayValueObject).getRowCount();
- const columnCount = (variant as ArrayValueObject).getColumnCount();
-
- if (rowCount > 1 || columnCount > 1) {
- return {
- isError: true,
- errorObject: ErrorValueObject.create(ErrorType.VALUE),
- };
- }
-
- variant = (variant as ArrayValueObject).get(0, 0) as BaseValueObject;
- }
-
- if (variant.isError()) {
- return {
- isError: true,
- errorObject: variant,
- };
- }
-
- if (variant.isBoolean()) {
- return {
- isError: true,
- errorObject: ErrorValueObject.create(ErrorType.VALUE),
- };
- }
-
- variants[i] = variant;
- }
-
- return {
- isError: false,
- variants,
- };
-}
-
// eslint-disable-next-line ts/no-namespace
export namespace BESSEL {
const W = 0.636619772;
diff --git a/packages/engine-formula/src/basics/financial.ts b/packages/engine-formula/src/basics/financial.ts
new file mode 100644
index 0000000000..8f3ea6e268
--- /dev/null
+++ b/packages/engine-formula/src/basics/financial.ts
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export function calculatePMT(rate: number, nper: number, pv: number, fv: number, type: number): number {
+ // type = 0 Payment at the end of the period
+ // type = 1 Payment at the beginning of the period
+ let result: number;
+
+ if (rate === 0) {
+ result = (pv + fv) / nper;
+ } else {
+ const term = (1 + rate) ** nper;
+
+ result = type === 1
+ ? ((fv * rate) / (term - 1) + (pv * rate) / (1 - 1 / term)) / (1 + rate)
+ : (fv * rate) / (term - 1) + (pv * rate) / (1 - 1 / term);
+ }
+
+ return -result;
+}
+
+export function calculateFV(rate: number, nper: number, pmt: number, pv: number, type: number): number {
+ // type = 0 Payment at the end of the period
+ // type = 1 Payment at the beginning of the period
+ let result: number;
+
+ if (rate === 0) {
+ result = pv + pmt * nper;
+ } else {
+ const term = (1 + rate) ** nper;
+
+ result = type === 1
+ ? pv * term + (pmt * (1 + rate) * (term - 1)) / rate
+ : pv * term + (pmt * (term - 1)) / rate;
+ }
+
+ return -result;
+}
+
+export function calculateIPMT(rate: number, per: number, nper: number, pv: number, fv: number, type: number): number {
+ // type = 0 Payment at the end of the period
+ // type = 1 Payment at the beginning of the period
+ const payment = calculatePMT(rate, nper, pv, fv, type);
+
+ const result = per === 1
+ ? (type === 1 ? 0 : -pv)
+ : (type === 1 ? calculateFV(rate, per - 2, payment, pv, 1) - payment : calculateFV(rate, per - 1, payment, pv, 0));
+
+ return result * rate;
+}
diff --git a/packages/engine-formula/src/engine/utils/check-variant-error.ts b/packages/engine-formula/src/engine/utils/check-variant-error.ts
new file mode 100644
index 0000000000..103806b910
--- /dev/null
+++ b/packages/engine-formula/src/engine/utils/check-variant-error.ts
@@ -0,0 +1,91 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../basics/error-type';
+import type { ArrayValueObject } from '../value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../value-object/base-value-object';
+
+export function checkVariantErrorIsArray(variant: BaseValueObject): BaseValueObject {
+ let _variant = variant;
+
+ if (variant.isArray()) {
+ const rowCount = (variant as ArrayValueObject).getRowCount();
+ const columnCount = (variant as ArrayValueObject).getColumnCount();
+
+ if (rowCount > 1 || columnCount > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ _variant = (variant as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ if (_variant.isError()) {
+ return _variant;
+ }
+
+ return _variant;
+}
+
+export function checkVariantsErrorIsArrayOrBoolean(...variants: BaseValueObject[]) {
+ for (let i = 0; i < variants.length; i++) {
+ const variant = checkVariantErrorIsArray(variants[i]);
+
+ if (variant.isError()) {
+ return {
+ isError: true,
+ errorObject: variant,
+ };
+ }
+
+ if (variant.isBoolean()) {
+ return {
+ isError: true,
+ errorObject: ErrorValueObject.create(ErrorType.VALUE),
+ };
+ }
+
+ variants[i] = variant;
+ }
+
+ return {
+ isError: false,
+ variants,
+ };
+}
+
+export function checkVariantsErrorIsStringToNumber(...variants: BaseValueObject[]) {
+ for (let i = 0; i < variants.length; i++) {
+ let variant = variants[i];
+
+ if (variant.isString()) {
+ variant = variant.convertToNumberObjectValue();
+ }
+
+ if (variant.isError()) {
+ return {
+ isError: true,
+ errorObject: variant,
+ };
+ }
+
+ variants[i] = variant;
+ }
+
+ return {
+ isError: false,
+ variants,
+ };
+}
diff --git a/packages/engine-formula/src/engine/value-object/array-value-object.ts b/packages/engine-formula/src/engine/value-object/array-value-object.ts
index 2a413608d7..e19ebcf882 100644
--- a/packages/engine-formula/src/engine/value-object/array-value-object.ts
+++ b/packages/engine-formula/src/engine/value-object/array-value-object.ts
@@ -1639,14 +1639,6 @@ export class ArrayValueObject extends BaseValueObject {
(currentValue as ErrorValueObject).getErrorType(),
r + startRow
);
- } else if (currentValue.isNull()) {
- // In comparison operations, these two situations are equivalent
-
- // ">"&A1 (A1 is an empty cell)
- // ">"
-
- // So the empty cell is also cached as an empty string so that it can be retrieved next time
- CELL_INVERTED_INDEX_CACHE.set(unitId, sheetId, column + startColumn, '', r + startRow);
} else {
CELL_INVERTED_INDEX_CACHE.set(
unitId,
diff --git a/packages/engine-formula/src/functions/date/days360/index.ts b/packages/engine-formula/src/functions/date/days360/index.ts
index 9ece7748be..10d701a18c 100644
--- a/packages/engine-formula/src/functions/date/days360/index.ts
+++ b/packages/engine-formula/src/functions/date/days360/index.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { excelSerialToDate, getDateSerialNumberByObject } from '../../../basics/date';
+import { getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
import { ErrorType } from '../../../basics/error-type';
import { expandArrayValueObject } from '../../../engine/utils/array-object';
import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
@@ -90,7 +90,13 @@ export class Days360 extends BaseFunction {
return methodObject;
}
- return this._getResult(startDateSerialNumber, endDateSerialNumber, methodObject);
+ const methodValue = +methodObject.getValue();
+
+ const { days } = getTwoDateDaysByBasis(startDateSerialNumber, endDateSerialNumber, !methodValue ? 0 : 4);
+
+ const result = endDateSerialNumber >= startDateSerialNumber ? days : -days;
+
+ return NumberValueObject.create(result);
});
if (maxRowLength === 1 && maxColumnLength === 1) {
@@ -99,56 +105,4 @@ export class Days360 extends BaseFunction {
return resultArray;
}
-
- private _getResult(startDateSerialNumber: number, endDateSerialNumber: number, methodObject: BaseValueObject) {
- const startDateDate = excelSerialToDate(startDateSerialNumber);
- const startYear = startDateSerialNumber > 0 ? startDateDate.getUTCFullYear() : 1900;
- const startMonth = startDateSerialNumber > 0 ? startDateDate.getUTCMonth() + 1 : 1;
- let startDay = startDateSerialNumber > 0 ? startDateDate.getUTCDate() : 0;
-
- let endDateDate = excelSerialToDate(endDateSerialNumber);
- let endYear = endDateSerialNumber > 0 ? endDateDate.getUTCFullYear() : 1900;
- let endMonth = endDateSerialNumber > 0 ? endDateDate.getUTCMonth() + 1 : 1;
- let endDay = endDateSerialNumber > 0 ? endDateDate.getUTCDate() : 0;
-
- const methodValue = +methodObject.getValue();
-
- if (!methodValue) {
- // U.S. (NASD) method.
- // If the starting date is the last day of a month, it becomes equal to the 30th day of the same month.
- // If the ending date is the last day of a month and the starting date is earlier than the 30th day of a month, the ending date becomes equal to the 1st day of the next month; otherwise the ending date becomes equal to the 30th day of the same month.
- if (startDay === 31) {
- startDay = 30;
- }
-
- if (endDay === 31) {
- if (startDay < 30) {
- endDateDate = excelSerialToDate(endDateSerialNumber + 1);
- endYear = endDateDate.getUTCFullYear();
- endMonth = endDateDate.getUTCMonth() + 1;
- endDay = endDateDate.getUTCDate();
- } else {
- endDay = 30;
- }
- }
- } else {
- // European method. Starting dates and ending dates that occur on the 31st day of a month become equal to the 30th day of the same month.
- if (startDay === 31) {
- startDay = 30;
- }
-
- if (endDay === 31) {
- endDay = 30;
- }
- }
-
- const daysInYears = (endYear - startYear) * 360;
- const daysInStartMonth = endDateSerialNumber >= startDateSerialNumber ? 30 - startDay : -startDay;
- const daysInEndMonth = endDateSerialNumber >= startDateSerialNumber ? endDay : endDay - 30;
- const daysInMidMonths = (endDateSerialNumber >= startDateSerialNumber ? (endMonth - startMonth - 1) : (endMonth - startMonth + 1)) * 30;
-
- const totalDays = daysInYears + daysInStartMonth + daysInEndMonth + daysInMidMonths;
-
- return NumberValueObject.create(totalDays);
- }
}
diff --git a/packages/engine-formula/src/functions/date/yearfrac/index.ts b/packages/engine-formula/src/functions/date/yearfrac/index.ts
index 2346e26673..eb894ed121 100644
--- a/packages/engine-formula/src/functions/date/yearfrac/index.ts
+++ b/packages/engine-formula/src/functions/date/yearfrac/index.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject } from '../../../basics/date';
+import { getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
import { ErrorType } from '../../../basics/error-type';
-import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { checkVariantErrorIsArray } from '../../../engine/utils/check-variant-error';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
import { BaseFunction } from '../../base-function';
@@ -29,19 +29,19 @@ export class Yearfrac extends BaseFunction {
override calculate(startDate: BaseValueObject, endDate: BaseValueObject, basis?: BaseValueObject) {
let _basis = basis ?? NumberValueObject.create(0);
- const _startDate = this._checkArrayError(startDate);
+ const _startDate = checkVariantErrorIsArray(startDate);
if (_startDate.isError()) {
return _startDate;
}
- const _endDate = this._checkArrayError(endDate);
+ const _endDate = checkVariantErrorIsArray(endDate);
if (_endDate.isError()) {
return _endDate;
}
- _basis = this._checkArrayError(_basis);
+ _basis = checkVariantErrorIsArray(_basis);
if (_basis.isError()) {
return _basis;
@@ -73,146 +73,9 @@ export class Yearfrac extends BaseFunction {
return ErrorValueObject.create(ErrorType.NUM);
}
- switch (basisValue) {
- case 0:
- return this._getResultByNASD(startDateSerialNumber, endDateSerialNumber);
- case 1:
- return this._getResultByActual(startDateSerialNumber, endDateSerialNumber);
- case 2:
- return NumberValueObject.create(Math.abs(endDateSerialNumber - startDateSerialNumber) / 360);
- case 3:
- return NumberValueObject.create(Math.abs(endDateSerialNumber - startDateSerialNumber) / 365);
- case 4:
- return this._getResultByEuropean(startDateSerialNumber, endDateSerialNumber);
- default:
- return NumberValueObject.create(0);
- }
- }
-
- private _checkArrayError(variant: BaseValueObject): BaseValueObject {
- let _variant = variant;
-
- if (_variant.isArray()) {
- const rowCount = (_variant as ArrayValueObject).getRowCount();
- const columnCount = (_variant as ArrayValueObject).getColumnCount();
-
- if (rowCount > 1 || columnCount > 1) {
- return ErrorValueObject.create(ErrorType.VALUE);
- }
-
- _variant = (_variant as ArrayValueObject).get(0, 0) as BaseValueObject;
- }
-
- if (_variant.isError()) {
- return _variant;
- }
-
- return _variant;
- }
-
- private _getResultByNASD(startDateSerialNumber: number, endDateSerialNumber: number): BaseValueObject {
- const startDateDate = excelSerialToDate(startDateSerialNumber);
- const startYear = startDateSerialNumber > 0 ? startDateDate.getUTCFullYear() : 1900;
- const startMonth = startDateSerialNumber > 0 ? startDateDate.getUTCMonth() + 1 : 1;
- let startDay = startDateSerialNumber > 0 ? startDateDate.getUTCDate() : 0;
-
- let endDateDate = excelSerialToDate(endDateSerialNumber);
- let endYear = endDateSerialNumber > 0 ? endDateDate.getUTCFullYear() : 1900;
- let endMonth = endDateSerialNumber > 0 ? endDateDate.getUTCMonth() + 1 : 1;
- let endDay = endDateSerialNumber > 0 ? endDateDate.getUTCDate() : 0;
-
- if (startDay === 31) {
- startDay = 30;
- }
-
- if (endDay === 31) {
- if (startDay < 30) {
- endDateDate = excelSerialToDate(endDateSerialNumber + 1);
- endYear = endDateDate.getUTCFullYear();
- endMonth = endDateDate.getUTCMonth() + 1;
- endDay = endDateDate.getUTCDate();
- } else {
- endDay = 30;
- }
- }
-
- const daysInYears = (endYear - startYear) * 360;
- const daysInStartMonth = endDateSerialNumber >= startDateSerialNumber ? 30 - startDay : -startDay;
- const daysInEndMonth = endDateSerialNumber >= startDateSerialNumber ? endDay : endDay - 30;
- const daysInMidMonths = (endDateSerialNumber >= startDateSerialNumber ? (endMonth - startMonth - 1) : (endMonth - startMonth + 1)) * 30;
- const totalDays = Math.abs(daysInYears + daysInStartMonth + daysInEndMonth + daysInMidMonths);
-
- const result = totalDays / 360;
-
- return NumberValueObject.create(result);
- }
-
- private _getResultByActual(startDateSerialNumber: number, endDateSerialNumber: number): BaseValueObject {
- const startDateDate = excelSerialToDate(startDateSerialNumber);
- const startYear = startDateSerialNumber > 0 ? startDateDate.getUTCFullYear() : 1900;
-
- const endDateDate = excelSerialToDate(endDateSerialNumber);
- const endYear = endDateSerialNumber > 0 ? endDateDate.getUTCFullYear() : 1900;
-
- const totalDays = Math.abs(endDateSerialNumber - startDateSerialNumber);
- const totalYear = Math.abs(endYear - startYear) + 1;
-
- let startYearFirstDaySerialNumber;
- let endYearLastDaySerialNumber;
-
- if (endYear < startYear) {
- const startYearFirstDay = new Date(Date.UTC(endYear, 0, 1));
- const endYearLastDay = new Date(Date.UTC(startYear, 11, 31));
-
- startYearFirstDaySerialNumber = excelDateSerial(startYearFirstDay);
- endYearLastDaySerialNumber = excelDateSerial(endYearLastDay);
-
- if (endYear === 1900) { // Special handle. excel 1900 days = 365, 1900/12/31 SerialNumber = 366. so start add 1
- startYearFirstDaySerialNumber += 1;
- }
- } else {
- const startYearFirstDay = new Date(Date.UTC(startYear, 0, 1));
- const endYearLastDay = new Date(Date.UTC(endYear, 11, 31));
-
- startYearFirstDaySerialNumber = excelDateSerial(startYearFirstDay);
- endYearLastDaySerialNumber = excelDateSerial(endYearLastDay);
-
- if (startYear === 1900) { // Special handle. excel 1900 days = 365, 1900/12/31 SerialNumber = 366. so start add 1
- startYearFirstDaySerialNumber += 1;
- }
- }
-
- const result = totalDays / ((endYearLastDaySerialNumber - startYearFirstDaySerialNumber + 1) / totalYear);
-
- return NumberValueObject.create(result);
- }
-
- private _getResultByEuropean(startDateSerialNumber: number, endDateSerialNumber: number): BaseValueObject {
- const startDateDate = excelSerialToDate(startDateSerialNumber);
- const startYear = startDateSerialNumber > 0 ? startDateDate.getUTCFullYear() : 1900;
- const startMonth = startDateSerialNumber > 0 ? startDateDate.getUTCMonth() + 1 : 1;
- let startDay = startDateSerialNumber > 0 ? startDateDate.getUTCDate() : 0;
-
- const endDateDate = excelSerialToDate(endDateSerialNumber);
- const endYear = endDateSerialNumber > 0 ? endDateDate.getUTCFullYear() : 1900;
- const endMonth = endDateSerialNumber > 0 ? endDateDate.getUTCMonth() + 1 : 1;
- let endDay = endDateSerialNumber > 0 ? endDateDate.getUTCDate() : 0;
-
- if (startDay === 31) {
- startDay = 30;
- }
-
- if (endDay === 31) {
- endDay = 30;
- }
-
- const daysInYears = (endYear - startYear) * 360;
- const daysInStartMonth = endDateSerialNumber >= startDateSerialNumber ? 30 - startDay : -startDay;
- const daysInEndMonth = endDateSerialNumber >= startDateSerialNumber ? endDay : endDay - 30;
- const daysInMidMonths = (endDateSerialNumber >= startDateSerialNumber ? (endMonth - startMonth - 1) : (endMonth - startMonth + 1)) * 30;
- const totalDays = Math.abs(daysInYears + daysInStartMonth + daysInEndMonth + daysInMidMonths);
+ const { days, yearDays } = getTwoDateDaysByBasis(startDateSerialNumber, endDateSerialNumber, basisValue);
- const result = totalDays / 360;
+ const result = days / yearDays;
return NumberValueObject.create(result);
}
diff --git a/packages/engine-formula/src/functions/engineering/besseli/index.ts b/packages/engine-formula/src/functions/engineering/besseli/index.ts
index a6473b13c0..f7671ee5d3 100644
--- a/packages/engine-formula/src/functions/engineering/besseli/index.ts
+++ b/packages/engine-formula/src/functions/engineering/besseli/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { BESSEL, checkVariantsErrorIsArrayOrBoolean } from '../../../basics/engineering';
+import { BESSEL } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Besseli extends BaseFunction {
override minParams = 2;
diff --git a/packages/engine-formula/src/functions/engineering/besselj/index.ts b/packages/engine-formula/src/functions/engineering/besselj/index.ts
index 3c6a4cfdf4..0ada8235c5 100644
--- a/packages/engine-formula/src/functions/engineering/besselj/index.ts
+++ b/packages/engine-formula/src/functions/engineering/besselj/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { BESSEL, checkVariantsErrorIsArrayOrBoolean } from '../../../basics/engineering';
+import { BESSEL } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Besselj extends BaseFunction {
override minParams = 2;
diff --git a/packages/engine-formula/src/functions/engineering/besselk/index.ts b/packages/engine-formula/src/functions/engineering/besselk/index.ts
index 5486bb1a0c..fb8ea2c0c2 100644
--- a/packages/engine-formula/src/functions/engineering/besselk/index.ts
+++ b/packages/engine-formula/src/functions/engineering/besselk/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { BESSEL, checkVariantsErrorIsArrayOrBoolean } from '../../../basics/engineering';
+import { BESSEL } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Besselk extends BaseFunction {
override minParams = 2;
diff --git a/packages/engine-formula/src/functions/engineering/bessely/index.ts b/packages/engine-formula/src/functions/engineering/bessely/index.ts
index 1fb1c840a5..e976f5a858 100644
--- a/packages/engine-formula/src/functions/engineering/bessely/index.ts
+++ b/packages/engine-formula/src/functions/engineering/bessely/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { BESSEL, checkVariantsErrorIsArrayOrBoolean } from '../../../basics/engineering';
+import { BESSEL } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Bessely extends BaseFunction {
override minParams = 2;
diff --git a/packages/engine-formula/src/functions/engineering/bin2dec/index.ts b/packages/engine-formula/src/functions/engineering/bin2dec/index.ts
index 9973c8aed2..c28ab1d958 100644
--- a/packages/engine-formula/src/functions/engineering/bin2dec/index.ts
+++ b/packages/engine-formula/src/functions/engineering/bin2dec/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean, isValidBinaryNumber } from '../../../basics/engineering';
+import { isValidBinaryNumber } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Bin2dec extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/bin2hex/index.ts b/packages/engine-formula/src/functions/engineering/bin2hex/index.ts
index 006260e37e..15d64e0a40 100644
--- a/packages/engine-formula/src/functions/engineering/bin2hex/index.ts
+++ b/packages/engine-formula/src/functions/engineering/bin2hex/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean, isValidBinaryNumber } from '../../../basics/engineering';
+import { isValidBinaryNumber } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { StringValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Bin2hex extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/bin2oct/index.ts b/packages/engine-formula/src/functions/engineering/bin2oct/index.ts
index 7b9ab63c3a..29f8bc05d3 100644
--- a/packages/engine-formula/src/functions/engineering/bin2oct/index.ts
+++ b/packages/engine-formula/src/functions/engineering/bin2oct/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean, isValidBinaryNumber } from '../../../basics/engineering';
+import { isValidBinaryNumber } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { StringValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Bin2oct extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/complex/index.ts b/packages/engine-formula/src/functions/engineering/complex/index.ts
index 8e32664597..a397258729 100644
--- a/packages/engine-formula/src/functions/engineering/complex/index.ts
+++ b/packages/engine-formula/src/functions/engineering/complex/index.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Complex extends BaseFunction {
override minParams = 2;
diff --git a/packages/engine-formula/src/functions/engineering/convert/index.ts b/packages/engine-formula/src/functions/engineering/convert/index.ts
index 4376fdf2b0..78e227123c 100644
--- a/packages/engine-formula/src/functions/engineering/convert/index.ts
+++ b/packages/engine-formula/src/functions/engineering/convert/index.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
type IUnitItem = Array<string | Array<string> | number | boolean | null>;
diff --git a/packages/engine-formula/src/functions/engineering/dec2bin/index.ts b/packages/engine-formula/src/functions/engineering/dec2bin/index.ts
index b87b0257d0..e6001d327a 100644
--- a/packages/engine-formula/src/functions/engineering/dec2bin/index.ts
+++ b/packages/engine-formula/src/functions/engineering/dec2bin/index.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { StringValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Dec2bin extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/dec2hex/index.ts b/packages/engine-formula/src/functions/engineering/dec2hex/index.ts
index 511d4af70a..75bb941a35 100644
--- a/packages/engine-formula/src/functions/engineering/dec2hex/index.ts
+++ b/packages/engine-formula/src/functions/engineering/dec2hex/index.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { StringValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Dec2hex extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/dec2oct/index.ts b/packages/engine-formula/src/functions/engineering/dec2oct/index.ts
index 6fa43bfa24..b175020cd4 100644
--- a/packages/engine-formula/src/functions/engineering/dec2oct/index.ts
+++ b/packages/engine-formula/src/functions/engineering/dec2oct/index.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { StringValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Dec2oct extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/delta/index.ts b/packages/engine-formula/src/functions/engineering/delta/index.ts
index 99de46ec91..ba1d15ad56 100644
--- a/packages/engine-formula/src/functions/engineering/delta/index.ts
+++ b/packages/engine-formula/src/functions/engineering/delta/index.ts
@@ -18,7 +18,7 @@ import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
-import { checkVariantsErrorIsArrayOrBoolean } from '../../../basics/engineering';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Delta extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/erf-precise/index.ts b/packages/engine-formula/src/functions/engineering/erf-precise/index.ts
index 75eb0ed2c5..76fdbb7ed8 100644
--- a/packages/engine-formula/src/functions/engineering/erf-precise/index.ts
+++ b/packages/engine-formula/src/functions/engineering/erf-precise/index.ts
@@ -18,7 +18,8 @@ import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
-import { checkVariantsErrorIsArrayOrBoolean, erf } from '../../../basics/engineering';
+import { erf } from '../../../basics/engineering';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class ErfPrecise extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/erf/index.ts b/packages/engine-formula/src/functions/engineering/erf/index.ts
index 2a0095d772..6b2695c829 100644
--- a/packages/engine-formula/src/functions/engineering/erf/index.ts
+++ b/packages/engine-formula/src/functions/engineering/erf/index.ts
@@ -18,7 +18,8 @@ import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
-import { checkVariantsErrorIsArrayOrBoolean, erf } from '../../../basics/engineering';
+import { erf } from '../../../basics/engineering';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Erf extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/erfc-precise/index.ts b/packages/engine-formula/src/functions/engineering/erfc-precise/index.ts
index a7b11233f6..630a56704a 100644
--- a/packages/engine-formula/src/functions/engineering/erfc-precise/index.ts
+++ b/packages/engine-formula/src/functions/engineering/erfc-precise/index.ts
@@ -18,7 +18,8 @@ import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
-import { checkVariantsErrorIsArrayOrBoolean, erf } from '../../../basics/engineering';
+import { erf } from '../../../basics/engineering';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class ErfcPrecise extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/erfc/index.ts b/packages/engine-formula/src/functions/engineering/erfc/index.ts
index 4ddfa1cb69..aa3e55be29 100644
--- a/packages/engine-formula/src/functions/engineering/erfc/index.ts
+++ b/packages/engine-formula/src/functions/engineering/erfc/index.ts
@@ -18,7 +18,8 @@ import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
-import { checkVariantsErrorIsArrayOrBoolean, erf } from '../../../basics/engineering';
+import { erf } from '../../../basics/engineering';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Erfc extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/hex2bin/index.ts b/packages/engine-formula/src/functions/engineering/hex2bin/index.ts
index 0dcacc0155..2fc23df647 100644
--- a/packages/engine-formula/src/functions/engineering/hex2bin/index.ts
+++ b/packages/engine-formula/src/functions/engineering/hex2bin/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean, isValidHexadecimalNumber } from '../../../basics/engineering';
+import { isValidHexadecimalNumber } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { StringValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Hex2bin extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/hex2dec/index.ts b/packages/engine-formula/src/functions/engineering/hex2dec/index.ts
index 126e8cb115..0a97f44abe 100644
--- a/packages/engine-formula/src/functions/engineering/hex2dec/index.ts
+++ b/packages/engine-formula/src/functions/engineering/hex2dec/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean, isValidHexadecimalNumber } from '../../../basics/engineering';
+import { isValidHexadecimalNumber } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Hex2dec extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/hex2oct/index.ts b/packages/engine-formula/src/functions/engineering/hex2oct/index.ts
index 44765be434..52e0f8f831 100644
--- a/packages/engine-formula/src/functions/engineering/hex2oct/index.ts
+++ b/packages/engine-formula/src/functions/engineering/hex2oct/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean, isValidHexadecimalNumber } from '../../../basics/engineering';
+import { isValidHexadecimalNumber } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { StringValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Hex2oct extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/oct2bin/index.ts b/packages/engine-formula/src/functions/engineering/oct2bin/index.ts
index 950592778c..411c36c561 100644
--- a/packages/engine-formula/src/functions/engineering/oct2bin/index.ts
+++ b/packages/engine-formula/src/functions/engineering/oct2bin/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean, isValidOctalNumber } from '../../../basics/engineering';
+import { isValidOctalNumber } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { StringValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Oct2bin extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/oct2dec/index.ts b/packages/engine-formula/src/functions/engineering/oct2dec/index.ts
index a3ebb42e24..1a4148c368 100644
--- a/packages/engine-formula/src/functions/engineering/oct2dec/index.ts
+++ b/packages/engine-formula/src/functions/engineering/oct2dec/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean, isValidOctalNumber } from '../../../basics/engineering';
+import { isValidOctalNumber } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Oct2dec extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/engineering/oct2hex/index.ts b/packages/engine-formula/src/functions/engineering/oct2hex/index.ts
index 990f978738..85d8ad50ab 100644
--- a/packages/engine-formula/src/functions/engineering/oct2hex/index.ts
+++ b/packages/engine-formula/src/functions/engineering/oct2hex/index.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import { checkVariantsErrorIsArrayOrBoolean, isValidOctalNumber } from '../../../basics/engineering';
+import { isValidOctalNumber } from '../../../basics/engineering';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import { StringValueObject } from '../../../engine/value-object/primitive-object';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
export class Oct2hex extends BaseFunction {
override minParams = 1;
diff --git a/packages/engine-formula/src/functions/financial/accrint/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/accrint/__tests__/index.spec.ts
new file mode 100644
index 0000000000..4123bbca82
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/accrint/__tests__/index.spec.ts
@@ -0,0 +1,144 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Accrint } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test accrint function', () => {
+ const testFunction = new Accrint(FUNCTION_NAMES_FINANCIAL.ACCRINT);
+
+ describe('Accrint', () => {
+ it('value is normal', () => {
+ const issue = StringValueObject.create('2008/2/29');
+ const firstInterest = StringValueObject.create('2008/8/31');
+ const settlement = StringValueObject.create('2008/5/1');
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const frequency = NumberValueObject.create(2);
+
+ let result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency);
+ expect(result.getValue()).toStrictEqual(16.944444444444446);
+
+ const basis = NumberValueObject.create(1);
+ result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency, basis);
+ expect(result.getValue()).toStrictEqual(16.939890710382514);
+ });
+
+ it('value is normal, endDate < startDate', () => {
+ const issue = StringValueObject.create('2008/5/1');
+ const firstInterest = StringValueObject.create('2008/8/31');
+ const settlement = StringValueObject.create('2008/2/29');
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const frequency = NumberValueObject.create(2);
+ const result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('value is error', () => {
+ const issue = NumberValueObject.create(1);
+ const firstInterest = StringValueObject.create('2008/8/31');
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const frequency = NumberValueObject.create(2);
+ const result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('value is boolean', () => {
+ const issue = BooleanValueObject.create(false);
+ const firstInterest = StringValueObject.create('2008/8/31');
+ const settlement = NumberValueObject.create(43832.233);
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const frequency = NumberValueObject.create(2);
+
+ let result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const basis = BooleanValueObject.create(true);
+ result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('value is normal string', () => {
+ const issue = StringValueObject.create('test');
+ const firstInterest = StringValueObject.create('2008/8/31');
+ const settlement = StringValueObject.create('2008/5/1');
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const frequency = NumberValueObject.create(2);
+ const result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('rate or par value less than or equal to 0', () => {
+ const issue = StringValueObject.create('2008/2/29');
+ const firstInterest = StringValueObject.create('2008/8/31');
+ const settlement = StringValueObject.create('2008/5/1');
+ const rate = NumberValueObject.create(0);
+ const par = NumberValueObject.create(1000);
+ const frequency = NumberValueObject.create(2);
+ const result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const rate2 = NumberValueObject.create(0.1);
+ const par2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(issue, firstInterest, settlement, rate2, par2, frequency);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('basis value less than 0 or greater than 4', () => {
+ const issue = StringValueObject.create('2008/2/29');
+ const firstInterest = StringValueObject.create('2008/8/31');
+ const settlement = StringValueObject.create('2008/5/1');
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(-1);
+ const result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('value is array', () => {
+ const issue = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const firstInterest = StringValueObject.create('2008/8/31');
+ const settlement = StringValueObject.create('2008/5/1');
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const frequency = NumberValueObject.create(2);
+ const result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/accrint/index.ts b/packages/engine-formula/src/functions/financial/accrint/index.ts
new file mode 100644
index 0000000000..c23b107873
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/accrint/index.ts
@@ -0,0 +1,130 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject, NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Accrint extends BaseFunction {
+ override minParams = 6;
+
+ override maxParams = 8;
+
+ override calculate(
+ issue: BaseValueObject,
+ firstInterest: BaseValueObject,
+ settlement: BaseValueObject,
+ rate: BaseValueObject,
+ par: BaseValueObject,
+ frequency: BaseValueObject,
+ basis?: BaseValueObject,
+ calcMethod?: BaseValueObject
+ ) {
+ const _basis = basis ?? NumberValueObject.create(0);
+ const _calcMethod = calcMethod ?? BooleanValueObject.create(true);
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(issue, firstInterest, settlement, rate, par, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [issueObject, firstInterestObject, settlementObject, rateObject, parObject, frequencyObject, basisObject] = variants as BaseValueObject[];
+
+ const issueSerialNumber = getDateSerialNumberByObject(issueObject);
+
+ if (typeof issueSerialNumber !== 'number') {
+ return issueSerialNumber;
+ }
+
+ const firstInterestSerialNumber = getDateSerialNumberByObject(firstInterestObject);
+
+ if (typeof firstInterestSerialNumber !== 'number') {
+ return firstInterestSerialNumber;
+ }
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const rateValue = +rateObject.getValue();
+ const parValue = +parObject.getValue();
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+ const calcMethodValue = +_calcMethod.getValue();
+
+ if (Number.isNaN(rateValue) || Number.isNaN(parValue) || Number.isNaN(frequencyValue) || Number.isNaN(basisValue) || Number.isNaN(calcMethodValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ rateValue <= 0 ||
+ parValue <= 0 ||
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ Math.floor(issueSerialNumber) >= Math.floor(settlementSerialNumber)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return this._getResult(issueSerialNumber, firstInterestSerialNumber, settlementSerialNumber, rateValue, parValue, frequencyValue, basisValue, calcMethodValue);
+ }
+
+ private _getResult(
+ issueSerialNumber: number,
+ firstInterestSerialNumber: number,
+ settlementSerialNumber: number,
+ rateValue: number,
+ parValue: number,
+ frequencyValue: number,
+ basisValue: number,
+ calcMethodValue: number
+ ): NumberValueObject {
+ let TwoDateDays;
+
+ if (Math.floor(settlementSerialNumber) >= Math.floor(firstInterestSerialNumber) && !calcMethodValue) {
+ TwoDateDays = getTwoDateDaysByBasis(firstInterestSerialNumber, settlementSerialNumber, basisValue);
+ } else {
+ TwoDateDays = getTwoDateDaysByBasis(issueSerialNumber, settlementSerialNumber, basisValue);
+ }
+
+ const { days, yearDays } = TwoDateDays;
+
+ const NC = Math.ceil((days / yearDays) * frequencyValue);
+ const NLi = yearDays / frequencyValue;
+
+ let accruedDaysSum = 0;
+ for (let i = 1; i <= NC; i++) {
+ if (i * NLi > days) {
+ const Ai = days - (i - 1) * NLi;
+ accruedDaysSum += Ai / NLi;
+ } else {
+ accruedDaysSum += 1;
+ }
+ }
+
+ // TODO: The results are not very accurate now.
+ const result = parValue * (rateValue / frequencyValue) * accruedDaysSum;
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/accrintm/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/accrintm/__tests__/index.spec.ts
new file mode 100644
index 0000000000..ca311965ca
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/accrintm/__tests__/index.spec.ts
@@ -0,0 +1,128 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Accrintm } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test accrintm function', () => {
+ const testFunction = new Accrintm(FUNCTION_NAMES_FINANCIAL.ACCRINTM);
+
+ describe('Accrintm', () => {
+ it('value is normal', () => {
+ const issue = StringValueObject.create('2012/2/2');
+ const settlement = StringValueObject.create('2021/3/11');
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+
+ let result = testFunction.calculate(issue, settlement, rate, par);
+ expect(result.getValue()).toStrictEqual(910.8333333333334);
+
+ const basis = NumberValueObject.create(1);
+ result = testFunction.calculate(issue, settlement, rate, par, basis);
+ expect(result.getValue()).toStrictEqual(910.2107856556255);
+ });
+
+ it('value is normal, endDate < startDate', () => {
+ const issue = StringValueObject.create('2021/3/11');
+ const settlement = StringValueObject.create('2012/2/2');
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const result = testFunction.calculate(issue, settlement, rate, par);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('value is error', () => {
+ const issue = NumberValueObject.create(1);
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const result = testFunction.calculate(issue, settlement, rate, par);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('value is boolean', () => {
+ const issue = BooleanValueObject.create(false);
+ const settlement = NumberValueObject.create(43832.233);
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+
+ let result = testFunction.calculate(issue, settlement, rate, par);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const basis = BooleanValueObject.create(true);
+ result = testFunction.calculate(issue, settlement, rate, par, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('value is normal string', () => {
+ const issue = StringValueObject.create('test');
+ const settlement = StringValueObject.create('2021-12-31');
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const result = testFunction.calculate(issue, settlement, rate, par);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('rate or par value less than or equal to 0', () => {
+ const issue = StringValueObject.create('2012/2/2');
+ const settlement = StringValueObject.create('2021/3/11');
+ const rate = NumberValueObject.create(0);
+ const par = NumberValueObject.create(1000);
+ const result = testFunction.calculate(issue, settlement, rate, par);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const rate2 = NumberValueObject.create(0.1);
+ const par2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(issue, settlement, rate2, par2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('basis value less than 0 or greater than 4', () => {
+ const issue = StringValueObject.create('2012/2/2');
+ const settlement = StringValueObject.create('2021/3/11');
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const basis = NumberValueObject.create(-1);
+ const result = testFunction.calculate(issue, settlement, rate, par, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('value is array', () => {
+ const issue = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const settlement = StringValueObject.create('2021-12-31');
+ const rate = NumberValueObject.create(0.1);
+ const par = NumberValueObject.create(1000);
+ const result = testFunction.calculate(issue, settlement, rate, par);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/accrintm/index.ts b/packages/engine-formula/src/functions/financial/accrintm/index.ts
new file mode 100644
index 0000000000..27ddb18c4b
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/accrintm/index.ts
@@ -0,0 +1,74 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Accrintm extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 5;
+
+ override calculate(issue: BaseValueObject, settlement: BaseValueObject, rate: BaseValueObject, par: BaseValueObject, basis?: BaseValueObject) {
+ const _basis = basis ?? NumberValueObject.create(0);
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(issue, settlement, rate, par, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [issueObject, settlementObject, rateObject, parObject, basisObject] = variants as BaseValueObject[];
+
+ const issueSerialNumber = getDateSerialNumberByObject(issueObject);
+
+ if (typeof issueSerialNumber !== 'number') {
+ return issueSerialNumber;
+ }
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const rateValue = +rateObject.getValue();
+ const parValue = +parObject.getValue();
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(rateValue) || Number.isNaN(parValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (rateValue <= 0 || parValue <= 0 || basisValue < 0 || basisValue > 4 || Math.floor(issueSerialNumber) > Math.floor(settlementSerialNumber)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (Math.floor(issueSerialNumber) === Math.floor(settlementSerialNumber)) {
+ return NumberValueObject.create(0);
+ }
+
+ const { days, yearDays } = getTwoDateDaysByBasis(issueSerialNumber, settlementSerialNumber, basisValue);
+
+ const result = parValue * rateValue * days / yearDays;
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/amorlinc/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/amorlinc/__tests__/index.spec.ts
new file mode 100644
index 0000000000..fc7aacd38e
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/amorlinc/__tests__/index.spec.ts
@@ -0,0 +1,173 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Amorlinc } from '../index';
+import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test amorlinc function', () => {
+ const testFunction = new Amorlinc(FUNCTION_NAMES_FINANCIAL.AMORLINC);
+
+ describe('Amorlinc', () => {
+ it('Value is normal', () => {
+ const cost = NumberValueObject.create(2400);
+ const datePurchased = StringValueObject.create('2008/8/19');
+ const firstPeriod = StringValueObject.create('2008/12/31');
+ const salvage = NumberValueObject.create(300);
+ const period = NumberValueObject.create(1);
+ const rate = NumberValueObject.create(0.15);
+ const basis = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis);
+ expect(result.getValue()).toStrictEqual(360);
+ });
+
+ it('Cost is normal string', () => {
+ const cost = StringValueObject.create('test');
+ const datePurchased = StringValueObject.create('2008/8/19');
+ const firstPeriod = StringValueObject.create('2008/12/31');
+ const salvage = NumberValueObject.create(300);
+ const period = NumberValueObject.create(1);
+ const rate = NumberValueObject.create(0.15);
+ const basis = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Cost <= 0 or salvage < 0 or cost < salvage', () => {
+ const cost = NumberValueObject.create(0);
+ const datePurchased = StringValueObject.create('2008/8/19');
+ const firstPeriod = StringValueObject.create('2008/12/31');
+ const salvage = NumberValueObject.create(300);
+ const period = NumberValueObject.create(1);
+ const rate = NumberValueObject.create(0.15);
+ const basis = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const cost2 = NumberValueObject.create(2400);
+ const salvage2 = NumberValueObject.create(-1);
+ const result2 = testFunction.calculate(cost2, datePurchased, firstPeriod, salvage2, period, rate, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const cost3 = NumberValueObject.create(100);
+ const salvage3 = NumberValueObject.create(200);
+ const result3 = testFunction.calculate(cost3, datePurchased, firstPeriod, salvage3, period, rate, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('DatePurchased > firstPeriod', () => {
+ const cost = NumberValueObject.create(2400);
+ const datePurchased = StringValueObject.create('2008/12/31');
+ const firstPeriod = StringValueObject.create('2008/8/19');
+ const salvage = NumberValueObject.create(300);
+ const period = NumberValueObject.create(1);
+ const rate = NumberValueObject.create(0.15);
+ const basis = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Period < 0 or period = 0 or period is last or period > maxPeriod', () => {
+ const cost = NumberValueObject.create(2400);
+ const datePurchased = StringValueObject.create('2008/8/19');
+ const firstPeriod = StringValueObject.create('2008/12/31');
+ const salvage = NumberValueObject.create(300);
+ const period = NumberValueObject.create(-1);
+ const rate = NumberValueObject.create(0.15);
+ const basis = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const period2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period2, rate, basis);
+ expect(result2.getValue()).toStrictEqual(132);
+
+ const period3 = NumberValueObject.create(6);
+ const result3 = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period3, rate, basis);
+ expect(result3.getValue()).toStrictEqual(168.00000000000023);
+
+ const period4 = NumberValueObject.create(7);
+ const result4 = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period4, rate, basis);
+ expect(result4.getValue()).toStrictEqual(0);
+ });
+
+ it('Rate <= 0', () => {
+ const cost = NumberValueObject.create(2400);
+ const datePurchased = StringValueObject.create('2008/8/19');
+ const firstPeriod = StringValueObject.create('2008/12/31');
+ const salvage = NumberValueObject.create(300);
+ const period = NumberValueObject.create(1);
+ const rate = NumberValueObject.create(0);
+ const basis = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Basis value is 0|1|3|4', () => {
+ const cost = NumberValueObject.create(2400);
+ const datePurchased = StringValueObject.create('2008/8/19');
+ const firstPeriod = StringValueObject.create('2008/12/31');
+ const salvage = NumberValueObject.create(300);
+ const period = NumberValueObject.create(0);
+ const rate = NumberValueObject.create(0.15);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis2);
+ expect(result2.getValue()).toStrictEqual(132);
+
+ const basis3 = NumberValueObject.create(1);
+ const result3 = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis3);
+ expect(result3.getValue()).toStrictEqual(131.80327868852459);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis4);
+ expect(result4.getValue()).toStrictEqual(132.16438356164383);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis5);
+ expect(result5.getValue()).toStrictEqual(131);
+ });
+
+ it('value is array', () => {
+ const cost = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const datePurchased = StringValueObject.create('2008/8/19');
+ const firstPeriod = StringValueObject.create('2008/12/31');
+ const salvage = NumberValueObject.create(300);
+ const period = NumberValueObject.create(1);
+ const rate = NumberValueObject.create(0.15);
+ const basis = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/amorlinc/index.ts b/packages/engine-formula/src/functions/financial/amorlinc/index.ts
new file mode 100644
index 0000000000..8b732a3f6c
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/amorlinc/index.ts
@@ -0,0 +1,122 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Amorlinc extends BaseFunction {
+ override minParams = 6;
+
+ override maxParams = 7;
+
+ override calculate(
+ cost: BaseValueObject,
+ datePurchased: BaseValueObject,
+ firstPeriod: BaseValueObject,
+ salvage: BaseValueObject,
+ period: BaseValueObject,
+ rate: BaseValueObject,
+ basis?: BaseValueObject
+ ) {
+ const _basis = basis ?? NumberValueObject.create(0);
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(cost, datePurchased, firstPeriod, salvage, period, rate, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [costObject, datePurchasedObject, firstPeriodObject, salvageObject, periodObject, rateObject, basisObject] = variants as BaseValueObject[];
+
+ const datePurchasedSerialNumber = getDateSerialNumberByObject(datePurchasedObject);
+
+ if (typeof datePurchasedSerialNumber !== 'number') {
+ return datePurchasedSerialNumber;
+ }
+
+ const firstPeriodSerialNumber = getDateSerialNumberByObject(firstPeriodObject);
+
+ if (typeof firstPeriodSerialNumber !== 'number') {
+ return firstPeriodSerialNumber;
+ }
+
+ const costValue = +costObject.getValue();
+ const salvageValue = +salvageObject.getValue();
+ let periodValue = +periodObject.getValue();
+ const rateValue = +rateObject.getValue();
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(costValue) || Number.isNaN(salvageValue) || Number.isNaN(periodValue) || Number.isNaN(rateValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ costValue <= 0 ||
+ salvageValue < 0 ||
+ costValue < salvageValue ||
+ Math.floor(datePurchasedSerialNumber) > Math.floor(firstPeriodSerialNumber) ||
+ periodValue < 0 ||
+ rateValue <= 0 ||
+ ![0, 1, 3, 4].includes(basisValue)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (periodValue > 1) {
+ periodValue = Math.floor(periodValue);
+ } else {
+ periodValue = Math.ceil(periodValue);
+ }
+
+ return this._getResult(costValue, datePurchasedSerialNumber, firstPeriodSerialNumber, salvageValue, periodValue, rateValue, basisValue);
+ }
+
+ private _getResult(
+ costValue: number,
+ datePurchasedSerialNumber: number,
+ firstPeriodSerialNumber: number,
+ salvageValue: number,
+ periodValue: number,
+ rateValue: number,
+ basisValue: number
+ ): NumberValueObject {
+ const totalDepreciation = costValue - salvageValue;
+ const baseDepreciation = costValue * rateValue;
+ const { days, yearDays } = getTwoDateDaysByBasis(datePurchasedSerialNumber, firstPeriodSerialNumber, basisValue);
+ const firstPeriodYearsFraction = days / yearDays;
+ const life = Math.ceil(totalDepreciation / baseDepreciation - firstPeriodYearsFraction);
+
+ if (life < 0) {
+ return NumberValueObject.create(costValue);
+ }
+
+ let result = baseDepreciation;
+
+ if (periodValue === 0) {
+ result = baseDepreciation * firstPeriodYearsFraction;
+ } else if (periodValue === life) {
+ result = totalDepreciation - baseDepreciation * (firstPeriodYearsFraction + periodValue - 1);
+ } else if (periodValue > life) {
+ result = 0;
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/coupdaybs/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/coupdaybs/__tests__/index.spec.ts
new file mode 100644
index 0000000000..8465b76c93
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/coupdaybs/__tests__/index.spec.ts
@@ -0,0 +1,136 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Coupdaybs } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test coupdaybs function', () => {
+ const testFunction = new Coupdaybs(FUNCTION_NAMES_FINANCIAL.COUPDAYBS);
+
+ describe('Coupdaybs', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(71);
+ });
+
+ it('Value is normal, settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2012-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(71);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(71);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(70);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(71);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(71);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(70);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const settlement = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/coupdaybs/index.ts b/packages/engine-formula/src/functions/financial/coupdaybs/index.ts
new file mode 100644
index 0000000000..585fd13c0d
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/coupdaybs/index.ts
@@ -0,0 +1,93 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Coupdaybs extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 4;
+
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ const _basis = basis ?? NumberValueObject.create(0);
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, frequencyObject, basisObject] = variants as BaseValueObject[];
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const maturitySerialNumber = getDateSerialNumberByObject(maturityObject);
+
+ if (typeof maturitySerialNumber !== 'number') {
+ return maturitySerialNumber;
+ }
+
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ Math.floor(settlementSerialNumber) >= Math.floor(maturitySerialNumber)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const settlementDate = excelSerialToDate(settlementSerialNumber);
+ const coupDate = excelSerialToDate(maturitySerialNumber);
+
+ coupDate.setUTCFullYear(settlementDate.getUTCFullYear());
+
+ if (coupDate < settlementDate) {
+ coupDate.setUTCFullYear(coupDate.getUTCFullYear() + 1);
+ }
+
+ // eslint-disable-next-line
+ while (coupDate > settlementDate) {
+ coupDate.setUTCMonth(coupDate.getUTCMonth() - 12 / frequencyValue);
+ }
+
+ let coupDateSerialNumber = excelDateSerial(coupDate);
+
+ // special handle for excel
+ if (coupDateSerialNumber < 0) {
+ coupDateSerialNumber = 0;
+ }
+
+ const { days } = getTwoDateDaysByBasis(coupDateSerialNumber, settlementSerialNumber, basisValue);
+
+ return NumberValueObject.create(days);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/coupdays/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/coupdays/__tests__/index.spec.ts
new file mode 100644
index 0000000000..a36e853662
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/coupdays/__tests__/index.spec.ts
@@ -0,0 +1,136 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Coupdays } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test coupdays function', () => {
+ const testFunction = new Coupdays(FUNCTION_NAMES_FINANCIAL.COUPDAYS);
+
+ describe('Coupdays', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(181);
+ });
+
+ it('Value is normal, settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2012-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(365);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(92);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(180);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(180);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(182.5);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(180);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const settlement = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/coupdays/index.ts b/packages/engine-formula/src/functions/financial/coupdays/index.ts
new file mode 100644
index 0000000000..05377c7fd3
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/coupdays/index.ts
@@ -0,0 +1,105 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Coupdays extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 4;
+
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ const _basis = basis ?? NumberValueObject.create(0);
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, frequencyObject, basisObject] = variants as BaseValueObject[];
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const maturitySerialNumber = getDateSerialNumberByObject(maturityObject);
+
+ if (typeof maturitySerialNumber !== 'number') {
+ return maturitySerialNumber;
+ }
+
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ Math.floor(settlementSerialNumber) >= Math.floor(maturitySerialNumber)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ let result;
+
+ if (basisValue === 1) {
+ const settlementDate = excelSerialToDate(settlementSerialNumber);
+ const coupDate = excelSerialToDate(maturitySerialNumber);
+
+ coupDate.setUTCFullYear(settlementDate.getUTCFullYear());
+
+ if (coupDate < settlementDate) {
+ coupDate.setUTCFullYear(coupDate.getUTCFullYear() + 1);
+ }
+
+ // eslint-disable-next-line
+ while (coupDate > settlementDate) {
+ coupDate.setUTCMonth(coupDate.getUTCMonth() - 12 / frequencyValue);
+ }
+
+ const beforeSettlementDateSerialNumber = excelDateSerial(coupDate);
+
+ coupDate.setUTCMonth(coupDate.getUTCMonth() + 12 / frequencyValue);
+
+ const afterSettlementDateSerialNumber = excelDateSerial(coupDate);
+
+ // special handle for excel
+ if (beforeSettlementDateSerialNumber < 0 && frequencyValue === 1) {
+ result = 365;
+ } else {
+ result = afterSettlementDateSerialNumber - beforeSettlementDateSerialNumber;
+ }
+ } else if (basisValue === 3) {
+ result = 365 / frequencyValue;
+ } else {
+ result = 360 / frequencyValue;
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/coupdaysnc/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/coupdaysnc/__tests__/index.spec.ts
new file mode 100644
index 0000000000..a6a843a422
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/coupdaysnc/__tests__/index.spec.ts
@@ -0,0 +1,136 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Coupdaysnc } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test coupdaysnc function', () => {
+ const testFunction = new Coupdaysnc(FUNCTION_NAMES_FINANCIAL.COUPDAYSNC);
+
+ describe('Coupdaysnc', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(110);
+ });
+
+ it('Value is normal, settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2012-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(294);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(21);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(110);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(110);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(110);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(110);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const settlement = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/coupdaysnc/index.ts b/packages/engine-formula/src/functions/financial/coupdaysnc/index.ts
new file mode 100644
index 0000000000..b8c3038420
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/coupdaysnc/index.ts
@@ -0,0 +1,90 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Coupdaysnc extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 4;
+
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ const _basis = basis ?? NumberValueObject.create(0);
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, frequencyObject, basisObject] = variants as BaseValueObject[];
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const maturitySerialNumber = getDateSerialNumberByObject(maturityObject);
+
+ if (typeof maturitySerialNumber !== 'number') {
+ return maturitySerialNumber;
+ }
+
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ Math.floor(settlementSerialNumber) >= Math.floor(maturitySerialNumber)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const settlementDate = excelSerialToDate(settlementSerialNumber);
+ const coupDate = excelSerialToDate(maturitySerialNumber);
+
+ coupDate.setUTCFullYear(settlementDate.getUTCFullYear());
+
+ if (coupDate < settlementDate) {
+ coupDate.setUTCFullYear(coupDate.getUTCFullYear() + 1);
+ }
+
+ // eslint-disable-next-line
+ while (coupDate > settlementDate) {
+ coupDate.setUTCMonth(coupDate.getUTCMonth() - 12 / frequencyValue);
+ }
+
+ coupDate.setUTCMonth(coupDate.getUTCMonth() + 12 / frequencyValue);
+
+ const coupDateSerialNumber = excelDateSerial(coupDate);
+
+ const { days } = getTwoDateDaysByBasis(settlementSerialNumber, coupDateSerialNumber, basisValue);
+
+ return NumberValueObject.create(days);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/coupncd/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/coupncd/__tests__/index.spec.ts
new file mode 100644
index 0000000000..970bc2c811
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/coupncd/__tests__/index.spec.ts
@@ -0,0 +1,136 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Coupncd } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test coupncd function', () => {
+ const testFunction = new Coupncd(FUNCTION_NAMES_FINANCIAL.COUPNCD);
+
+ describe('Coupncd', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(40678);
+ });
+
+ it('Value is normal, settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2012-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(40862);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(40589);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(40678);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(40678);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(40678);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(40678);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const settlement = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/coupncd/index.ts b/packages/engine-formula/src/functions/financial/coupncd/index.ts
new file mode 100644
index 0000000000..02adb58617
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/coupncd/index.ts
@@ -0,0 +1,88 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Coupncd extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 4;
+
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ const _basis = basis ?? NumberValueObject.create(0);
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, frequencyObject, basisObject] = variants as BaseValueObject[];
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const maturitySerialNumber = getDateSerialNumberByObject(maturityObject);
+
+ if (typeof maturitySerialNumber !== 'number') {
+ return maturitySerialNumber;
+ }
+
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ Math.floor(settlementSerialNumber) >= Math.floor(maturitySerialNumber)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const settlementDate = excelSerialToDate(settlementSerialNumber);
+ const coupDate = excelSerialToDate(maturitySerialNumber);
+
+ coupDate.setUTCFullYear(settlementDate.getUTCFullYear());
+
+ if (coupDate < settlementDate) {
+ coupDate.setUTCFullYear(coupDate.getUTCFullYear() + 1);
+ }
+
+ // eslint-disable-next-line
+ while (coupDate > settlementDate) {
+ coupDate.setUTCMonth(coupDate.getUTCMonth() - 12 / frequencyValue);
+ }
+
+ coupDate.setUTCMonth(coupDate.getUTCMonth() + 12 / frequencyValue);
+
+ const coupDateSerialNumber = excelDateSerial(coupDate);
+
+ return NumberValueObject.create(coupDateSerialNumber);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/coupnum/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/coupnum/__tests__/index.spec.ts
new file mode 100644
index 0000000000..1abaa249ae
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/coupnum/__tests__/index.spec.ts
@@ -0,0 +1,136 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Coupnum } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test coupnum function', () => {
+ const testFunction = new Coupnum(FUNCTION_NAMES_FINANCIAL.COUPNUM);
+
+ describe('Coupnum', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(2);
+ });
+
+ it('Value is normal, settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2012-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(1);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(4);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(2);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(2);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(2);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(2);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const settlement = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/coupnum/index.ts b/packages/engine-formula/src/functions/financial/coupnum/index.ts
new file mode 100644
index 0000000000..3512c73e98
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/coupnum/index.ts
@@ -0,0 +1,88 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Coupnum extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 4;
+
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ const _basis = basis ?? NumberValueObject.create(0);
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, frequencyObject, basisObject] = variants as BaseValueObject[];
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const maturitySerialNumber = getDateSerialNumberByObject(maturityObject);
+
+ if (typeof maturitySerialNumber !== 'number') {
+ return maturitySerialNumber;
+ }
+
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ Math.floor(settlementSerialNumber) >= Math.floor(maturitySerialNumber)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ let result = 0;
+
+ const settlementDate = excelSerialToDate(settlementSerialNumber);
+ const coupDate = excelSerialToDate(maturitySerialNumber);
+
+ // eslint-disable-next-line
+ while (coupDate > settlementDate) {
+ coupDate.setUTCMonth(coupDate.getUTCMonth() - 12 / frequencyValue);
+ result++;
+ }
+
+ const coupDateSerialNumber = excelDateSerial(coupDate);
+
+ // special handle for excel
+ if (coupDateSerialNumber < 0) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/couppcd/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/couppcd/__tests__/index.spec.ts
new file mode 100644
index 0000000000..659c4745c9
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/couppcd/__tests__/index.spec.ts
@@ -0,0 +1,136 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Couppcd } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test couppcd function', () => {
+ const testFunction = new Couppcd(FUNCTION_NAMES_FINANCIAL.COUPPCD);
+
+ describe('Couppcd', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(40497);
+ });
+
+ it('Value is normal, settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2012-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(40497);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(40497);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(40497);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(40497);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(40497);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(40497);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2011-1-25');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const settlement = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const maturity = StringValueObject.create('2011-11-15');
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/couppcd/index.ts b/packages/engine-formula/src/functions/financial/couppcd/index.ts
new file mode 100644
index 0000000000..40e8b0e4e5
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/couppcd/index.ts
@@ -0,0 +1,91 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Couppcd extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 4;
+
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ const _basis = basis ?? NumberValueObject.create(0);
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, frequencyObject, basisObject] = variants as BaseValueObject[];
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const maturitySerialNumber = getDateSerialNumberByObject(maturityObject);
+
+ if (typeof maturitySerialNumber !== 'number') {
+ return maturitySerialNumber;
+ }
+
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ Math.floor(settlementSerialNumber) >= Math.floor(maturitySerialNumber)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const settlementDate = excelSerialToDate(settlementSerialNumber);
+ const coupDate = excelSerialToDate(maturitySerialNumber);
+
+ coupDate.setUTCFullYear(settlementDate.getUTCFullYear());
+
+ if (coupDate < settlementDate) {
+ coupDate.setUTCFullYear(coupDate.getUTCFullYear() + 1);
+ }
+
+ // eslint-disable-next-line
+ while (coupDate > settlementDate) {
+ coupDate.setUTCMonth(coupDate.getUTCMonth() - 12 / frequencyValue);
+ }
+
+ let coupDateSerialNumber = excelDateSerial(coupDate);
+
+ // special handle for excel
+ if (coupDateSerialNumber < 0) {
+ coupDateSerialNumber = 0;
+ }
+
+ return NumberValueObject.create(coupDateSerialNumber);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/cumipmt/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/cumipmt/__tests__/index.spec.ts
new file mode 100644
index 0000000000..60885b742b
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/cumipmt/__tests__/index.spec.ts
@@ -0,0 +1,158 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Cumipmt } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test cumipmt function', () => {
+ const testFunction = new Cumipmt(FUNCTION_NAMES_FINANCIAL.CUMIPMT);
+
+ describe('Cumipmt', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.09 / 12);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(-1874.4879129661426);
+
+ const type2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type2);
+ expect(result2.getValue()).toStrictEqual(-930.0128168398438);
+ });
+
+ it('Rate <= 0 or nper <= 0 or pv <= 0', () => {
+ const rate = NumberValueObject.create(0);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const rate2 = NumberValueObject.create(0.09 / 12);
+ const nper2 = NumberValueObject.create(0);
+ const pv2 = NumberValueObject.create(125000);
+ const result2 = testFunction.calculate(rate2, nper2, pv2, startPeriod, endPeriod, type);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const rate3 = NumberValueObject.create(0.09 / 12);
+ const nper3 = NumberValueObject.create(30 * 12);
+ const pv3 = NumberValueObject.create(0);
+ const result3 = testFunction.calculate(rate3, nper3, pv3, startPeriod, endPeriod, type);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('StartPeriod < 1 or endPeriod < 1 or startPeriod > endPeriod', () => {
+ const rate = NumberValueObject.create(0.09 / 12);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(0);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const startPeriod2 = NumberValueObject.create(1);
+ const endPeriod2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(rate, nper, pv, startPeriod2, endPeriod2, type);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const startPeriod3 = NumberValueObject.create(3);
+ const endPeriod3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(rate, nper, pv, startPeriod3, endPeriod3, type);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Type value is not 0 or 1', () => {
+ const rate = NumberValueObject.create(0.09 / 12);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const type2 = NumberValueObject.create(1.1);
+ const result2 = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = NumberValueObject.create(0.09 / 12);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = BooleanValueObject.create(true);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const rate = StringValueObject.create('test');
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const rate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/cumipmt/index.ts b/packages/engine-formula/src/functions/financial/cumipmt/index.ts
new file mode 100644
index 0000000000..045d7db534
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/cumipmt/index.ts
@@ -0,0 +1,115 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { calculateFV, calculatePMT } from '../../../basics/financial';
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+
+export class Cumipmt extends BaseFunction {
+ override minParams = 6;
+
+ override maxParams = 6;
+
+ override calculate(rate: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, startPeriod: BaseValueObject, endPeriod: BaseValueObject, type: BaseValueObject) {
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(rate, nper, pv, startPeriod, endPeriod, type);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [rateObject, nperObject, pvObject, startPeriodObject, endPeriodObject, typeObject] = variants as BaseValueObject[];
+
+ const rateValue = +rateObject.getValue();
+ const nperValue = +nperObject.getValue();
+ const pvValue = +pvObject.getValue();
+ const startPeriodValue = +startPeriodObject.getValue();
+ const endPeriodValue = +endPeriodObject.getValue();
+ const typeValue = +typeObject.getValue();
+
+ if (Number.isNaN(rateValue) || Number.isNaN(nperValue) || Number.isNaN(pvValue) || Number.isNaN(startPeriodValue) || Number.isNaN(endPeriodValue) || Number.isNaN(typeValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ rateValue <= 0 ||
+ nperValue <= 0 ||
+ pvValue <= 0 ||
+ startPeriodValue < 1 ||
+ endPeriodValue < 1 ||
+ startPeriodValue > endPeriodValue ||
+ startPeriodValue > nperValue ||
+ endPeriodValue > nperValue ||
+ ![0, 1].includes(typeValue)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (Math.trunc(startPeriodValue) !== startPeriodValue && Math.trunc(endPeriodValue) !== endPeriodValue && Math.trunc(startPeriodValue) === Math.trunc(endPeriodValue)) {
+ return NumberValueObject.create(0);
+ }
+
+ return this._getResult(rateValue, nperValue, pvValue, startPeriodValue, endPeriodValue, typeValue);
+ }
+
+ private _getResult(
+ rateValue: number,
+ nperValue: number,
+ pvValue: number,
+ startPeriodValue: number,
+ endPeriodValue: number,
+ typeValue: number
+ ): NumberValueObject {
+ const payment = calculatePMT(rateValue, nperValue, pvValue, 0, typeValue);
+
+ let result = 0;
+ let _startPeriodValue = Math.ceil(startPeriodValue);
+
+ if (_startPeriodValue === 1) {
+ if (typeValue === 0) {
+ result = -pvValue;
+ }
+
+ _startPeriodValue++;
+ }
+
+ let canNotCalculate = false;
+
+ for (let i = _startPeriodValue; i <= endPeriodValue; i++) {
+ const principal = typeValue === 1
+ ? calculateFV(rateValue, i - 2, payment, pvValue, 1)
+ : calculateFV(rateValue, i - 1, payment, pvValue, 0);
+
+ if (principal === 0) {
+ canNotCalculate = true;
+ break;
+ }
+
+ result += typeValue === 1 ? principal - payment : principal;
+ }
+
+ result *= rateValue;
+
+ if (result < payment * (endPeriodValue - startPeriodValue + 1) || canNotCalculate) {
+ result = payment * (endPeriodValue - startPeriodValue + 1);
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/cumprinc/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/cumprinc/__tests__/index.spec.ts
new file mode 100644
index 0000000000..4b07d4b985
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/cumprinc/__tests__/index.spec.ts
@@ -0,0 +1,158 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Cumprinc } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test cumprinc function', () => {
+ const testFunction = new Cumprinc(FUNCTION_NAMES_FINANCIAL.CUMPRINC);
+
+ describe('Cumprinc', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.09 / 12);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(-137.06862939581106);
+
+ const type2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type2);
+ expect(result2.getValue()).toStrictEqual(-1066.5693592017974);
+ });
+
+ it('Rate <= 0 or nper <= 0 or pv <= 0', () => {
+ const rate = NumberValueObject.create(0);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const rate2 = NumberValueObject.create(0.09 / 12);
+ const nper2 = NumberValueObject.create(0);
+ const pv2 = NumberValueObject.create(125000);
+ const result2 = testFunction.calculate(rate2, nper2, pv2, startPeriod, endPeriod, type);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const rate3 = NumberValueObject.create(0.09 / 12);
+ const nper3 = NumberValueObject.create(30 * 12);
+ const pv3 = NumberValueObject.create(0);
+ const result3 = testFunction.calculate(rate3, nper3, pv3, startPeriod, endPeriod, type);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('StartPeriod < 1 or endPeriod < 1 or startPeriod > endPeriod', () => {
+ const rate = NumberValueObject.create(0.09 / 12);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(0);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const startPeriod2 = NumberValueObject.create(1);
+ const endPeriod2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(rate, nper, pv, startPeriod2, endPeriod2, type);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const startPeriod3 = NumberValueObject.create(3);
+ const endPeriod3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(rate, nper, pv, startPeriod3, endPeriod3, type);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Type value is not 0 or 1', () => {
+ const rate = NumberValueObject.create(0.09 / 12);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const type2 = NumberValueObject.create(1.1);
+ const result2 = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = NumberValueObject.create(0.09 / 12);
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = BooleanValueObject.create(true);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const rate = StringValueObject.create('test');
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const rate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const nper = NumberValueObject.create(30 * 12);
+ const pv = NumberValueObject.create(125000);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, startPeriod, endPeriod, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/cumprinc/index.ts b/packages/engine-formula/src/functions/financial/cumprinc/index.ts
new file mode 100644
index 0000000000..f2f7199a86
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/cumprinc/index.ts
@@ -0,0 +1,98 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { calculateFV, calculatePMT } from '../../../basics/financial';
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+
+export class Cumprinc extends BaseFunction {
+ override minParams = 6;
+
+ override maxParams = 6;
+
+ override calculate(rate: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, startPeriod: BaseValueObject, endPeriod: BaseValueObject, type: BaseValueObject) {
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(rate, nper, pv, startPeriod, endPeriod, type);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [rateObject, nperObject, pvObject, startPeriodObject, endPeriodObject, typeObject] = variants as BaseValueObject[];
+
+ const rateValue = +rateObject.getValue();
+ const nperValue = +nperObject.getValue();
+ const pvValue = +pvObject.getValue();
+ const startPeriodValue = +startPeriodObject.getValue();
+ const endPeriodValue = +endPeriodObject.getValue();
+ const typeValue = +typeObject.getValue();
+
+ if (Number.isNaN(rateValue) || Number.isNaN(nperValue) || Number.isNaN(pvValue) || Number.isNaN(startPeriodValue) || Number.isNaN(endPeriodValue) || Number.isNaN(typeValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ rateValue <= 0 ||
+ nperValue <= 0 ||
+ pvValue <= 0 ||
+ startPeriodValue < 1 ||
+ endPeriodValue < 1 ||
+ startPeriodValue > endPeriodValue ||
+ ![0, 1].includes(typeValue)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (Math.trunc(startPeriodValue) !== startPeriodValue && Math.trunc(endPeriodValue) !== endPeriodValue && Math.trunc(startPeriodValue) === Math.trunc(endPeriodValue)) {
+ return NumberValueObject.create(0);
+ }
+
+ return this._getResult(rateValue, nperValue, pvValue, startPeriodValue, endPeriodValue, typeValue);
+ }
+
+ private _getResult(
+ rateValue: number,
+ nperValue: number,
+ pvValue: number,
+ startPeriodValue: number,
+ endPeriodValue: number,
+ typeValue: number
+ ): NumberValueObject {
+ const payment = calculatePMT(rateValue, nperValue, pvValue, 0, typeValue);
+
+ let result = 0;
+ let _startPeriodValue = Math.ceil(startPeriodValue);
+
+ if (_startPeriodValue === 1) {
+ result = typeValue === 0
+ ? payment + pvValue * rateValue
+ : payment;
+
+ _startPeriodValue++;
+ }
+
+ for (let i = _startPeriodValue; i <= endPeriodValue; i++) {
+ result += typeValue === 1
+ ? payment - (calculateFV(rateValue, i - 2, payment, pvValue, 1) - payment) * rateValue
+ : payment - calculateFV(rateValue, i - 1, payment, pvValue, 0) * rateValue;
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/db/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/db/__tests__/index.spec.ts
new file mode 100644
index 0000000000..ae9520d9b7
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/db/__tests__/index.spec.ts
@@ -0,0 +1,109 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Db } from '../index';
+import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test db function', () => {
+ const testFunction = new Db(FUNCTION_NAMES_FINANCIAL.DB);
+
+ describe('Db', () => {
+ it('Value is normal', () => {
+ const cost = NumberValueObject.create(10000000);
+ const salvage = NumberValueObject.create(1000000);
+ const life = NumberValueObject.create(6);
+ const period = NumberValueObject.create(1);
+ const month = NumberValueObject.create(7);
+ const result = testFunction.calculate(cost, salvage, life, period, month);
+ expect(result.getValue()).toStrictEqual(1860833.3333333333);
+ });
+
+ it('Cost is normal string', () => {
+ const cost = StringValueObject.create('test');
+ const salvage = NumberValueObject.create(1000000);
+ const life = NumberValueObject.create(6);
+ const period = NumberValueObject.create(1);
+ const month = NumberValueObject.create(7);
+ const result = testFunction.calculate(cost, salvage, life, period, month);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Cost <= 0 or salvage < 0 or cost < salvage', () => {
+ const cost = NumberValueObject.create(0);
+ const salvage = NumberValueObject.create(1000000);
+ const life = NumberValueObject.create(6);
+ const period = NumberValueObject.create(1);
+ const month = NumberValueObject.create(7);
+ const result = testFunction.calculate(cost, salvage, life, period, month);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const cost2 = NumberValueObject.create(2400);
+ const salvage2 = NumberValueObject.create(-1);
+ const result2 = testFunction.calculate(cost2, salvage2, life, period, month);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const cost3 = NumberValueObject.create(10000);
+ const salvage3 = NumberValueObject.create(1000000);
+ const result3 = testFunction.calculate(cost3, salvage3, life, period, month);
+ expect(result3.getValue()).toStrictEqual(-6731.666666666667);
+ });
+
+ it('Period <= 0 or period is last or period > life', () => {
+ const cost = NumberValueObject.create(10000000);
+ const salvage = NumberValueObject.create(1000000);
+ const life = NumberValueObject.create(6);
+ const period = NumberValueObject.create(0);
+ const month = NumberValueObject.create(7);
+ const result = testFunction.calculate(cost, salvage, life, period, month);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const period2 = NumberValueObject.create(6);
+ const result2 = testFunction.calculate(cost, salvage, life, period2, month);
+ expect(result2.getValue()).toStrictEqual(558417.5673602844);
+
+ const period3 = NumberValueObject.create(7);
+ const result3 = testFunction.calculate(cost, salvage, life, period3, month);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('value is array', () => {
+ const cost = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [1000000, 'test', true, false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const salvage = NumberValueObject.create(10000);
+ const life = NumberValueObject.create(6);
+ const period = NumberValueObject.create(1);
+ const month = NumberValueObject.create(7);
+ const result = testFunction.calculate(cost, salvage, life, period, month);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [312666.6666666667, ErrorType.VALUE, -2.1245, ErrorType.NUM, ErrorType.NAME, ErrorType.NUM],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/db/index.ts b/packages/engine-formula/src/functions/financial/db/index.ts
new file mode 100644
index 0000000000..f017274201
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/db/index.ts
@@ -0,0 +1,154 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';
+
+export class Db extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 5;
+
+ override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject, period: BaseValueObject, month?: BaseValueObject) {
+ let _month = month ?? NumberValueObject.create(12);
+
+ if (_month.isNull()) {
+ _month = NumberValueObject.create(12);
+ }
+
+ const maxRowLength = Math.max(
+ cost.isArray() ? (cost as ArrayValueObject).getRowCount() : 1,
+ salvage.isArray() ? (salvage as ArrayValueObject).getRowCount() : 1,
+ life.isArray() ? (life as ArrayValueObject).getRowCount() : 1,
+ period.isArray() ? (period as ArrayValueObject).getRowCount() : 1,
+ _month.isArray() ? (_month as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ cost.isArray() ? (cost as ArrayValueObject).getColumnCount() : 1,
+ salvage.isArray() ? (salvage as ArrayValueObject).getColumnCount() : 1,
+ life.isArray() ? (life as ArrayValueObject).getColumnCount() : 1,
+ period.isArray() ? (period as ArrayValueObject).getColumnCount() : 1,
+ _month.isArray() ? (_month as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const costArray = expandArrayValueObject(maxRowLength, maxColumnLength, cost, ErrorValueObject.create(ErrorType.NA));
+ const salvageArray = expandArrayValueObject(maxRowLength, maxColumnLength, salvage, ErrorValueObject.create(ErrorType.NA));
+ const lifeArray = expandArrayValueObject(maxRowLength, maxColumnLength, life, ErrorValueObject.create(ErrorType.NA));
+ const periodArray = expandArrayValueObject(maxRowLength, maxColumnLength, period, ErrorValueObject.create(ErrorType.NA));
+ const monthArray = expandArrayValueObject(maxRowLength, maxColumnLength, _month, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = costArray.map((costObject, rowIndex, columnIndex) => {
+ const salvageObject = salvageArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const lifeObject = lifeArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const periodObject = periodArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const monthObject = monthArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(costObject, salvageObject, lifeObject, periodObject, monthObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_costObject, _salvageObject, _lifeObject, _periodObject, _monthObject] = variants as BaseValueObject[];
+
+ const costValue = +_costObject.getValue();
+ const salvageValue = +_salvageObject.getValue();
+ const lifeValue = +_lifeObject.getValue();
+ let periodValue = +_periodObject.getValue();
+ const monthValue = Math.floor(+_monthObject.getValue());
+
+ if (
+ costValue < 0 ||
+ salvageValue < 0 ||
+ lifeValue <= 0 ||
+ periodValue <= 0 ||
+ Math.floor(periodValue) > Math.floor(lifeValue) ||
+ monthValue < 1 ||
+ monthValue > 12
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (periodValue < 1) {
+ periodValue = 1;
+ }
+
+ periodValue = Math.floor(periodValue);
+
+ return this._getResult(costValue, salvageValue, lifeValue, periodValue, monthValue, rowIndex, columnIndex);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+
+ private _getResult(
+ costValue: number,
+ salvageValue: number,
+ lifeValue: number,
+ periodValue: number,
+ monthValue: number,
+ rowIndex: number,
+ columnIndex: number
+ ): BaseValueObject {
+ const rate = +((1 - (salvageValue / costValue) ** (1 / lifeValue)).toFixed(3));
+
+ // Compute initial depreciation
+ const initial = (costValue * rate * monthValue) / 12;
+
+ // Compute total depreciation
+ let total = initial;
+ let current = 0;
+ const ceiling = periodValue === lifeValue ? lifeValue - 1 : periodValue;
+
+ for (let i = 2; i <= ceiling; i++) {
+ current = (costValue - total) * rate;
+ total += current;
+ }
+
+ let result;
+
+ // Depreciation for the first and last periods are special cases
+ if (periodValue === 1) {
+ // First period
+ result = initial;
+ } else if (periodValue === lifeValue) {
+ // Last period
+ result = (costValue - total) * rate;
+ } else {
+ result = current;
+ }
+
+ if (Number.isNaN(result) || !Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ } else {
+ return NumberValueObject.create(result);
+ }
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/ddb/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/ddb/__tests__/index.spec.ts
new file mode 100644
index 0000000000..69123b214d
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/ddb/__tests__/index.spec.ts
@@ -0,0 +1,109 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Ddb } from '../index';
+import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test ddb function', () => {
+ const testFunction = new Ddb(FUNCTION_NAMES_FINANCIAL.DDB);
+
+ describe('Ddb', () => {
+ it('Value is normal', () => {
+ const cost = NumberValueObject.create(24000);
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(6);
+ const period = NumberValueObject.create(1);
+ const factor = NumberValueObject.create(2);
+ const result = testFunction.calculate(cost, salvage, life, period, factor);
+ expect(result.getValue()).toStrictEqual(8000);
+ });
+
+ it('Cost is normal string', () => {
+ const cost = StringValueObject.create('test');
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(6);
+ const period = NumberValueObject.create(1);
+ const factor = NumberValueObject.create(2);
+ const result = testFunction.calculate(cost, salvage, life, period, factor);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Cost <= 0 or salvage < 0 or cost < salvage', () => {
+ const cost = NumberValueObject.create(0);
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(6);
+ const period = NumberValueObject.create(1);
+ const factor = NumberValueObject.create(2);
+ const result = testFunction.calculate(cost, salvage, life, period, factor);
+ expect(result.getValue()).toStrictEqual(0);
+
+ const cost2 = NumberValueObject.create(24000);
+ const salvage2 = NumberValueObject.create(-1);
+ const result2 = testFunction.calculate(cost2, salvage2, life, period, factor);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const cost3 = NumberValueObject.create(24000);
+ const salvage3 = NumberValueObject.create(1000000);
+ const result3 = testFunction.calculate(cost3, salvage3, life, period, factor);
+ expect(result3.getValue()).toStrictEqual(0);
+ });
+
+ it('Period <= 0 or period is last or period > life', () => {
+ const cost = NumberValueObject.create(24000);
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(6);
+ const period = NumberValueObject.create(0);
+ const factor = NumberValueObject.create(2);
+ const result = testFunction.calculate(cost, salvage, life, period, factor);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const period2 = NumberValueObject.create(6);
+ const result2 = testFunction.calculate(cost, salvage, life, period2, factor);
+ expect(result2.getValue()).toStrictEqual(160.49382716049513);
+
+ const period3 = NumberValueObject.create(7);
+ const result3 = testFunction.calculate(cost, salvage, life, period3, factor);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('value is array', () => {
+ const cost = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [24000, 'test', true, false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(6);
+ const period = NumberValueObject.create(1);
+ const factor = NumberValueObject.create(2);
+ const result = testFunction.calculate(cost, salvage, life, period, factor);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [8000, ErrorType.VALUE, 0, 0, ErrorType.NAME, 0],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/ddb/index.ts b/packages/engine-formula/src/functions/financial/ddb/index.ts
new file mode 100644
index 0000000000..643ada5349
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/ddb/index.ts
@@ -0,0 +1,129 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';
+
+export class Ddb extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 5;
+
+ override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject, period: BaseValueObject, factor?: BaseValueObject) {
+ let _factor = factor ?? NumberValueObject.create(2);
+
+ if (_factor.isNull()) {
+ _factor = NumberValueObject.create(2);
+ }
+
+ const maxRowLength = Math.max(
+ cost.isArray() ? (cost as ArrayValueObject).getRowCount() : 1,
+ salvage.isArray() ? (salvage as ArrayValueObject).getRowCount() : 1,
+ life.isArray() ? (life as ArrayValueObject).getRowCount() : 1,
+ period.isArray() ? (period as ArrayValueObject).getRowCount() : 1,
+ _factor.isArray() ? (_factor as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ cost.isArray() ? (cost as ArrayValueObject).getColumnCount() : 1,
+ salvage.isArray() ? (salvage as ArrayValueObject).getColumnCount() : 1,
+ life.isArray() ? (life as ArrayValueObject).getColumnCount() : 1,
+ period.isArray() ? (period as ArrayValueObject).getColumnCount() : 1,
+ _factor.isArray() ? (_factor as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const costArray = expandArrayValueObject(maxRowLength, maxColumnLength, cost, ErrorValueObject.create(ErrorType.NA));
+ const salvageArray = expandArrayValueObject(maxRowLength, maxColumnLength, salvage, ErrorValueObject.create(ErrorType.NA));
+ const lifeArray = expandArrayValueObject(maxRowLength, maxColumnLength, life, ErrorValueObject.create(ErrorType.NA));
+ const periodArray = expandArrayValueObject(maxRowLength, maxColumnLength, period, ErrorValueObject.create(ErrorType.NA));
+ const factorArray = expandArrayValueObject(maxRowLength, maxColumnLength, _factor, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = costArray.map((costObject, rowIndex, columnIndex) => {
+ const salvageObject = salvageArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const lifeObject = lifeArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const periodObject = periodArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const factorObject = factorArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(costObject, salvageObject, lifeObject, periodObject, factorObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_costObject, _salvageObject, _lifeObject, _periodObject, _factorObject] = variants as BaseValueObject[];
+
+ const costValue = +_costObject.getValue();
+ const salvageValue = +_salvageObject.getValue();
+ const lifeValue = +_lifeObject.getValue();
+ const periodValue = Math.ceil(+_periodObject.getValue());
+ const factorValue = +_factorObject.getValue();
+
+ if (
+ costValue < 0 ||
+ salvageValue < 0 ||
+ lifeValue <= 0 ||
+ periodValue <= 0 ||
+ Math.floor(periodValue) > Math.floor(lifeValue) ||
+ factorValue <= 0
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return this._getResult(costValue, salvageValue, lifeValue, periodValue, factorValue, rowIndex, columnIndex);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+
+ private _getResult(
+ costValue: number,
+ salvageValue: number,
+ lifeValue: number,
+ periodValue: number,
+ factorValue: number,
+ rowIndex: number,
+ columnIndex: number
+ ): BaseValueObject {
+ let total = 0;
+ let result = 0;
+
+ if (salvageValue < costValue) {
+ for (let i = 1; i <= periodValue; i++) {
+ result = Math.min((costValue - total) * (factorValue / lifeValue), costValue - salvageValue - total);
+ total += result;
+ }
+ }
+
+ if (Number.isNaN(result) || !Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ } else {
+ return NumberValueObject.create(result);
+ }
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/disc/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/disc/__tests__/index.spec.ts
new file mode 100644
index 0000000000..595ef82e4c
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/disc/__tests__/index.spec.ts
@@ -0,0 +1,126 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Disc } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test disc function', () => {
+ const testFunction = new Disc(FUNCTION_NAMES_FINANCIAL.DISC);
+
+ describe('Disc', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const pr = NumberValueObject.create(97.975);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, pr, redemption, basis);
+ expect(result.getValue()).toStrictEqual(0.0006863841691213469);
+ });
+
+ it('Value is normal, settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2048-1-1');
+ const maturity = StringValueObject.create('2018-7-1');
+ const pr = NumberValueObject.create(97.975);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, pr, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const pr = NumberValueObject.create(97.975);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, pr, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, pr, redemption, basis2);
+ expect(result2.getValue()).toStrictEqual(0.0006864406779661036);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, pr, redemption, basis3);
+ expect(result3.getValue()).toStrictEqual(0.0006765033407572402);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, pr, redemption, basis4);
+ expect(result4.getValue()).toStrictEqual(0.0006858992204899796);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, pr, redemption, basis5);
+ expect(result5.getValue()).toStrictEqual(0.0006864406779661036);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2048-1-1');
+ const pr = NumberValueObject.create(97.975);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, pr, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const pr = BooleanValueObject.create(true);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, pr, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2048-1-1');
+ const pr = NumberValueObject.create(97.975);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, pr, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const settlement = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const maturity = StringValueObject.create('2048-1-1');
+ const pr = NumberValueObject.create(97.975);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, pr, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/disc/index.ts b/packages/engine-formula/src/functions/financial/disc/index.ts
new file mode 100644
index 0000000000..eca19aef60
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/disc/index.ts
@@ -0,0 +1,76 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Disc extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 5;
+
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, pr: BaseValueObject, redemption: BaseValueObject, basis?: BaseValueObject) {
+ const _basis = basis ?? NumberValueObject.create(0);
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, pr, redemption, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, prObject, redemptionObject, basisObject] = variants as BaseValueObject[];
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const maturitySerialNumber = getDateSerialNumberByObject(maturityObject);
+
+ if (typeof maturitySerialNumber !== 'number') {
+ return maturitySerialNumber;
+ }
+
+ const prValue = +prObject.getValue();
+ const redemptionValue = +redemptionObject.getValue();
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(prValue) || Number.isNaN(redemptionValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ prValue <= 0 ||
+ redemptionValue <= 0 ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ Math.floor(settlementSerialNumber) >= Math.floor(maturitySerialNumber)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const { days, yearDays } = getTwoDateDaysByBasis(settlementSerialNumber, maturitySerialNumber, basisValue);
+
+ const result = ((redemptionValue - prValue) / redemptionValue) * (yearDays / days);
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/dollarde/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/dollarde/__tests__/index.spec.ts
new file mode 100644
index 0000000000..aca801ec3a
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/dollarde/__tests__/index.spec.ts
@@ -0,0 +1,75 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Dollarde } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test dollarde function', () => {
+ const testFunction = new Dollarde(FUNCTION_NAMES_FINANCIAL.DOLLARDE);
+
+ describe('Dollarde', () => {
+ it('Value is normal', () => {
+ const fractionalDollar = NumberValueObject.create(1.02);
+ const fraction = NumberValueObject.create(16);
+ const result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(1.125);
+ });
+
+ it('Value is error', () => {
+ const fractionalDollar = ErrorValueObject.create(ErrorType.NAME);
+ const fraction = NumberValueObject.create(16);
+ const result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const fractionalDollar = NumberValueObject.create(1.02);
+ const fraction = BooleanValueObject.create(true);
+ const result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const fractionalDollar = StringValueObject.create('test');
+ const fraction = NumberValueObject.create(16);
+ const result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const fractionalDollar = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const fraction = NumberValueObject.create(16);
+ const result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/dollarde/index.ts b/packages/engine-formula/src/functions/financial/dollarde/index.ts
new file mode 100644
index 0000000000..8efc356af5
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/dollarde/index.ts
@@ -0,0 +1,67 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dollarde extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 2;
+
+ override calculate(fractionalDollar: BaseValueObject, fraction: BaseValueObject) {
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(fractionalDollar, fraction);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [fractionalDollarObject, fractionObject] = variants as BaseValueObject[];
+
+ const fractionalDollarValue = +fractionalDollarObject.getValue();
+ let fractionValue = Math.floor(+fractionObject.getValue());
+
+ if (Number.isNaN(fractionalDollarValue) || Number.isNaN(fractionValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (fractionValue < 0) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (fractionValue >= 0 && fractionValue < 1) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ fractionValue = Number.parseInt(`${fractionValue}`, 10);
+
+ // Compute integer part
+ let result = Number.parseInt(`${fractionalDollarValue}`, 10);
+
+ // Add decimal part
+ result += ((fractionalDollarValue % 1) * 10 ** Math.ceil(Math.log(fractionValue) / Math.LN10)) / fractionValue;
+
+ // Round result
+ const power = 10 ** (Math.ceil(Math.log(fractionValue) / Math.LN2) + 1);
+
+ result = Math.round(result * power) / power;
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/dollarfr/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/dollarfr/__tests__/index.spec.ts
new file mode 100644
index 0000000000..ddbf1c202e
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/dollarfr/__tests__/index.spec.ts
@@ -0,0 +1,75 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Dollarfr } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test dollarfr function', () => {
+ const testFunction = new Dollarfr(FUNCTION_NAMES_FINANCIAL.DOLLARFR);
+
+ describe('Dollarfr', () => {
+ it('Value is normal', () => {
+ const fractionalDollar = NumberValueObject.create(1.02);
+ const fraction = NumberValueObject.create(16);
+ const result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(1.0032);
+ });
+
+ it('Value is error', () => {
+ const fractionalDollar = ErrorValueObject.create(ErrorType.NAME);
+ const fraction = NumberValueObject.create(16);
+ const result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const fractionalDollar = NumberValueObject.create(1.02);
+ const fraction = BooleanValueObject.create(true);
+ const result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const fractionalDollar = StringValueObject.create('test');
+ const fraction = NumberValueObject.create(16);
+ const result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const fractionalDollar = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const fraction = NumberValueObject.create(16);
+ const result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/dollarfr/index.ts b/packages/engine-formula/src/functions/financial/dollarfr/index.ts
new file mode 100644
index 0000000000..6f5ca3ce17
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/dollarfr/index.ts
@@ -0,0 +1,62 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dollarfr extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 2;
+
+ override calculate(decimalDollar: BaseValueObject, fraction: BaseValueObject) {
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(decimalDollar, fraction);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [decimalDollarObject, fractionObject] = variants as BaseValueObject[];
+
+ const decimalDollarValue = +decimalDollarObject.getValue();
+ let fractionValue = Math.floor(+fractionObject.getValue());
+
+ if (Number.isNaN(decimalDollarValue) || Number.isNaN(fractionValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (fractionValue < 0) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (fractionValue >= 0 && fractionValue < 1) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ fractionValue = Number.parseInt(`${fractionValue}`, 10);
+
+ // Compute integer part
+ let result = Number.parseInt(`${decimalDollarValue}`, 10);
+
+ // Add decimal part
+ result += (decimalDollarValue % 1) * 10 ** -Math.ceil(Math.log(fractionValue) / Math.LN10) * fractionValue;
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/effect/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/effect/__tests__/index.spec.ts
new file mode 100644
index 0000000000..85c1c2564b
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/effect/__tests__/index.spec.ts
@@ -0,0 +1,82 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Effect } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test effect function', () => {
+ const testFunction = new Effect(FUNCTION_NAMES_FINANCIAL.EFFECT);
+
+ describe('Effect', () => {
+ it('Value is normal', () => {
+ const nominalRate = NumberValueObject.create(0.0525);
+ const npery = NumberValueObject.create(4);
+ const result = testFunction.calculate(nominalRate, npery);
+ expect(result.getValue()).toStrictEqual(0.05354266737075819);
+ });
+
+ it('Value is error', () => {
+ const nominalRate = ErrorValueObject.create(ErrorType.NAME);
+ const npery = NumberValueObject.create(4);
+ const result = testFunction.calculate(nominalRate, npery);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const nominalRate = NumberValueObject.create(0.0525);
+ const npery = BooleanValueObject.create(true);
+ const result = testFunction.calculate(nominalRate, npery);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is blank cell', () => {
+ const nominalRate = NumberValueObject.create(0.0525);
+ const npery = NullValueObject.create();
+ const result = testFunction.calculate(nominalRate, npery);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is normal string', () => {
+ const nominalRate = StringValueObject.create('test');
+ const npery = NumberValueObject.create(4);
+ const result = testFunction.calculate(nominalRate, npery);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const nominalRate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const npery = NumberValueObject.create(4);
+ const result = testFunction.calculate(nominalRate, npery);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/effect/index.ts b/packages/engine-formula/src/functions/financial/effect/index.ts
new file mode 100644
index 0000000000..be621937ca
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/effect/index.ts
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Effect extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 2;
+
+ override calculate(nominalRate: BaseValueObject, npery: BaseValueObject) {
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(nominalRate, npery);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [nominalRateObject, nperyObject] = variants as BaseValueObject[];
+
+ const nominalRateValue = +nominalRateObject.getValue();
+ let nperyValue = Math.floor(+nperyObject.getValue());
+
+ if (Number.isNaN(nominalRateValue) || Number.isNaN(nperyValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (nominalRateValue <= 0 || nperyValue < 1) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ nperyValue = Number.parseInt(`${nperyValue}`, 10);
+
+ // Return effective annual interest rate
+ const result = (1 + nominalRateValue / nperyValue) ** nperyValue - 1;
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/function-map.ts b/packages/engine-formula/src/functions/financial/function-map.ts
index 1d2ff99d1c..a152bb98e8 100644
--- a/packages/engine-formula/src/functions/financial/function-map.ts
+++ b/packages/engine-formula/src/functions/financial/function-map.ts
@@ -14,4 +14,63 @@
* limitations under the License.
*/
-export const functionFinancial = [];
+import { FUNCTION_NAMES_FINANCIAL } from './function-names';
+import { Accrint } from './accrint';
+import { Accrintm } from './accrintm';
+import { Amorlinc } from './amorlinc';
+import { Coupdaybs } from './coupdaybs';
+import { Coupdays } from './coupdays';
+import { Coupdaysnc } from './coupdaysnc';
+import { Coupncd } from './coupncd';
+import { Coupnum } from './coupnum';
+import { Couppcd } from './couppcd';
+import { Cumipmt } from './cumipmt';
+import { Cumprinc } from './cumprinc';
+import { Db } from './db';
+import { Ddb } from './ddb';
+import { Disc } from './disc';
+import { Dollarde } from './dollarde';
+import { Dollarfr } from './dollarfr';
+import { Effect } from './effect';
+import { Fv } from './fv';
+import { Fvschedule } from './fvschedule';
+import { Intrate } from './intrate';
+import { Ipmt } from './ipmt';
+import { Ispmt } from './ispmt';
+import { Nominal } from './nominal';
+import { Nper } from './nper';
+import { Pmt } from './pmt';
+import { Ppmt } from './ppmt';
+import { Pv } from './pv';
+import { Rate } from './rate';
+
+export const functionFinancial = [
+ [Accrint, FUNCTION_NAMES_FINANCIAL.ACCRINT],
+ [Accrintm, FUNCTION_NAMES_FINANCIAL.ACCRINTM],
+ [Amorlinc, FUNCTION_NAMES_FINANCIAL.AMORLINC],
+ [Coupdaybs, FUNCTION_NAMES_FINANCIAL.COUPDAYBS],
+ [Coupdays, FUNCTION_NAMES_FINANCIAL.COUPDAYS],
+ [Coupdaysnc, FUNCTION_NAMES_FINANCIAL.COUPDAYSNC],
+ [Coupncd, FUNCTION_NAMES_FINANCIAL.COUPNCD],
+ [Coupnum, FUNCTION_NAMES_FINANCIAL.COUPNUM],
+ [Couppcd, FUNCTION_NAMES_FINANCIAL.COUPPCD],
+ [Cumipmt, FUNCTION_NAMES_FINANCIAL.CUMIPMT],
+ [Cumprinc, FUNCTION_NAMES_FINANCIAL.CUMPRINC],
+ [Db, FUNCTION_NAMES_FINANCIAL.DB],
+ [Ddb, FUNCTION_NAMES_FINANCIAL.DDB],
+ [Disc, FUNCTION_NAMES_FINANCIAL.DISC],
+ [Dollarde, FUNCTION_NAMES_FINANCIAL.DOLLARDE],
+ [Dollarfr, FUNCTION_NAMES_FINANCIAL.DOLLARFR],
+ [Effect, FUNCTION_NAMES_FINANCIAL.EFFECT],
+ [Fv, FUNCTION_NAMES_FINANCIAL.FV],
+ [Fvschedule, FUNCTION_NAMES_FINANCIAL.FVSCHEDULE],
+ [Intrate, FUNCTION_NAMES_FINANCIAL.INTRATE],
+ [Ipmt, FUNCTION_NAMES_FINANCIAL.IPMT],
+ [Ispmt, FUNCTION_NAMES_FINANCIAL.ISPMT],
+ [Nominal, FUNCTION_NAMES_FINANCIAL.NOMINAL],
+ [Nper, FUNCTION_NAMES_FINANCIAL.NPER],
+ [Pmt, FUNCTION_NAMES_FINANCIAL.PMT],
+ [Ppmt, FUNCTION_NAMES_FINANCIAL.PPMT],
+ [Pv, FUNCTION_NAMES_FINANCIAL.PV],
+ [Rate, FUNCTION_NAMES_FINANCIAL.RATE],
+];
diff --git a/packages/engine-formula/src/functions/financial/fv/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/fv/__tests__/index.spec.ts
new file mode 100644
index 0000000000..8b64957fe5
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/fv/__tests__/index.spec.ts
@@ -0,0 +1,134 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Fv } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test fv function', () => {
+ const testFunction = new Fv(FUNCTION_NAMES_FINANCIAL.FV);
+
+ describe('Fv', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.06 / 12);
+ const nper = NumberValueObject.create(10);
+ const pmt = NumberValueObject.create(-200);
+ const pv = NumberValueObject.create(-500);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pmt, pv, type);
+ expect(result.getValue()).toStrictEqual(2571.175347651979);
+
+ const type2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(rate, nper, pmt, pv, type2);
+ expect(result2.getValue()).toStrictEqual(2581.4033740601362);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const nper = NumberValueObject.create(10);
+ const pmt = NumberValueObject.create(-200);
+ const pv = NumberValueObject.create(-500);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pmt, pv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = BooleanValueObject.create(true);
+ const nper = NumberValueObject.create(10);
+ const pmt = NumberValueObject.create(-200);
+ const pv = NumberValueObject.create(-500);
+ const type = NumberValueObject.create(1);
+ const result = testFunction.calculate(rate, nper, pmt, pv, type);
+ expect(result.getValue()).toStrictEqual(921200);
+ });
+
+ it('Value is blank cell', () => {
+ const rate = NullValueObject.create();
+ const nper = NumberValueObject.create(10);
+ const pmt = NumberValueObject.create(-200);
+ const pv = NumberValueObject.create(-500);
+ const type = NumberValueObject.create(1);
+ const result = testFunction.calculate(rate, nper, pmt, pv, type);
+ expect(result.getValue()).toStrictEqual(2500);
+ });
+
+ it('Value is normal string', () => {
+ const rate = StringValueObject.create('test');
+ const nper = NumberValueObject.create(10);
+ const pmt = NumberValueObject.create(-200);
+ const pv = NumberValueObject.create(-500);
+ const type = NumberValueObject.create(1);
+ const result = testFunction.calculate(rate, nper, pmt, pv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const rate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['test', 0.06, false],
+ [true, null, ErrorType.NAME],
+ [-22, '1.23', 100],
+ ]),
+ rowCount: 3,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const nper = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, 10, false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 4,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const pmt = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ [-200],
+ [false],
+ [null],
+ ]),
+ rowCount: 4,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const pv = NumberValueObject.create(-500);
+ const type = NumberValueObject.create(1);
+ const result = testFunction.calculate(rate, nper, pmt, pv, type);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, 881.4522056325036, 500, ErrorType.NA],
+ [1400, 2500, ErrorType.NAME, ErrorType.NA],
+ [-10500, 1520612.7751707924, 500, ErrorType.NA],
+ [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/fv/index.ts b/packages/engine-formula/src/functions/financial/fv/index.ts
new file mode 100644
index 0000000000..ccfd5bed18
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/fv/index.ts
@@ -0,0 +1,97 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { calculateFV } from '../../../basics/financial';
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';
+
+export class Fv extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 5;
+
+ override calculate(rate: BaseValueObject, nper: BaseValueObject, pmt: BaseValueObject, pv?: BaseValueObject, type?: BaseValueObject) {
+ const _pv = pv ?? NumberValueObject.create(0);
+ const _type = type ?? NumberValueObject.create(0);
+
+ const maxRowLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getRowCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getRowCount() : 1,
+ pmt.isArray() ? (pmt as ArrayValueObject).getRowCount() : 1,
+ _pv.isArray() ? (_pv as ArrayValueObject).getRowCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getColumnCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getColumnCount() : 1,
+ pmt.isArray() ? (pmt as ArrayValueObject).getColumnCount() : 1,
+ _pv.isArray() ? (_pv as ArrayValueObject).getColumnCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const rateArray = expandArrayValueObject(maxRowLength, maxColumnLength, rate, ErrorValueObject.create(ErrorType.NA));
+ const nperArray = expandArrayValueObject(maxRowLength, maxColumnLength, nper, ErrorValueObject.create(ErrorType.NA));
+ const pmtArray = expandArrayValueObject(maxRowLength, maxColumnLength, pmt, ErrorValueObject.create(ErrorType.NA));
+ const pvArray = expandArrayValueObject(maxRowLength, maxColumnLength, _pv, ErrorValueObject.create(ErrorType.NA));
+ const typeArray = expandArrayValueObject(maxRowLength, maxColumnLength, _type, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = rateArray.map((rateObject, rowIndex, columnIndex) => {
+ const nperObject = nperArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const pmtObject = pmtArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const pvObject = pvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const typeObject = typeArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(rateObject, nperObject, pmtObject, pvObject, typeObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_rateObject, _nperObject, _pmtObject, _pvObject, _typeObject] = variants as BaseValueObject[];
+
+ const rateValue = +_rateObject.getValue();
+ const nperValue = +_nperObject.getValue();
+ const pmtValue = +_pmtObject.getValue();
+ const pvValue = +_pvObject.getValue();
+ const typeValue = +_typeObject.getValue();
+
+ const result = calculateFV(rateValue, nperValue, pmtValue, pvValue, typeValue ? 1 : 0);
+
+ if (Number.isNaN(result) || !Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ } else {
+ return NumberValueObject.create(result);
+ }
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/fvschedule/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/fvschedule/__tests__/index.spec.ts
new file mode 100644
index 0000000000..7ce123cdc1
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/fvschedule/__tests__/index.spec.ts
@@ -0,0 +1,82 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Fvschedule } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test fvschedule function', () => {
+ const testFunction = new Fvschedule(FUNCTION_NAMES_FINANCIAL.FVSCHEDULE);
+
+ describe('Fvschedule', () => {
+ it('Value is normal', () => {
+ const principal = NumberValueObject.create(1);
+ const schedule = ArrayValueObject.create('{0.09,0.11,0.1}');
+ const result = testFunction.calculate(principal, schedule);
+ expect(result.getValue()).toStrictEqual(1.3308900000000004);
+ });
+
+ it('Value is error', () => {
+ const principal = ErrorValueObject.create(ErrorType.NAME);
+ const schedule = ArrayValueObject.create('{0.09,0.11,0.1}');
+ const result = testFunction.calculate(principal, schedule);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const principal = BooleanValueObject.create(true);
+ const schedule = ArrayValueObject.create('{0.09,0.11,0.1}');
+ const result = testFunction.calculate(principal, schedule);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is blank cell', () => {
+ const principal = NullValueObject.create();
+ const schedule = ArrayValueObject.create('{0.09,0.11,0.1}');
+ const result = testFunction.calculate(principal, schedule);
+ expect(result.getValue()).toStrictEqual(0);
+ });
+
+ it('Value is normal string', () => {
+ const principal = StringValueObject.create('test');
+ const schedule = ArrayValueObject.create('{0.09,0.11,0.1}');
+ const result = testFunction.calculate(principal, schedule);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const principal = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const schedule = ArrayValueObject.create('{0.09,0.11,0.1}');
+ const result = testFunction.calculate(principal, schedule);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/fvschedule/index.ts b/packages/engine-formula/src/functions/financial/fvschedule/index.ts
new file mode 100644
index 0000000000..411e9d716f
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/fvschedule/index.ts
@@ -0,0 +1,79 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Fvschedule extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 2;
+
+ override calculate(principal: BaseValueObject, schedule: BaseValueObject) {
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(principal);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [principalObject] = variants as BaseValueObject[];
+
+ const principalValue = +principalObject.getValue();
+
+ if (Number.isNaN(principalValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ let result = principalValue;
+
+ if (schedule.isArray()) {
+ const scheduleValues = schedule.getArrayValue().flat();
+
+ for (let i = 0; i < scheduleValues.length; i++) {
+ const scheduleObject = scheduleValues[i] as BaseValueObject;
+
+ if (scheduleObject.isBoolean()) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ const scheduleValue = +scheduleObject.getValue();
+
+ if (Number.isNaN(scheduleValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ result *= 1 + scheduleValue;
+ }
+ } else {
+ if (schedule.isBoolean()) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ const scheduleValue = +schedule.getValue();
+
+ if (Number.isNaN(scheduleValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ result *= 1 + scheduleValue;
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/intrate/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/intrate/__tests__/index.spec.ts
new file mode 100644
index 0000000000..9650e0040d
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/intrate/__tests__/index.spec.ts
@@ -0,0 +1,126 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Intrate } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test intrate function', () => {
+ const testFunction = new Intrate(FUNCTION_NAMES_FINANCIAL.INTRATE);
+
+ describe('Intrate', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-2-15');
+ const maturity = StringValueObject.create('2008-5-15');
+ const investment = NumberValueObject.create(10000000);
+ const redemption = NumberValueObject.create(10144200);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, redemption, basis);
+ expect(result.getValue()).toStrictEqual(0.05768);
+ });
+
+ it('Value is normal, settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2008-5-15');
+ const maturity = StringValueObject.create('2008-2-15');
+ const investment = NumberValueObject.create(10000000);
+ const redemption = NumberValueObject.create(10144200);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2008-2-15');
+ const maturity = StringValueObject.create('2008-5-15');
+ const investment = NumberValueObject.create(10000000);
+ const redemption = NumberValueObject.create(10144200);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, investment, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, investment, redemption, basis2);
+ expect(result2.getValue()).toStrictEqual(0.05768);
+
+ const basis3 = NumberValueObject.create(1);
+ const result3 = testFunction.calculate(settlement, maturity, investment, redemption, basis3);
+ expect(result3.getValue()).toStrictEqual(0.05864133333333333);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, investment, redemption, basis4);
+ expect(result4.getValue()).toStrictEqual(0.05848111111111111);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, investment, redemption, basis5);
+ expect(result5.getValue()).toStrictEqual(0.05768);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2008-5-15');
+ const investment = NumberValueObject.create(10000000);
+ const redemption = NumberValueObject.create(10144200);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-2-15');
+ const maturity = StringValueObject.create('2008-5-15');
+ const investment = BooleanValueObject.create(true);
+ const redemption = NumberValueObject.create(10144200);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2008-5-15');
+ const investment = NumberValueObject.create(10000000);
+ const redemption = NumberValueObject.create(10144200);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const settlement = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['2012-3-29', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const maturity = StringValueObject.create('2008-5-15');
+ const investment = NumberValueObject.create(10000000);
+ const redemption = NumberValueObject.create(10144200);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/intrate/index.ts b/packages/engine-formula/src/functions/financial/intrate/index.ts
new file mode 100644
index 0000000000..b72c8920e5
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/intrate/index.ts
@@ -0,0 +1,76 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Intrate extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 5;
+
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, investment: BaseValueObject, redemption: BaseValueObject, basis?: BaseValueObject) {
+ const _basis = basis ?? NumberValueObject.create(0);
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, investment, redemption, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, investmentObject, redemptionObject, basisObject] = variants as BaseValueObject[];
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const maturitySerialNumber = getDateSerialNumberByObject(maturityObject);
+
+ if (typeof maturitySerialNumber !== 'number') {
+ return maturitySerialNumber;
+ }
+
+ const investmentValue = +investmentObject.getValue();
+ const redemptionValue = +redemptionObject.getValue();
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(investmentValue) || Number.isNaN(redemptionValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ investmentValue <= 0 ||
+ redemptionValue <= 0 ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ Math.floor(settlementSerialNumber) >= Math.floor(maturitySerialNumber)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const { days, yearDays } = getTwoDateDaysByBasis(settlementSerialNumber, maturitySerialNumber, basisValue);
+
+ const result = ((redemptionValue - investmentValue) / investmentValue) * (yearDays / days);
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/ipmt/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/ipmt/__tests__/index.spec.ts
new file mode 100644
index 0000000000..10c49e0963
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/ipmt/__tests__/index.spec.ts
@@ -0,0 +1,140 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Ipmt } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test ipmt function', () => {
+ const testFunction = new Ipmt(FUNCTION_NAMES_FINANCIAL.IPMT);
+
+ describe('Ipmt', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.1 / 12);
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(-666.6666666666666);
+
+ const type2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(rate, per, nper, pv, fv, type2);
+ expect(result2.getValue()).toStrictEqual(0);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = BooleanValueObject.create(true);
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(-80000);
+ });
+
+ it('Value is blank cell', () => {
+ const rate = NullValueObject.create();
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(-0 | 0);
+ });
+
+ it('Value is normal string', () => {
+ const rate = StringValueObject.create('test');
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const rate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['test', 0.06, false],
+ [true, null, ErrorType.NAME],
+ [-22, '1.23', 100],
+ ]),
+ rowCount: 3,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const per = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, 2, false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 4,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const nper = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ [10],
+ [false],
+ [null],
+ ]),
+ rowCount: 4,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, ErrorType.NUM, ErrorType.NUM, ErrorType.NA],
+ [-80000, 0, ErrorType.NAME, ErrorType.NA],
+ [ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, ErrorType.NA],
+ [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/ipmt/index.ts b/packages/engine-formula/src/functions/financial/ipmt/index.ts
new file mode 100644
index 0000000000..74cfd0f2ab
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/ipmt/index.ts
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { calculateIPMT } from '../../../basics/financial';
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';
+
+export class Ipmt extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 6;
+
+ override calculate(rate: BaseValueObject, per: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject) {
+ const _fv = fv ?? NumberValueObject.create(0);
+ const _type = type ?? NumberValueObject.create(0);
+
+ const maxRowLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getRowCount() : 1,
+ per.isArray() ? (per as ArrayValueObject).getRowCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getRowCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getRowCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getRowCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getColumnCount() : 1,
+ per.isArray() ? (per as ArrayValueObject).getColumnCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getColumnCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getColumnCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getColumnCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const rateArray = expandArrayValueObject(maxRowLength, maxColumnLength, rate, ErrorValueObject.create(ErrorType.NA));
+ const perArray = expandArrayValueObject(maxRowLength, maxColumnLength, per, ErrorValueObject.create(ErrorType.NA));
+ const nperArray = expandArrayValueObject(maxRowLength, maxColumnLength, nper, ErrorValueObject.create(ErrorType.NA));
+ const pvArray = expandArrayValueObject(maxRowLength, maxColumnLength, pv, ErrorValueObject.create(ErrorType.NA));
+ const fvArray = expandArrayValueObject(maxRowLength, maxColumnLength, _fv, ErrorValueObject.create(ErrorType.NA));
+ const typeArray = expandArrayValueObject(maxRowLength, maxColumnLength, _type, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = rateArray.map((rateObject, rowIndex, columnIndex) => {
+ const perObject = perArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const nperObject = nperArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const pvObject = pvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const fvObject = fvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const typeObject = typeArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(rateObject, perObject, nperObject, pvObject, fvObject, typeObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_rateObject, _perObject, _nperObject, _pvObject, _fvObject, _typeObject] = variants as BaseValueObject[];
+
+ const rateValue = +_rateObject.getValue();
+ const perValue = +_perObject.getValue();
+ const nperValue = +_nperObject.getValue();
+ const pvValue = +_pvObject.getValue();
+ const fvValue = +_fvObject.getValue();
+ const typeValue = +_typeObject.getValue();
+
+ if (perValue < 1 || Math.floor(perValue) > Math.ceil(nperValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = calculateIPMT(rateValue, perValue, nperValue, pvValue, fvValue, typeValue ? 1 : 0);
+
+ if (Number.isNaN(result) || !Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ } else {
+ return NumberValueObject.create(result);
+ }
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/ispmt/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/ispmt/__tests__/index.spec.ts
new file mode 100644
index 0000000000..1f438a4d04
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/ispmt/__tests__/index.spec.ts
@@ -0,0 +1,133 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Ispmt } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test ispmt function', () => {
+ const testFunction = new Ispmt(FUNCTION_NAMES_FINANCIAL.ISPMT);
+
+ describe('Ispmt', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.1 / 12);
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const result = testFunction.calculate(rate, per, nper, pv);
+ expect(result.getValue()).toStrictEqual(-648.1481481481482);
+ });
+
+ it('Nper value is 0', () => {
+ const rate = NumberValueObject.create(0.1 / 12);
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(0);
+ const pv = NumberValueObject.create(80000);
+ const result = testFunction.calculate(rate, per, nper, pv);
+ expect(result.getValue()).toStrictEqual(ErrorType.DIV_BY_ZERO);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const result = testFunction.calculate(rate, per, nper, pv);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = BooleanValueObject.create(true);
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const result = testFunction.calculate(rate, per, nper, pv);
+ expect(result.getValue()).toStrictEqual(-77777.77777777778);
+ });
+
+ it('Value is blank cell', () => {
+ const rate = NullValueObject.create();
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const result = testFunction.calculate(rate, per, nper, pv);
+ expect(result.getValue()).toBe(0 | -0);
+ });
+
+ it('Value is normal string', () => {
+ const rate = StringValueObject.create('test');
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const result = testFunction.calculate(rate, per, nper, pv);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const rate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['test', 0.06, false],
+ [true, null, ErrorType.NAME],
+ [-22, '1.23', 100],
+ ]),
+ rowCount: 3,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const per = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, 2, false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 4,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const nper = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ [10],
+ [false],
+ [null],
+ ]),
+ rowCount: 4,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const pv = NumberValueObject.create(80000);
+ const result = testFunction.calculate(rate, per, nper, pv);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, 4800, 0 | -0, ErrorType.NA],
+ [-72000, 0 | -0, ErrorType.NAME, ErrorType.NA],
+ [ErrorType.DIV_BY_ZERO, ErrorType.DIV_BY_ZERO, ErrorType.DIV_BY_ZERO, ErrorType.NA],
+ [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/ispmt/index.ts b/packages/engine-formula/src/functions/financial/ispmt/index.ts
new file mode 100644
index 0000000000..db4e7eedb5
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/ispmt/index.ts
@@ -0,0 +1,84 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';
+
+export class Ispmt extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 4;
+
+ override calculate(rate: BaseValueObject, per: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject) {
+ const maxRowLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getRowCount() : 1,
+ per.isArray() ? (per as ArrayValueObject).getRowCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getRowCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getColumnCount() : 1,
+ per.isArray() ? (per as ArrayValueObject).getColumnCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getColumnCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const rateArray = expandArrayValueObject(maxRowLength, maxColumnLength, rate, ErrorValueObject.create(ErrorType.NA));
+ const perArray = expandArrayValueObject(maxRowLength, maxColumnLength, per, ErrorValueObject.create(ErrorType.NA));
+ const nperArray = expandArrayValueObject(maxRowLength, maxColumnLength, nper, ErrorValueObject.create(ErrorType.NA));
+ const pvArray = expandArrayValueObject(maxRowLength, maxColumnLength, pv, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = rateArray.map((rateObject, rowIndex, columnIndex) => {
+ const perObject = perArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const nperObject = nperArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const pvObject = pvArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(rateObject, perObject, nperObject, pvObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_rateObject, _perObject, _nperObject, _pvObject] = variants as BaseValueObject[];
+
+ const rateValue = +_rateObject.getValue();
+ const perValue = +_perObject.getValue();
+ const nperValue = +_nperObject.getValue();
+ const pvValue = +_pvObject.getValue();
+
+ if (nperValue === 0) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ const result = pvValue * rateValue * (perValue / nperValue - 1);
+
+ return NumberValueObject.create(result);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/nominal/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/nominal/__tests__/index.spec.ts
new file mode 100644
index 0000000000..b52bfc167f
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/nominal/__tests__/index.spec.ts
@@ -0,0 +1,82 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Nominal } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test nominal function', () => {
+ const testFunction = new Nominal(FUNCTION_NAMES_FINANCIAL.NOMINAL);
+
+ describe('Nominal', () => {
+ it('Value is normal', () => {
+ const effectRate = NumberValueObject.create(0.053543);
+ const npery = NumberValueObject.create(4);
+ const result = testFunction.calculate(effectRate, npery);
+ expect(result.getValue()).toStrictEqual(0.052500319868356016);
+ });
+
+ it('Value is error', () => {
+ const effectRate = ErrorValueObject.create(ErrorType.NAME);
+ const npery = NumberValueObject.create(4);
+ const result = testFunction.calculate(effectRate, npery);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const effectRate = NumberValueObject.create(0.053543);
+ const npery = BooleanValueObject.create(true);
+ const result = testFunction.calculate(effectRate, npery);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is blank cell', () => {
+ const effectRate = NumberValueObject.create(0.053543);
+ const npery = NullValueObject.create();
+ const result = testFunction.calculate(effectRate, npery);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is normal string', () => {
+ const effectRate = StringValueObject.create('test');
+ const npery = NumberValueObject.create(4);
+ const result = testFunction.calculate(effectRate, npery);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const effectRate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const npery = NumberValueObject.create(4);
+ const result = testFunction.calculate(effectRate, npery);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/nominal/index.ts b/packages/engine-formula/src/functions/financial/nominal/index.ts
new file mode 100644
index 0000000000..6f1666eb6e
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/nominal/index.ts
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Nominal extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 2;
+
+ override calculate(effectRate: BaseValueObject, npery: BaseValueObject) {
+ const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(effectRate, npery);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [effectRateObject, nperyObject] = variants as BaseValueObject[];
+
+ const effectRateValue = +effectRateObject.getValue();
+ let nperyValue = Math.floor(+nperyObject.getValue());
+
+ if (Number.isNaN(effectRateValue) || Number.isNaN(nperyValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (effectRateValue <= 0 || nperyValue < 1) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ nperyValue = Number.parseInt(`${nperyValue}`, 10);
+
+ // Return nominal annual interest rate
+ const result = ((effectRateValue + 1) ** (1 / nperyValue) - 1) * nperyValue;
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/nper/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/nper/__tests__/index.spec.ts
new file mode 100644
index 0000000000..6c25ca5adf
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/nper/__tests__/index.spec.ts
@@ -0,0 +1,120 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Nper } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test nper function', () => {
+ const testFunction = new Nper(FUNCTION_NAMES_FINANCIAL.NPER);
+
+ describe('Nper', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.12 / 12);
+ const pmt = NumberValueObject.create(-100);
+ const pv = NumberValueObject.create(-1000);
+ const fv = NumberValueObject.create(10000);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, pmt, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(60.08212285376166);
+
+ const type2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(rate, pmt, pv, fv, type2);
+ expect(result2.getValue()).toStrictEqual(59.67386567429457);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const pmt = NumberValueObject.create(-100);
+ const pv = NumberValueObject.create(-1000);
+ const fv = NumberValueObject.create(10000);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, pmt, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = BooleanValueObject.create(true);
+ const pmt = NumberValueObject.create(-100);
+ const pv = NumberValueObject.create(-1000);
+ const fv = NumberValueObject.create(10000);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, pmt, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(3.1987798641144978);
+ });
+
+ it('Value is blank cell', () => {
+ const rate = NullValueObject.create();
+ const pmt = NumberValueObject.create(-100);
+ const pv = NumberValueObject.create(-1000);
+ const fv = NumberValueObject.create(10000);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, pmt, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(90);
+ });
+
+ it('Value is normal string', () => {
+ const rate = StringValueObject.create('test');
+ const pmt = NumberValueObject.create(-100);
+ const pv = NumberValueObject.create(-1000);
+ const fv = NumberValueObject.create(10000);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, pmt, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const rate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['test', 0.06, false],
+ [true, null, ErrorType.NAME],
+ [-22, '1.23', 100],
+ ]),
+ rowCount: 3,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const pmt = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, -200, false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 4,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const pv = NumberValueObject.create(-1000);
+ const fv = NumberValueObject.create(10000);
+ const type = NumberValueObject.create(1);
+ const result = testFunction.calculate(rate, pmt, pv, fv, type);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, 18.769843284838526, ErrorType.DIV_BY_ZERO, ErrorType.NA],
+ [3.324527806346263, 45, ErrorType.NAME, ErrorType.NA],
+ [ErrorType.NUM, 2.5296801547320293, 0.49892198580547814, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/nper/index.ts b/packages/engine-formula/src/functions/financial/nper/index.ts
new file mode 100644
index 0000000000..01fa522492
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/nper/index.ts
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';
+
+export class Nper extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 5;
+
+ override calculate(rate: BaseValueObject, pmt: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject) {
+ const _fv = fv ?? NumberValueObject.create(0);
+ const _type = type ?? NumberValueObject.create(0);
+
+ const maxRowLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getRowCount() : 1,
+ pmt.isArray() ? (pmt as ArrayValueObject).getRowCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getRowCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getRowCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getColumnCount() : 1,
+ pmt.isArray() ? (pmt as ArrayValueObject).getColumnCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getColumnCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getColumnCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const rateArray = expandArrayValueObject(maxRowLength, maxColumnLength, rate, ErrorValueObject.create(ErrorType.NA));
+ const pmtArray = expandArrayValueObject(maxRowLength, maxColumnLength, pmt, ErrorValueObject.create(ErrorType.NA));
+ const pvArray = expandArrayValueObject(maxRowLength, maxColumnLength, pv, ErrorValueObject.create(ErrorType.NA));
+ const fvArray = expandArrayValueObject(maxRowLength, maxColumnLength, _fv, ErrorValueObject.create(ErrorType.NA));
+ const typeArray = expandArrayValueObject(maxRowLength, maxColumnLength, _type, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = rateArray.map((rateObject, rowIndex, columnIndex) => {
+ const pmtObject = pmtArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const pvObject = pvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const fvObject = fvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const typeObject = typeArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(rateObject, pmtObject, pvObject, fvObject, typeObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_rateObject, _pmtObject, _pvObject, _fvObject, _typeObject] = variants as BaseValueObject[];
+
+ const rateValue = +_rateObject.getValue();
+ const pmtValue = +_pmtObject.getValue();
+ const pvValue = +_pvObject.getValue();
+ const fvValue = +_fvObject.getValue();
+ let typeValue = +_typeObject.getValue();
+ typeValue = typeValue ? 1 : 0;
+
+ if (rateValue === 0 && pmtValue === 0) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ let result;
+
+ if (rateValue === 0) {
+ result = -(pvValue + fvValue) / pmtValue;
+ } else {
+ const num = pmtValue * (1 + rateValue * typeValue) - fvValue * rateValue;
+ const den = pvValue * rateValue + pmtValue * (1 + rateValue * typeValue);
+
+ result = Math.log(num / den) / Math.log(1 + rateValue);
+ }
+
+ if (Number.isNaN(result) || !Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return NumberValueObject.create(result);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/pmt/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/pmt/__tests__/index.spec.ts
new file mode 100644
index 0000000000..0737b6a340
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/pmt/__tests__/index.spec.ts
@@ -0,0 +1,120 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Pmt } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test pmt function', () => {
+ const testFunction = new Pmt(FUNCTION_NAMES_FINANCIAL.PMT);
+
+ describe('Pmt', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.08 / 12);
+ const nper = NumberValueObject.create(10);
+ const pv = NumberValueObject.create(100000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(-10370.320893591643);
+
+ const type2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(rate, nper, pv, fv, type2);
+ expect(result2.getValue()).toStrictEqual(-10301.643271779778);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const nper = NumberValueObject.create(10);
+ const pv = NumberValueObject.create(100000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = BooleanValueObject.create(true);
+ const nper = NumberValueObject.create(10);
+ const pv = NumberValueObject.create(100000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(-100097.75171065493);
+ });
+
+ it('Value is blank cell', () => {
+ const rate = NullValueObject.create();
+ const nper = NumberValueObject.create(10);
+ const pv = NumberValueObject.create(100000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(-10000);
+ });
+
+ it('Value is normal string', () => {
+ const rate = StringValueObject.create('test');
+ const nper = NumberValueObject.create(10);
+ const pv = NumberValueObject.create(100000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const rate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['test', 0.06, false],
+ [true, null, ErrorType.NAME],
+ [-22, '1.23', 100],
+ ]),
+ rowCount: 3,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const nper = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, -200, false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 4,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const pv = NumberValueObject.create(100000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pv, fv, type);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, 0.05211730735859072, ErrorType.NUM, ErrorType.NA],
+ [-200000, 500, ErrorType.NAME, ErrorType.NA],
+ [ErrorType.NUM, 2.684927120963371e-65, ErrorType.NUM, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/pmt/index.ts b/packages/engine-formula/src/functions/financial/pmt/index.ts
new file mode 100644
index 0000000000..f15e987afe
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/pmt/index.ts
@@ -0,0 +1,101 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import { calculatePMT } from '../../../basics/financial';
+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';
+
+export class Pmt extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 5;
+
+ override calculate(rate: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject) {
+ const _fv = fv ?? NumberValueObject.create(0);
+ const _type = type ?? NumberValueObject.create(0);
+
+ const maxRowLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getRowCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getRowCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getRowCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getRowCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getColumnCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getColumnCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getColumnCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getColumnCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const rateArray = expandArrayValueObject(maxRowLength, maxColumnLength, rate, ErrorValueObject.create(ErrorType.NA));
+ const nperArray = expandArrayValueObject(maxRowLength, maxColumnLength, nper, ErrorValueObject.create(ErrorType.NA));
+ const pvArray = expandArrayValueObject(maxRowLength, maxColumnLength, pv, ErrorValueObject.create(ErrorType.NA));
+ const fvArray = expandArrayValueObject(maxRowLength, maxColumnLength, _fv, ErrorValueObject.create(ErrorType.NA));
+ const typeArray = expandArrayValueObject(maxRowLength, maxColumnLength, _type, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = rateArray.map((rateObject, rowIndex, columnIndex) => {
+ const nperObject = nperArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const pvObject = pvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const fvObject = fvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const typeObject = typeArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(rateObject, nperObject, pvObject, fvObject, typeObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_rateObject, _nperObject, _pvObject, _fvObject, _typeObject] = variants as BaseValueObject[];
+
+ const rateValue = +_rateObject.getValue();
+ const nperValue = +_nperObject.getValue();
+ const pvValue = +_pvObject.getValue();
+ const fvValue = +_fvObject.getValue();
+ const typeValue = +_typeObject.getValue();
+
+ if (rateValue <= -1) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = calculatePMT(rateValue, nperValue, pvValue, fvValue, typeValue ? 1 : 0);
+
+ if (Number.isNaN(result) || !Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ } else {
+ return NumberValueObject.create(result);
+ }
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/ppmt/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/ppmt/__tests__/index.spec.ts
new file mode 100644
index 0000000000..a8b0236a45
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/ppmt/__tests__/index.spec.ts
@@ -0,0 +1,140 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Ppmt } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test ppmt function', () => {
+ const testFunction = new Ppmt(FUNCTION_NAMES_FINANCIAL.PPMT);
+
+ describe('Ppmt', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.1 / 12);
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(-1914.7083088403392);
+
+ const type2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(rate, per, nper, pv, fv, type2);
+ expect(result2.getValue()).toStrictEqual(-2560.041298023477);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = BooleanValueObject.create(true);
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(-0.0000011641532182693481);
+ });
+
+ it('Value is blank cell', () => {
+ const rate = NullValueObject.create();
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(-2222.222222222222);
+ });
+
+ it('Value is normal string', () => {
+ const rate = StringValueObject.create('test');
+ const per = NumberValueObject.create(1);
+ const nper = NumberValueObject.create(3 * 12);
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const rate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['test', 0.06, false],
+ [true, null, ErrorType.NAME],
+ [-22, '1.23', 100],
+ ]),
+ rowCount: 3,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const per = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, 2, false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 4,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const nper = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ [10],
+ [false],
+ [null],
+ ]),
+ rowCount: 4,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const pv = NumberValueObject.create(80000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, per, nper, pv, fv, type);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, ErrorType.NUM, ErrorType.NUM, ErrorType.NA],
+ [-78.2013685239508, -8000, ErrorType.NAME, ErrorType.NA],
+ [ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, ErrorType.NA],
+ [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/ppmt/index.ts b/packages/engine-formula/src/functions/financial/ppmt/index.ts
new file mode 100644
index 0000000000..fc89b032ac
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/ppmt/index.ts
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { calculateIPMT, calculatePMT } from '../../../basics/financial';
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';
+
+export class Ppmt extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 6;
+
+ override calculate(rate: BaseValueObject, per: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject) {
+ const _fv = fv ?? NumberValueObject.create(0);
+ const _type = type ?? NumberValueObject.create(0);
+
+ const maxRowLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getRowCount() : 1,
+ per.isArray() ? (per as ArrayValueObject).getRowCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getRowCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getRowCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getRowCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getColumnCount() : 1,
+ per.isArray() ? (per as ArrayValueObject).getColumnCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getColumnCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getColumnCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getColumnCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const rateArray = expandArrayValueObject(maxRowLength, maxColumnLength, rate, ErrorValueObject.create(ErrorType.NA));
+ const perArray = expandArrayValueObject(maxRowLength, maxColumnLength, per, ErrorValueObject.create(ErrorType.NA));
+ const nperArray = expandArrayValueObject(maxRowLength, maxColumnLength, nper, ErrorValueObject.create(ErrorType.NA));
+ const pvArray = expandArrayValueObject(maxRowLength, maxColumnLength, pv, ErrorValueObject.create(ErrorType.NA));
+ const fvArray = expandArrayValueObject(maxRowLength, maxColumnLength, _fv, ErrorValueObject.create(ErrorType.NA));
+ const typeArray = expandArrayValueObject(maxRowLength, maxColumnLength, _type, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = rateArray.map((rateObject, rowIndex, columnIndex) => {
+ const perObject = perArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const nperObject = nperArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const pvObject = pvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const fvObject = fvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const typeObject = typeArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(rateObject, perObject, nperObject, pvObject, fvObject, typeObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_rateObject, _perObject, _nperObject, _pvObject, _fvObject, _typeObject] = variants as BaseValueObject[];
+
+ const rateValue = +_rateObject.getValue();
+ const perValue = +_perObject.getValue();
+ const nperValue = +_nperObject.getValue();
+ const pvValue = +_pvObject.getValue();
+ const fvValue = +_fvObject.getValue();
+ const typeValue = +_typeObject.getValue();
+
+ if (perValue < 1 || Math.floor(perValue) > Math.ceil(nperValue) || perValue - nperValue >= 1) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = calculatePMT(rateValue, nperValue, pvValue, fvValue, typeValue ? 1 : 0) - calculateIPMT(rateValue, perValue, nperValue, pvValue, fvValue, typeValue ? 1 : 0);
+
+ if (Number.isNaN(result) || !Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ } else {
+ return NumberValueObject.create(result);
+ }
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/pv/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/pv/__tests__/index.spec.ts
new file mode 100644
index 0000000000..da45d74c04
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/pv/__tests__/index.spec.ts
@@ -0,0 +1,134 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Pv } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test pv function', () => {
+ const testFunction = new Pv(FUNCTION_NAMES_FINANCIAL.NPER);
+
+ describe('Pv', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.08 / 12);
+ const nper = NumberValueObject.create(20 * 12);
+ const pmt = NumberValueObject.create(50000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pmt, fv, type);
+ expect(result.getValue()).toStrictEqual(-5977714.585118777);
+
+ const type2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(rate, nper, pmt, fv, type2);
+ expect(result2.getValue()).toStrictEqual(-6017566.015686235);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const nper = NumberValueObject.create(20 * 12);
+ const pmt = NumberValueObject.create(50000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pmt, fv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = BooleanValueObject.create(true);
+ const nper = NumberValueObject.create(20 * 12);
+ const pmt = NumberValueObject.create(50000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pmt, fv, type);
+ expect(result.getValue()).toStrictEqual(-50000);
+ });
+
+ it('Value is blank cell', () => {
+ const rate = NullValueObject.create();
+ const nper = NumberValueObject.create(20 * 12);
+ const pmt = NumberValueObject.create(50000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pmt, fv, type);
+ expect(result.getValue()).toStrictEqual(-12000000);
+ });
+
+ it('Value is normal string', () => {
+ const rate = StringValueObject.create('test');
+ const nper = NumberValueObject.create(20 * 12);
+ const pmt = NumberValueObject.create(50000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pmt, fv, type);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const rate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['test', 0.06, false],
+ [true, null, ErrorType.NAME],
+ [-22, '1.23', 100],
+ ]),
+ rowCount: 3,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const nper = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, -200, false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 4,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const pmt = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ [10],
+ [false],
+ [null],
+ ]),
+ rowCount: 4,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const result = testFunction.calculate(rate, nper, pmt, fv, type);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, 1918748.3979545343, 0, ErrorType.NA],
+ [-5, 2000, ErrorType.NAME, ErrorType.NA],
+ [0, 0, 0, ErrorType.NA],
+ [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/pv/index.ts b/packages/engine-formula/src/functions/financial/pv/index.ts
new file mode 100644
index 0000000000..ca702d89f7
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/pv/index.ts
@@ -0,0 +1,99 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';
+
+export class Pv extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 5;
+
+ override calculate(rate: BaseValueObject, nper: BaseValueObject, pmt: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject) {
+ const _fv = fv ?? NumberValueObject.create(0);
+ const _type = type ?? NumberValueObject.create(0);
+
+ const maxRowLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getRowCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getRowCount() : 1,
+ pmt.isArray() ? (pmt as ArrayValueObject).getRowCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getRowCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getColumnCount() : 1,
+ nper.isArray() ? (nper as ArrayValueObject).getColumnCount() : 1,
+ pmt.isArray() ? (pmt as ArrayValueObject).getColumnCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getColumnCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const rateArray = expandArrayValueObject(maxRowLength, maxColumnLength, rate, ErrorValueObject.create(ErrorType.NA));
+ const nperArray = expandArrayValueObject(maxRowLength, maxColumnLength, nper, ErrorValueObject.create(ErrorType.NA));
+ const pmtArray = expandArrayValueObject(maxRowLength, maxColumnLength, pmt, ErrorValueObject.create(ErrorType.NA));
+ const fvArray = expandArrayValueObject(maxRowLength, maxColumnLength, _fv, ErrorValueObject.create(ErrorType.NA));
+ const typeArray = expandArrayValueObject(maxRowLength, maxColumnLength, _type, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = rateArray.map((rateObject, rowIndex, columnIndex) => {
+ const nperObject = nperArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const pmtObject = pmtArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const fvObject = fvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const typeObject = typeArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(rateObject, nperObject, pmtObject, fvObject, typeObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_rateObject, _nperObject, _pmtObject, _fvObject, _typeObject] = variants as BaseValueObject[];
+
+ const rateValue = +_rateObject.getValue();
+ const nperValue = +_nperObject.getValue();
+ const pmtValue = +_pmtObject.getValue();
+ const fvValue = +_fvObject.getValue();
+ let typeValue = +_typeObject.getValue();
+ typeValue = typeValue ? 1 : 0;
+
+ const result = rateValue === 0
+ ? -pmtValue * nperValue - fvValue
+ : (((1 - (1 + rateValue) ** nperValue) / rateValue) * pmtValue * (1 + rateValue * typeValue) - fvValue) / (1 + rateValue) ** nperValue;
+
+ if (Number.isNaN(result) || !Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ } else {
+ return NumberValueObject.create(result);
+ }
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/rate/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/rate/__tests__/index.spec.ts
new file mode 100644
index 0000000000..b5ae8b6da1
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/rate/__tests__/index.spec.ts
@@ -0,0 +1,140 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Rate } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test rate function', () => {
+ const testFunction = new Rate(FUNCTION_NAMES_FINANCIAL.RATE);
+
+ describe('Rate', () => {
+ it('Value is normal', () => {
+ const nper = NumberValueObject.create(4 * 12);
+ const pmt = NumberValueObject.create(-200);
+ const pv = NumberValueObject.create(100000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(nper, pmt, pv, fv, type, guess);
+ expect(result.getValue()).toStrictEqual(-0.0726317700766071);
+
+ const type2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(nper, pmt, pv, fv, type2, guess);
+ expect(result2.getValue()).toStrictEqual(-0.07459013341097893);
+ });
+
+ it('Value is error', () => {
+ const nper = ErrorValueObject.create(ErrorType.NAME);
+ const pmt = NumberValueObject.create(-200);
+ const pv = NumberValueObject.create(100000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(nper, pmt, pv, fv, type, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const nper = BooleanValueObject.create(true);
+ const pmt = NumberValueObject.create(-200);
+ const pv = NumberValueObject.create(100000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(nper, pmt, pv, fv, type, guess);
+ expect(result.getValue()).toStrictEqual(-0.9980000000000001);
+ });
+
+ it('Value is blank cell', () => {
+ const nper = NullValueObject.create();
+ const pmt = NumberValueObject.create(-200);
+ const pv = NumberValueObject.create(100000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(nper, pmt, pv, fv, type, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is normal string', () => {
+ const nper = StringValueObject.create('test');
+ const pmt = NumberValueObject.create(-200);
+ const pv = NumberValueObject.create(100000);
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(nper, pmt, pv, fv, type, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const nper = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['test', 0.06, false],
+ [true, null, ErrorType.NAME],
+ [-22, '1.23', 100],
+ ]),
+ rowCount: 3,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const pmt = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, -200, false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 4,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const pv = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ [10],
+ [false],
+ [null],
+ ]),
+ rowCount: 4,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const fv = NumberValueObject.create(0);
+ const type = NumberValueObject.create(0);
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(nper, pmt, pv, fv, type, guess);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, 39.93118175604701, ErrorType.NUM, ErrorType.NA],
+ [ErrorType.NUM, ErrorType.NUM, ErrorType.NAME, ErrorType.NA],
+ [ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, ErrorType.NA],
+ [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/rate/index.ts b/packages/engine-formula/src/functions/financial/rate/index.ts
new file mode 100644
index 0000000000..48e8526002
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/rate/index.ts
@@ -0,0 +1,151 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';
+
+export class Rate extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 6;
+
+ override calculate(nper: BaseValueObject, pmt: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject, guess?: BaseValueObject) {
+ const _fv = fv ?? NumberValueObject.create(0);
+ const _type = type ?? NumberValueObject.create(0);
+ const _guess = guess ?? NumberValueObject.create(0.1);
+
+ const maxRowLength = Math.max(
+ nper.isArray() ? (nper as ArrayValueObject).getRowCount() : 1,
+ pmt.isArray() ? (pmt as ArrayValueObject).getRowCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getRowCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getRowCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getRowCount() : 1,
+ _guess.isArray() ? (_guess as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ nper.isArray() ? (nper as ArrayValueObject).getColumnCount() : 1,
+ pmt.isArray() ? (pmt as ArrayValueObject).getColumnCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getColumnCount() : 1,
+ _fv.isArray() ? (_fv as ArrayValueObject).getColumnCount() : 1,
+ _type.isArray() ? (_type as ArrayValueObject).getColumnCount() : 1,
+ _guess.isArray() ? (_guess as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const nperArray = expandArrayValueObject(maxRowLength, maxColumnLength, nper, ErrorValueObject.create(ErrorType.NA));
+ const pmtArray = expandArrayValueObject(maxRowLength, maxColumnLength, pmt, ErrorValueObject.create(ErrorType.NA));
+ const pvArray = expandArrayValueObject(maxRowLength, maxColumnLength, pv, ErrorValueObject.create(ErrorType.NA));
+ const fvArray = expandArrayValueObject(maxRowLength, maxColumnLength, _fv, ErrorValueObject.create(ErrorType.NA));
+ const typeArray = expandArrayValueObject(maxRowLength, maxColumnLength, _type, ErrorValueObject.create(ErrorType.NA));
+ const guessArray = expandArrayValueObject(maxRowLength, maxColumnLength, _guess, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = nperArray.map((nperObject, rowIndex, columnIndex) => {
+ const pmtObject = pmtArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const pvObject = pvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const fvObject = fvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const typeObject = typeArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const guessObject = guessArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(nperObject, pmtObject, pvObject, fvObject, typeObject, guessObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_nperObject, _pmtObject, _pvObject, _fvObject, _typeObject, _guessObject] = variants as BaseValueObject[];
+
+ const nperValue = +_nperObject.getValue();
+ const pmtValue = +_pmtObject.getValue();
+ const pvValue = +_pvObject.getValue();
+ const fvValue = +_fvObject.getValue();
+ let typeValue = +_typeObject.getValue();
+ const guessValue = +_guessObject.getValue();
+
+ typeValue = typeValue ? 1 : 0;
+
+ if (nperValue <= 0 || pmtValue >= 0) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return this._getResult(nperValue, pmtValue, pvValue, fvValue, typeValue, guessValue, rowIndex, columnIndex);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+
+ private _getResult(
+ nperValue: number,
+ pmtValue: number,
+ pvValue: number,
+ fvValue: number,
+ typeValue: number,
+ guessValue: number,
+ rowIndex: number,
+ columnIndex: number
+ ): BaseValueObject {
+ const epsMax = 1e-10;
+ const iterMax = 20;
+
+ let result = guessValue;
+
+ for (let i = 0; i < iterMax; i++) {
+ if (result <= -1) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ let y, f;
+
+ if (Math.abs(result) < epsMax) {
+ y = pvValue * (1 + nperValue * result) + pmtValue * (1 + result * typeValue) * nperValue + fvValue;
+ } else {
+ f = (1 + result) ** nperValue;
+ y = pvValue * f + pmtValue * (1 / result + typeValue) * (f - 1) + fvValue;
+ }
+
+ if (Math.abs(y) < epsMax) {
+ break;
+ }
+
+ let dy;
+
+ if (Math.abs(result) < epsMax) {
+ dy = pvValue * nperValue + pmtValue * typeValue * nperValue;
+ } else {
+ f = (1 + result) ** nperValue;
+ const df = nperValue * (1 + result) ** (nperValue - 1);
+ dy = pvValue * df + pmtValue * (1 / result + typeValue) * df + pmtValue * (-1 / (result * result)) * (f - 1);
+ }
+
+ result -= y / dy;
+ }
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '0%');
+ } else {
+ return NumberValueObject.create(result);
+ }
+ }
+}
diff --git a/packages/engine-formula/src/functions/logical/ifs/index.ts b/packages/engine-formula/src/functions/logical/ifs/index.ts
index 6884b06e99..248d4e12d4 100644
--- a/packages/engine-formula/src/functions/logical/ifs/index.ts
+++ b/packages/engine-formula/src/functions/logical/ifs/index.ts
@@ -38,24 +38,6 @@ export class Ifs extends BaseFunction {
}
}
- if (!params.some((param) => param.isArray())) {
- // Handle non-array inputs
- for (let i = 0; i < params.length; i += 2) {
- const condition = params[i];
- const result = params[i + 1];
-
- if (condition.isNull()) {
- continue;
- }
-
- const conditionValue = condition.getValue();
- if (conditionValue) {
- return result.isNull() ? ErrorValueObject.create(ErrorType.NA) : result;
- }
- }
- return ErrorValueObject.create(ErrorType.NA);
- }
-
// Determine max row and column length
const maxRowLength = Math.max(
...params.map((param) => (param.isArray() ? (param as ArrayValueObject).getRowCount() : 1))
@@ -69,7 +51,7 @@ export class Ifs extends BaseFunction {
expandArrayValueObject(maxRowLength, maxColumnLength, param, ErrorValueObject.create(ErrorType.NA))
);
- return expandedParams[0].map((_, rowIndex, columnIndex) => {
+ const resultArray = expandedParams[0].map((_, rowIndex, columnIndex) => {
for (let i = 0; i < expandedParams.length; i += 2) {
const condition = expandedParams[i].get(rowIndex, columnIndex) || NullValueObject.create();
const result = expandedParams[i + 1].get(rowIndex, columnIndex) || NullValueObject.create();
@@ -83,11 +65,31 @@ export class Ifs extends BaseFunction {
}
const conditionValue = condition.getValue();
- if (conditionValue) {
+
+ if (condition.isString()) {
+ if (`${conditionValue}`.toLocaleUpperCase() === 'TRUE') {
+ return result;
+ }
+
+ if (`${conditionValue}`.toLocaleUpperCase() === 'FALSE') {
+ continue;
+ }
+
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (+conditionValue) {
return result.isNull() ? ErrorValueObject.create(ErrorType.NA) : result;
}
}
+
return ErrorValueObject.create(ErrorType.NA);
});
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
}
}
diff --git a/packages/engine-formula/src/functions/logical/not/__tests__/index.spec.ts b/packages/engine-formula/src/functions/logical/not/__tests__/index.spec.ts
index a637028564..f9e2b3e715 100644
--- a/packages/engine-formula/src/functions/logical/not/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/logical/not/__tests__/index.spec.ts
@@ -47,7 +47,7 @@ describe('Test not function', () => {
it('logical null', () => {
const logical = NullValueObject.create();
const result = textFunction.calculate(logical);
- expect(result.getValue()).toBe(ErrorType.VALUE);
+ expect(result.getValue()).toBe(true);
});
it('logical true', () => {
diff --git a/packages/engine-formula/src/functions/logical/not/index.ts b/packages/engine-formula/src/functions/logical/not/index.ts
index bb0a825d4d..5cb7b8d132 100644
--- a/packages/engine-formula/src/functions/logical/not/index.ts
+++ b/packages/engine-formula/src/functions/logical/not/index.ts
@@ -15,7 +15,6 @@
*/
import { ErrorType } from '../../../basics/error-type';
-import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
import { BaseFunction } from '../../base-function';
@@ -25,26 +24,25 @@ export class Not extends BaseFunction {
override maxParams = 1;
- override calculate(logicalValue: BaseValueObject) {
- if (logicalValue.isError()) {
- return logicalValue;
+ override calculate(logical: BaseValueObject) {
+ if (logical.isArray()) {
+ return logical.map((logicalObject) => this._handleSingleObject(logicalObject));
}
- if (logicalValue.isArray()) {
- const resultArray = (logicalValue as ArrayValueObject).map((value) => {
- if (value?.isError()) {
- return value;
- } else if (value?.isBoolean() || value?.isNumber()) {
- return BooleanValueObject.create(!value.getValue());
- } else {
- return ErrorValueObject.create(ErrorType.VALUE);
- }
- });
- return resultArray;
- } else if (logicalValue.isBoolean() || logicalValue.isNumber()) {
- return BooleanValueObject.create(!logicalValue.getValue());
- } else {
+ return this._handleSingleObject(logical);
+ }
+
+ private _handleSingleObject(logical: BaseValueObject) {
+ if (logical.isError()) {
+ return logical;
+ }
+
+ const logicalValue = +logical.getValue();
+
+ if (Number.isNaN(logicalValue)) {
return ErrorValueObject.create(ErrorType.VALUE);
}
+
+ return BooleanValueObject.create(!logicalValue);
}
}
diff --git a/packages/engine-formula/src/functions/logical/switch/index.ts b/packages/engine-formula/src/functions/logical/switch/index.ts
index 1cacb40717..17fc916089 100644
--- a/packages/engine-formula/src/functions/logical/switch/index.ts
+++ b/packages/engine-formula/src/functions/logical/switch/index.ts
@@ -52,7 +52,7 @@ export class Switch extends BaseFunction {
return switchValue;
}
- if (expression.getValue() === switchValue.getValue()) {
+ if (`${expression.getValue()}`.toLocaleLowerCase() === `${switchValue.getValue()}`.toLocaleLowerCase()) {
return resultValue.isNull() ? ErrorValueObject.create(ErrorType.NA) : resultValue;
}
}
@@ -92,7 +92,7 @@ export class Switch extends BaseFunction {
return switchValue.isError() ? switchValue : expValue;
}
- if (expValue.getValue() === switchValue.getValue()) {
+ if (`${expValue.getValue()}`.toLocaleLowerCase() === `${switchValue.getValue()}`.toLocaleLowerCase()) {
return resultValue.isNull() ? ErrorValueObject.create(ErrorType.NA) : resultValue;
}
}
diff --git a/packages/engine-formula/src/functions/statistical/countif/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/countif/__tests__/index.spec.ts
index ecbdfe5572..b6cb49eab9 100644
--- a/packages/engine-formula/src/functions/statistical/countif/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/statistical/countif/__tests__/index.spec.ts
@@ -133,7 +133,7 @@ describe('Test countif function', () => {
const criteria = ArrayValueObject.create({
calculateValueList: transformToValueObject([
- ['=1', '= ', '=1.23', '=true', '=false', '='],
+ ['=1', '= ', '=1.23', '=true', '=false', '=0'],
['=0', '=100', '=2.34', '=test', '=-3', ErrorType.NAME],
]),
rowCount: 2,
@@ -145,7 +145,10 @@ describe('Test countif function', () => {
});
const resultObject = testFunction.calculate(range, criteria);
- expect(transformToValue(resultObject.getArrayValue())).toStrictEqual([[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]);
+ expect(transformToValue(resultObject.getArrayValue())).toStrictEqual([
+ [1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1],
+ ]);
});
});
});
diff --git a/packages/sheets-formula/src/locale/function-list/financial/en-US.ts b/packages/sheets-formula/src/locale/function-list/financial/en-US.ts
index 4885b0fac5..d1256e2121 100644
--- a/packages/sheets-formula/src/locale/function-list/financial/en-US.ts
+++ b/packages/sheets-formula/src/locale/function-list/financial/en-US.ts
@@ -25,8 +25,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ issue: { name: 'issue', detail: "The security's issue date." },
+ firstInterest: { name: 'first_interest', detail: "The security's first interest date." },
+ settlement: { name: 'settlement', detail: "The security's maturity date." },
+ rate: { name: 'rate', detail: "The security's annual coupon rate." },
+ par: { name: 'par', detail: "The security's par value." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
+ calcMethod: { name: 'calc_method', detail: 'Is a logical value: interest accrues from the issue date = TRUE or ignored; interest accrues from the last coupon payment date = FALSE.' },
},
},
ACCRINTM: {
@@ -39,8 +45,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ issue: { name: 'issue', detail: "The security's issue date." },
+ settlement: { name: 'settlement', detail: "The security's maturity date." },
+ rate: { name: 'rate', detail: "The security's annual coupon rate." },
+ par: { name: 'par', detail: "The security's par value." },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
AMORDEGRC: {
@@ -67,8 +76,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: 'cost', detail: 'The cost of the asset.' },
+ datePurchased: { name: 'date_purchased', detail: 'The date of the purchase of the asset.' },
+ firstPeriod: { name: 'first_period', detail: 'The date of the end of the first period.' },
+ salvage: { name: 'salvage', detail: 'The salvage value at the end of the life of the asset.' },
+ period: { name: 'period', detail: 'The period.' },
+ rate: { name: 'rate', detail: 'The rate of depreciation.' },
+ basis: { name: 'basis', detail: 'The year basis to be used.' },
},
},
COUPDAYBS: {
@@ -81,8 +95,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'settlement', detail: "The security's settlement date." },
+ maturity: { name: 'maturity', detail: "The security's maturity date." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
COUPDAYS: {
@@ -95,8 +111,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'settlement', detail: "The security's settlement date." },
+ maturity: { name: 'maturity', detail: "The security's maturity date." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
COUPDAYSNC: {
@@ -109,8 +127,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'settlement', detail: "The security's settlement date." },
+ maturity: { name: 'maturity', detail: "The security's maturity date." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
COUPNCD: {
@@ -123,8 +143,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'settlement', detail: "The security's settlement date." },
+ maturity: { name: 'maturity', detail: "The security's maturity date." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
COUPNUM: {
@@ -137,8 +159,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'settlement', detail: "The security's settlement date." },
+ maturity: { name: 'maturity', detail: "The security's maturity date." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
COUPPCD: {
@@ -151,8 +175,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'settlement', detail: "The security's settlement date." },
+ maturity: { name: 'maturity', detail: "The security's maturity date." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
CUMIPMT: {
@@ -165,8 +191,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'The interest rate.' },
+ nper: { name: 'nper', detail: 'The total number of payment periods.' },
+ pv: { name: 'pv', detail: 'The present value.' },
+ startPeriod: { name: 'start_period', detail: 'The first period in the calculation. Payment periods are numbered beginning with 1.' },
+ endPeriod: { name: 'end_period', detail: 'The last period in the calculation.' },
+ type: { name: 'type', detail: 'The timing of the payment.' },
},
},
CUMPRINC: {
@@ -179,8 +209,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'The interest rate.' },
+ nper: { name: 'nper', detail: 'The total number of payment periods.' },
+ pv: { name: 'pv', detail: 'The present value.' },
+ startPeriod: { name: 'start_period', detail: 'The first period in the calculation. Payment periods are numbered beginning with 1.' },
+ endPeriod: { name: 'end_period', detail: 'The last period in the calculation.' },
+ type: { name: 'type', detail: 'The timing of the payment.' },
},
},
DB: {
@@ -193,8 +227,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: 'cost', detail: 'The initial cost of the asset.' },
+ salvage: { name: 'salvage', detail: 'The value at the end of the depreciation (sometimes called the salvage value of the asset).' },
+ life: { name: 'life', detail: 'The number of periods over which the asset is being depreciated (sometimes called the useful life of the asset).' },
+ period: { name: 'period', detail: 'The period for which you want to calculate the depreciation.' },
+ month: { name: 'month', detail: 'The number of months in the first year. If month is omitted, it is assumed to be 12.' },
},
},
DDB: {
@@ -207,8 +244,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: 'cost', detail: 'The initial cost of the asset.' },
+ salvage: { name: 'salvage', detail: 'The value at the end of the depreciation (sometimes called the salvage value of the asset).' },
+ life: { name: 'life', detail: 'The number of periods over which the asset is being depreciated (sometimes called the useful life of the asset).' },
+ period: { name: 'period', detail: 'The period for which you want to calculate the depreciation.' },
+ factor: { name: 'factor', detail: 'The rate at which the balance declines. If factor is omitted, it is assumed to be 2 (the double-declining balance method).' },
},
},
DISC: {
@@ -221,8 +261,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'settlement', detail: "The security's settlement date." },
+ maturity: { name: 'maturity', detail: "The security's maturity date." },
+ pr: { name: 'pr', detail: "The security's price per $100 face value." },
+ redemption: { name: 'redemption', detail: "The security's redemption value per $100 face value." },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
DOLLARDE: {
@@ -235,8 +278,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ fractionalDollar: { name: 'fractional_dollar', detail: 'A number expressed as an integer part and a fraction part, separated by a decimal symbol.' },
+ fraction: { name: 'fraction', detail: 'The integer to use in the denominator of the fraction.' },
},
},
DOLLARFR: {
@@ -249,8 +292,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ decimalDollar: { name: 'decimal_dollar', detail: 'A decimal number.' },
+ fraction: { name: 'fraction', detail: 'The integer to use in the denominator of the fraction.' },
},
},
DURATION: {
@@ -277,8 +320,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nominalRate: { name: 'nominal_rate', detail: 'The nominal interest rate.' },
+ npery: { name: 'npery', detail: 'The number of compounding periods per year.' },
},
},
FV: {
@@ -291,8 +334,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'The interest rate per period.' },
+ nper: { name: 'nper', detail: 'The total number of payment periods in an annuity.' },
+ pmt: { name: 'pmt', detail: 'The payment made each period; it cannot change over the life of the annuity.' },
+ pv: { name: 'pv', detail: 'The present value, or the lump-sum amount that a series of future payments is worth right now.' },
+ type: { name: 'type', detail: 'The number 0 or 1 and indicates when payments are due.' },
},
},
FVSCHEDULE: {
@@ -305,8 +351,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ principal: { name: 'principal', detail: 'The present value.' },
+ schedule: { name: 'schedule', detail: 'An array of interest rates to apply.' },
},
},
INTRATE: {
@@ -319,8 +365,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'settlement', detail: "The security's settlement date." },
+ maturity: { name: 'maturity', detail: "The security's maturity date." },
+ investment: { name: 'investment', detail: 'The amount invested in the security.' },
+ redemption: { name: 'redemption', detail: 'The amount to be received at maturity.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
IPMT: {
@@ -333,8 +382,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'The interest rate per period.' },
+ per: { name: 'per', detail: 'The period for which you want to find the interest and must be in the range 1 to nper.' },
+ nper: { name: 'nper', detail: 'The total number of payment periods in an annuity.' },
+ pv: { name: 'pv', detail: 'The present value, or the lump-sum amount that a series of future payments is worth right now.' },
+ fv: { name: 'fv', detail: 'The future value, or a cash balance you want to attain after the last payment is made.' },
+ type: { name: 'type', detail: 'The number 0 or 1 and indicates when payments are due.' },
},
},
IRR: {
@@ -361,8 +414,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'The interest rate for the investment.' },
+ per: { name: 'per', detail: 'The period for which you want to find the interest, and must be between 1 and Nper.' },
+ nper: { name: 'nper', detail: 'The total number of payment periods for the investment.' },
+ pv: { name: 'pv', detail: 'The present value of the investment. For a loan, Pv is the loan amount.' },
},
},
MDURATION: {
@@ -403,8 +458,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ effectRate: { name: 'effect_rate', detail: 'The effective interest rate.' },
+ npery: { name: 'npery', detail: 'The number of compounding periods per year.' },
},
},
NPER: {
@@ -417,8 +472,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'The interest rate per period.' },
+ pmt: { name: 'pmt', detail: 'The payment made each period; it cannot change over the life of the annuity.' },
+ pv: { name: 'pv', detail: 'The present value, or the lump-sum amount that a series of future payments is worth right now.' },
+ fv: { name: 'fv', detail: 'The future value, or a cash balance you want to attain after the last payment is made.' },
+ type: { name: 'type', detail: 'The number 0 or 1 and indicates when payments are due.' },
},
},
NPV: {
@@ -515,8 +573,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'The interest rate per period.' },
+ nper: { name: 'nper', detail: 'The total number of payment periods in an annuity.' },
+ pv: { name: 'pv', detail: 'The present value, or the lump-sum amount that a series of future payments is worth right now.' },
+ fv: { name: 'fv', detail: 'The future value, or a cash balance you want to attain after the last payment is made.' },
+ type: { name: 'type', detail: 'The number 0 or 1 and indicates when payments are due.' },
},
},
PPMT: {
@@ -529,8 +590,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'The interest rate per period.' },
+ per: { name: 'per', detail: 'The period for which you want to find the interest and must be in the range 1 to nper.' },
+ nper: { name: 'nper', detail: 'The total number of payment periods in an annuity.' },
+ pv: { name: 'pv', detail: 'The present value, or the lump-sum amount that a series of future payments is worth right now.' },
+ fv: { name: 'fv', detail: 'The future value, or a cash balance you want to attain after the last payment is made.' },
+ type: { name: 'type', detail: 'The number 0 or 1 and indicates when payments are due.' },
},
},
PRICE: {
@@ -585,8 +650,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'The interest rate per period.' },
+ nper: { name: 'nper', detail: 'The total number of payment periods in an annuity.' },
+ pmt: { name: 'pmt', detail: 'The payment made each period; it cannot change over the life of the annuity.' },
+ fv: { name: 'fv', detail: 'The future value, or a cash balance you want to attain after the last payment is made.' },
+ type: { name: 'type', detail: 'The number 0 or 1 and indicates when payments are due.' },
},
},
RATE: {
@@ -599,8 +667,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nper: { name: 'nper', detail: 'The total number of payment periods in an annuity.' },
+ pmt: { name: 'pmt', detail: 'The payment made each period; it cannot change over the life of the annuity.' },
+ pv: { name: 'pv', detail: 'The present value, or the lump-sum amount that a series of future payments is worth right now.' },
+ fv: { name: 'fv', detail: 'The future value, or a cash balance you want to attain after the last payment is made.' },
+ type: { name: 'type', detail: 'The number 0 or 1 and indicates when payments are due.' },
+ guess: { name: 'guess', detail: 'Your guess for what the rate will be.' },
},
},
RECEIVED: {
diff --git a/packages/sheets-formula/src/locale/function-list/financial/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/financial/ja-JP.ts
index 4ef53bd5b8..32b7bc01bf 100644
--- a/packages/sheets-formula/src/locale/function-list/financial/ja-JP.ts
+++ b/packages/sheets-formula/src/locale/function-list/financial/ja-JP.ts
@@ -25,8 +25,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ issue: { name: '発行日', detail: '証券の発行日を指定します。' },
+ firstInterest: { name: '初回利払日', detail: '証券の利息が最初に支払われる日付を指定します。' },
+ settlement: { name: '受渡日', detail: '証券の満期日を指定します。' },
+ rate: { name: '利率', detail: '証券の年利を指定します。' },
+ par: { name: '額面', detail: '証券の額面価格を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
+ calcMethod: { name: '計算方式', detail: '論理値です: 発行日からの未払い利息 = TRUE、または最後のクーポン支払日から計算 = FALSE。' },
},
},
ACCRINTM: {
@@ -39,8 +45,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ issue: { name: '発行日', detail: '証券の発行日を指定します。' },
+ settlement: { name: '受渡日', detail: '証券の満期日を指定します。' },
+ rate: { name: '利率', detail: '証券の年利を指定します。' },
+ par: { name: '額面', detail: '証券の額面価格を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
AMORDEGRC: {
@@ -67,8 +76,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '取得価額', detail: '資産を購入した時点での価格を指定します。' },
+ datePurchased: { name: '購入日', detail: '資産を購入した日付を指定します。' },
+ firstPeriod: { name: '開始期', detail: '最初の会計期が終了する日付を指定します。' },
+ salvage: { name: '残存価額', detail: '耐用年数が終了した時点での資産の価格を指定します。' },
+ period: { name: '期', detail: '会計期 (会計年度) を指定します。' },
+ rate: { name: '率', detail: '減価償却率を指定します。' },
+ basis: { name: '基準', detail: '1 年を何日として計算するかを表す数値を指定します。' },
},
},
COUPDAYBS: {
@@ -81,8 +95,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
COUPDAYS: {
@@ -95,8 +111,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
COUPDAYSNC: {
@@ -109,8 +127,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
COUPNCD: {
@@ -123,8 +143,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
COUPNUM: {
@@ -137,8 +159,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
COUPPCD: {
@@ -151,8 +175,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
CUMIPMT: {
@@ -165,8 +191,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '貸付期間を通じて一定の利率を指定します。' },
+ nper: { name: '期間内支払回数', detail: '貸付期間全体での支払回数の合計を指定します。' },
+ pv: { name: '現在価値', detail: '現在の貸付額、つまり将来行われる一連の支払いを、現時点で一括支払いした場合の合計金額を指定します。' },
+ startPeriod: { name: '開始期', detail: '計算の対象となる最初の期を指定します。 最初の期から順に、1 から始まる番号が割り当てられます。' },
+ endPeriod: { name: '終了期', detail: '計算の対象となる最後の期を指定します。' },
+ type: { name: '支払期日', detail: '支払いがいつ行われるかを、数値の 0 または 1 で指定します。' },
},
},
CUMPRINC: {
@@ -179,8 +209,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '貸付期間を通じて一定の利率を指定します。' },
+ nper: { name: '期間内支払回数', detail: '貸付期間全体での支払回数の合計を指定します。' },
+ pv: { name: '現在価値', detail: '現在の貸付額、つまり将来行われる一連の支払いを、現時点で一括支払いした場合の合計金額を指定します。' },
+ startPeriod: { name: '開始期', detail: '計算の対象となる最初の期を指定します。 最初の期から順に、1 から始まる番号が割り当てられます。' },
+ endPeriod: { name: '終了期', detail: '計算の対象となる最後の期を指定します。' },
+ type: { name: '支払期日', detail: '支払いがいつ行われるかを、数値の 0 または 1 で指定します。' },
},
},
DB: {
@@ -193,8 +227,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '取得価額', detail: '資産を購入した時点での価格を指定します。' },
+ salvage: { name: '残存価額', detail: '耐用年数が終了した時点での資産の価格 (資産の救済価額) を指定します。' },
+ life: { name: '耐用年数', detail: '資産を使用できる年数 (資産の寿命年数) を指定します。' },
+ period: { name: '期間', detail: '減価償却費を計算する期間を指定します。' },
+ month: { name: '月', detail: '資産を購入した期 (年度) の月数を指定します。 省略すると、12 を指定したと見なされます。' },
},
},
DDB: {
@@ -207,8 +244,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '取得価額', detail: '資産を購入した時点での価格を指定します。' },
+ salvage: { name: '残存価額', detail: '耐用年数が終了した時点での資産の価格 (資産の救済価額) を指定します。' },
+ life: { name: '耐用年数', detail: '資産を使用できる年数 (資産の寿命年数) を指定します。' },
+ period: { name: '期間', detail: '減価償却費を計算する期間を指定します。' },
+ factor: { name: '率', detail: '減価償却率を指定します。率を省略すると、2 を指定したと見なされ、倍額定率法で計算が行われます。' },
},
},
DISC: {
@@ -221,8 +261,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ pr: { name: '現在価値', detail: '額面 $100 に対する証券の価値を指定します。' },
+ redemption: { name: '償還価額', detail: '額面 $100 に対する証券の償還額を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
DOLLARDE: {
@@ -235,8 +278,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ fractionalDollar: { name: '分数表現', detail: '整数部と小数部を小数点で区切って表現した数値です。' },
+ fraction: { name: '分母', detail: '分数の分母となる整数を指定します。' },
},
},
DOLLARFR: {
@@ -249,8 +292,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ decimalDollar: { name: '小数値', detail: '小数で表された数値を指定します。' },
+ fraction: { name: '分母', detail: '分数の分母となる整数を指定します。' },
},
},
DURATION: {
@@ -277,8 +320,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nominalRate: { name: '名目利率', detail: '名目年利率を指定します。' },
+ npery: { name: '複利計算回数', detail: '1 年あたりの複利計算回数を指定します。' },
},
},
FV: {
@@ -291,8 +334,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '投資期間を通じて一定の利率を指定します。' },
+ nper: { name: '期間内支払回数', detail: '投資期間全体での支払回数の合計を指定します。' },
+ pmt: { name: '定期支払額', detail: '各期間に行われた支払い。それは年金の生活の中で変わることはできません' },
+ pv: { name: '現在価値', detail: '投資の現在価値、つまり将来行われる一連の支払いを、現時点で一括払いした場合の合計金額を指定します。' },
+ type: { name: '支払期日', detail: 'いつ支払いが行われるかを、数値の 0 または 1 で指定します。' },
},
},
FVSCHEDULE: {
@@ -305,8 +351,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ principal: { name: '元金', detail: '現在の貸付額、つまり将来行われる一連の支払いを、現時点で一括支払いした場合の合計金額を指定します。' },
+ schedule: { name: '利率配列', detail: '投資期間内の変動金利を配列として指定します。' },
},
},
INTRATE: {
@@ -319,8 +365,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ investment: { name: '投資額', detail: '証券への投資額を指定します。' },
+ redemption: { name: '償還価額', detail: '満期日における証券の償還額を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
IPMT: {
@@ -333,8 +382,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '投資期間を通じて一定の利率を指定します。' },
+ per: { name: '期', detail: '金利支払額を求める期を 1 ~ "期間" の範囲で指定します。' },
+ nper: { name: '期間', detail: '投資期間全体での支払回数の合計を指定します。' },
+ pv: { name: '現在価値', detail: '投資の現在価値、つまり将来行われる一連の支払いを、現時点で一括払いした場合の合計金額を指定します。' },
+ fv: { name: '将来価値', detail: '投資の将来価値、つまり最後の支払いを行った後に残る現金の収支を指定します。' },
+ type: { name: '支払期日', detail: 'いつ支払いが行われるかを、数値の 0 または 1 で指定します。' },
},
},
IRR: {
@@ -361,8 +414,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '投資の利率を指定します。' },
+ per: { name: '期', detail: '関心を見つける期間であり、1 から Nper の間である必要があります。' },
+ nper: { name: '期間', detail: '投資期間全体での支払回数の合計を指定します。' },
+ pv: { name: '現在価値', detail: '投資の現在価値を指定します。ローンの場合、Pv はローン金額です。' },
},
},
MDURATION: {
@@ -403,8 +458,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ effectRate: { name: '実効利率', detail: '実効年利率を指定します。' },
+ npery: { name: '複利計算回数', detail: '1 年あたりの複利計算回数を指定します。' },
},
},
NPER: {
@@ -417,8 +472,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '投資期間を通じて一定の利率を指定します。' },
+ pmt: { name: '定期支払額', detail: '各期間に行われた支払い。それは年金の生活の中で変わることはできません' },
+ pv: { name: '現在価値', detail: '投資の現在価値、つまり将来行われる一連の支払いを、現時点で一括払いした場合の合計金額を指定します。' },
+ fv: { name: '将来価値', detail: '投資の将来価値、つまり最後の支払いを行った後に残る現金の収支を指定します。' },
+ type: { name: '支払期日', detail: 'いつ支払いが行われるかを、数値の 0 または 1 で指定します。' },
},
},
NPV: {
@@ -515,8 +573,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '投資期間を通じて一定の利率を指定します。' },
+ nper: { name: '期間内支払回数', detail: '投資期間全体での支払回数の合計を指定します。' },
+ pv: { name: '現在価値', detail: '投資の現在価値、つまり将来行われる一連の支払いを、現時点で一括払いした場合の合計金額を指定します。' },
+ fv: { name: '将来価値', detail: '投資の将来価値、つまり最後の支払いを行った後に残る現金の収支を指定します。' },
+ type: { name: '支払期日', detail: 'いつ支払いが行われるかを、数値の 0 または 1 で指定します。' },
},
},
PPMT: {
@@ -529,8 +590,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '投資期間を通じて一定の利率を指定します。' },
+ per: { name: '期', detail: '金利支払額を求める期を 1 ~ "期間" の範囲で指定します。' },
+ nper: { name: '期間', detail: '投資期間全体での支払回数の合計を指定します。' },
+ pv: { name: '現在価値', detail: '投資の現在価値、つまり将来行われる一連の支払いを、現時点で一括払いした場合の合計金額を指定します。' },
+ fv: { name: '将来価値', detail: '投資の将来価値、つまり最後の支払いを行った後に残る現金の収支を指定します。' },
+ type: { name: '支払期日', detail: 'いつ支払いが行われるかを、数値の 0 または 1 で指定します。' },
},
},
PRICE: {
@@ -585,8 +650,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '投資期間を通じて一定の利率を指定します。' },
+ nper: { name: '期間内支払回数', detail: '投資期間全体での支払回数の合計を指定します。' },
+ pmt: { name: '定期支払額', detail: '各期間に行われた支払い。それは年金の生活の中で変わることはできません' },
+ fv: { name: '将来価値', detail: '投資の将来価値、つまり最後の支払いを行った後に残る現金の収支を指定します。' },
+ type: { name: '支払期日', detail: 'いつ支払いが行われるかを、数値の 0 または 1 で指定します。' },
},
},
RATE: {
@@ -599,8 +667,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nper: { name: '期間内支払回数', detail: '投資期間全体での支払回数の合計を指定します。' },
+ pmt: { name: '定期支払額', detail: '各期間に行われた支払い。それは年金の生活の中で変わることはできません' },
+ pv: { name: '現在価値', detail: '投資の現在価値、つまり将来行われる一連の支払いを、現時点で一括払いした場合の合計金額を指定します。' },
+ fv: { name: '将来価値', detail: '投資の将来価値、つまり最後の支払いを行った後に残る現金の収支を指定します。' },
+ type: { name: '支払期日', detail: 'いつ支払いが行われるかを、数値の 0 または 1 で指定します。' },
+ guess: { name: '推定値', detail: '利率がおよそどれくらいになるかを推定した値を指定します。' },
},
},
RECEIVED: {
diff --git a/packages/sheets-formula/src/locale/function-list/financial/vi-VN.ts b/packages/sheets-formula/src/locale/function-list/financial/vi-VN.ts
index 9e703c3aed..e891f0f212 100644
--- a/packages/sheets-formula/src/locale/function-list/financial/vi-VN.ts
+++ b/packages/sheets-formula/src/locale/function-list/financial/vi-VN.ts
@@ -25,8 +25,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ issue: { name: 'ngày phát hành', detail: 'Ngày phát hành chứng khoán.' },
+ firstInterest: { name: 'ngày tính lãi đầu tiên', detail: 'Ngày tính lãi đầu tiên của chứng khoán.' },
+ settlement: { name: 'ngày thanh toán', detail: 'Ngày thanh toán chứng khoán.' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất phiếu lãi hàng năm của chứng khoán.' },
+ par: { name: 'mệnh giá', detail: 'Mệnh giá của chứng khoán.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu lãi hàng năm.' },
+ basis: { name: 'điểm chuẩn', detail: 'Loại cơ sở đếm ngày sẽ dùng.' },
+ calcMethod: { name: 'phương pháp tính toán', detail: 'Là một giá trị logic: tiền lãi tích lũy từ ngày phát hành = TRUE hoặc bị bỏ qua; được tính từ ngày thanh toán phiếu lãi cuối cùng = FALSE.' },
},
},
ACCRINTM: {
@@ -39,8 +45,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ issue: { name: 'ngày phát hành', detail: 'Ngày phát hành chứng khoán.' },
+ settlement: { name: 'ngày thanh toán', detail: 'Ngày thanh toán chứng khoán.' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất phiếu lãi hàng năm của chứng khoán.' },
+ par: { name: 'mệnh giá', detail: 'Mệnh giá của chứng khoán.' },
+ basis: { name: 'điểm chuẩn', detail: 'Loại cơ sở đếm ngày sẽ dùng.' },
},
},
AMORDEGRC: {
@@ -67,8 +76,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: 'trị giá', detail: 'Chi phí của tài sản.' },
+ datePurchased: { name: 'ngày mua', detail: 'Ngày mua tài sản.' },
+ firstPeriod: { name: 'kỳ đầu tiên', detail: 'Ngày kết thúc của kỳ thứ nhất.' },
+ salvage: { name: 'giá trị còn lại', detail: 'Giá trị thu hồi khi kết thúc vòng đời của tài sản.' },
+ period: { name: 'kỳ', detail: 'Kỳ.' },
+ rate: { name: 'tỷ lệ khấu hao', detail: 'Tỷ lệ khấu hao.' },
+ basis: { name: 'điểm chuẩn', detail: 'Cơ sở năm được dùng.' },
},
},
COUPDAYBS: {
@@ -81,8 +95,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'ngày thanh toán', detail: 'Ngày thanh toán chứng khoán.' },
+ maturity: { name: 'ngày đáo hạn', detail: 'Ngày đáo hạn của chứng khoán.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu lãi hàng năm.' },
+ basis: { name: 'điểm chuẩn', detail: 'Cơ sở năm được dùng.' },
},
},
COUPDAYS: {
@@ -95,8 +111,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'ngày thanh toán', detail: 'Ngày thanh toán chứng khoán.' },
+ maturity: { name: 'ngày đáo hạn', detail: 'Ngày đáo hạn của chứng khoán.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu lãi hàng năm.' },
+ basis: { name: 'điểm chuẩn', detail: 'Cơ sở năm được dùng.' },
},
},
COUPDAYSNC: {
@@ -109,8 +127,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'ngày thanh toán', detail: 'Ngày thanh toán chứng khoán.' },
+ maturity: { name: 'ngày đáo hạn', detail: 'Ngày đáo hạn của chứng khoán.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu lãi hàng năm.' },
+ basis: { name: 'điểm chuẩn', detail: 'Cơ sở năm được dùng.' },
},
},
COUPNCD: {
@@ -123,8 +143,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'ngày thanh toán', detail: 'Ngày thanh toán chứng khoán.' },
+ maturity: { name: 'ngày đáo hạn', detail: 'Ngày đáo hạn của chứng khoán.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu lãi hàng năm.' },
+ basis: { name: 'điểm chuẩn', detail: 'Cơ sở năm được dùng.' },
},
},
COUPNUM: {
@@ -137,8 +159,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'ngày thanh toán', detail: 'Ngày thanh toán chứng khoán.' },
+ maturity: { name: 'ngày đáo hạn', detail: 'Ngày đáo hạn của chứng khoán.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu lãi hàng năm.' },
+ basis: { name: 'điểm chuẩn', detail: 'Cơ sở năm được dùng.' },
},
},
COUPPCD: {
@@ -151,8 +175,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'ngày thanh toán', detail: 'Ngày thanh toán chứng khoán.' },
+ maturity: { name: 'ngày đáo hạn', detail: 'Ngày đáo hạn của chứng khoán.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu lãi hàng năm.' },
+ basis: { name: 'điểm chuẩn', detail: 'Cơ sở năm được dùng.' },
},
},
CUMIPMT: {
@@ -165,8 +191,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất.' },
+ nper: { name: 'tổng số kỳ', detail: 'Tổng số kỳ thanh toán.' },
+ pv: { name: 'giá trị hiện tại', detail: 'Giá trị hiện tại.' },
+ startPeriod: { name: 'kỳ đầu tiên', detail: 'Kỳ đầu tiên trong tính toán này. Các kỳ thanh toán được đánh số bắt đầu từ 1.' },
+ endPeriod: { name: 'kỳ cuối cùng', detail: 'Kỳ cuối cùng trong tính toán này.' },
+ type: { name: 'loại', detail: 'Thời hạn thanh toán.' },
},
},
CUMPRINC: {
@@ -179,8 +209,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất.' },
+ nper: { name: 'tổng số kỳ', detail: 'Tổng số kỳ thanh toán.' },
+ pv: { name: 'giá trị hiện tại', detail: 'Giá trị hiện tại.' },
+ startPeriod: { name: 'kỳ đầu tiên', detail: 'Kỳ đầu tiên trong tính toán này. Các kỳ thanh toán được đánh số bắt đầu từ 1.' },
+ endPeriod: { name: 'kỳ cuối cùng', detail: 'Kỳ cuối cùng trong tính toán này.' },
+ type: { name: 'loại', detail: 'Thời hạn thanh toán.' },
},
},
DB: {
@@ -193,8 +227,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: 'trị giá', detail: 'Chi phí của tài sản.' },
+ salvage: { name: 'giá trị còn lại', detail: 'Giá trị khi kết thúc khấu hao (đôi khi được gọi là giá trị thu hồi của tài sản).' },
+ life: { name: 'tuổi thọ sử dụng', detail: 'Số thời gian khấu hao của một tài sản (đôi khi còn được gọi là thời gian sử dụng hữu ích của tài sản).' },
+ period: { name: 'kỳ', detail: 'Khoảng thời gian mà bạn muốn tính khấu hao.' },
+ month: { name: 'tháng', detail: 'Số tháng trong năm đầu tiên. Nếu tháng bị bỏ qua, giá trị của nó được giả định là 12.' },
},
},
DDB: {
@@ -207,8 +244,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: 'trị giá', detail: 'Chi phí của tài sản.' },
+ salvage: { name: 'giá trị còn lại', detail: 'Giá trị khi kết thúc khấu hao (đôi khi được gọi là giá trị thu hồi của tài sản).' },
+ life: { name: 'tuổi thọ sử dụng', detail: 'Số thời gian khấu hao của một tài sản (đôi khi còn được gọi là thời gian sử dụng hữu ích của tài sản).' },
+ period: { name: 'kỳ', detail: 'Khoảng thời gian mà bạn muốn tính khấu hao.' },
+ factor: { name: 'nhân tố', detail: 'Tỷ lệ suy giảm số dư. Nếu bỏ qua yếu tố ảnh hưởng thì giả định là 2 (phương pháp số dư giảm dần kép).' },
},
},
DISC: {
@@ -221,8 +261,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'ngày thanh toán', detail: 'Ngày thanh toán chứng khoán.' },
+ maturity: { name: 'ngày đáo hạn', detail: 'Ngày đáo hạn của chứng khoán.' },
+ pr: { name: 'giá', detail: 'Giá của một chứng khoán có thể bán được trên thị trường.' },
+ redemption: { name: 'giá thanh lý', detail: 'Giá trị thanh lý của chứng khoán có mệnh giá 100' },
+ basis: { name: 'điểm chuẩn', detail: 'Cơ sở năm được dùng.' },
},
},
DOLLARDE: {
@@ -235,8 +278,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ fractionalDollar: { name: 'phân số', detail: 'Một số được biểu thị dưới dạng phần nguyên và phần phân số, cách nhau bằng dấu thập phân.' },
+ fraction: { name: 'mẫu số', detail: 'Số nguyên dùng làm mẫu số của một phân số.' },
},
},
DOLLARFR: {
@@ -249,8 +292,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ decimalDollar: { name: 'số thập phân', detail: 'số thập phân.' },
+ fraction: { name: 'mẫu số', detail: 'Số nguyên dùng làm mẫu số của một phân số.' },
},
},
DURATION: {
@@ -277,8 +320,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nominalRate: { name: 'lãi suất danh nghĩa', detail: 'Lãi suất danh nghĩa.' },
+ npery: { name: 'số kỳ', detail: 'Số kỳ ghép lãi trong năm.' },
},
},
FV: {
@@ -291,8 +334,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất.' },
+ nper: { name: 'tổng số kỳ', detail: 'Tổng số kỳ thanh toán.' },
+ pmt: { name: 'số tiền', detail: 'Số tiền phải trả trong mỗi kỳ không thay đổi trong suốt thời hạn niên kim.' },
+ pv: { name: 'giá trị hiện tại', detail: 'Giá trị hiện tại.' },
+ type: { name: 'loại', detail: 'Số 0 hoặc 1, dùng để xác định thời điểm thanh toán của mỗi kỳ là đầu hay cuối kỳ.' },
},
},
FVSCHEDULE: {
@@ -305,8 +351,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ principal: { name: 'hiệu trưởng', detail: 'giá trị hiện tại.' },
+ schedule: { name: 'mảng lãi suất', detail: 'Mảng lãi suất áp dụng.' },
},
},
INTRATE: {
@@ -319,8 +365,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'ngày thanh toán', detail: 'Ngày thanh toán chứng khoán.' },
+ maturity: { name: 'ngày đáo hạn', detail: 'Ngày đáo hạn của chứng khoán.' },
+ investment: { name: 'số tiền đầu', detail: 'Số tiền đầu tư vào chứng khoán có thể bán được.' },
+ redemption: { name: 'giá thanh lý', detail: 'Giá trị trao đổi của chứng khoán khi đáo hạn.' },
+ basis: { name: 'điểm chuẩn', detail: 'Cơ sở năm được dùng.' },
},
},
IPMT: {
@@ -333,8 +382,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất theo từng thời kỳ.' },
+ per: { name: 'kỳ', detail: 'Số kỳ dùng để tính số tiền lãi phải nằm trong khoảng từ 1 đến nper.' },
+ nper: { name: 'tổng số kỳ', detail: 'Tổng số kỳ thanh toán.' },
+ pv: { name: 'giá trị hiện tại', detail: 'Giá trị hiện tại.' },
+ fv: { name: 'số dư tiền mặt', detail: 'Giá trị tương lai hoặc số dư tiền mặt mong muốn sau khi thực hiện khoản thanh toán cuối cùng.' },
+ type: { name: 'loại', detail: 'Số 0 hoặc 1, dùng để xác định thời điểm thanh toán của mỗi kỳ là đầu hay cuối kỳ.' },
},
},
IRR: {
@@ -361,8 +414,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất theo từng thời kỳ.' },
+ per: { name: 'kỳ', detail: 'Số kỳ dùng để tính số tiền lãi phải nằm trong khoảng từ 1 đến nper.' },
+ nper: { name: 'tổng số kỳ', detail: 'Tổng số kỳ thanh toán.' },
+ pv: { name: 'giá trị hiện tại', detail: 'Giá trị hiện tại.' },
},
},
MIRR: {
@@ -389,8 +444,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ effectRate: { name: 'lãi suất thực', detail: 'lãi suất thực.' },
+ npery: { name: 'số kỳ', detail: 'Số kỳ ghép lãi trong năm.' },
},
},
NPER: {
@@ -403,8 +458,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất theo từng thời kỳ.' },
+ pmt: { name: 'số tiền', detail: 'Số tiền phải trả trong mỗi kỳ không thay đổi trong suốt thời hạn niên kim.' },
+ pv: { name: 'giá trị hiện tại', detail: 'Giá trị hiện tại.' },
+ fv: { name: 'số dư tiền mặt', detail: 'Giá trị tương lai hoặc số dư tiền mặt mong muốn sau khi thực hiện khoản thanh toán cuối cùng.' },
+ type: { name: 'loại', detail: 'Số 0 hoặc 1, dùng để xác định thời điểm thanh toán của mỗi kỳ là đầu hay cuối kỳ.' },
},
},
NPV: {
@@ -487,8 +545,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất theo từng thời kỳ.' },
+ nper: { name: 'tổng số kỳ', detail: 'Tổng số kỳ thanh toán.' },
+ pv: { name: 'giá trị hiện tại', detail: 'Giá trị hiện tại.' },
+ fv: { name: 'số dư tiền mặt', detail: 'Giá trị tương lai hoặc số dư tiền mặt mong muốn sau khi thực hiện khoản thanh toán cuối cùng.' },
+ type: { name: 'loại', detail: 'Số 0 hoặc 1, dùng để xác định thời điểm thanh toán của mỗi kỳ là đầu hay cuối kỳ.' },
},
},
PPMT: {
@@ -501,8 +562,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất theo từng thời kỳ.' },
+ per: { name: 'kỳ', detail: 'Số kỳ dùng để tính số tiền lãi phải nằm trong khoảng từ 1 đến nper.' },
+ nper: { name: 'tổng số kỳ', detail: 'Tổng số kỳ thanh toán.' },
+ pv: { name: 'giá trị hiện tại', detail: 'Giá trị hiện tại.' },
+ fv: { name: 'số dư tiền mặt', detail: 'Giá trị tương lai hoặc số dư tiền mặt mong muốn sau khi thực hiện khoản thanh toán cuối cùng.' },
+ type: { name: 'loại', detail: 'Số 0 hoặc 1, dùng để xác định thời điểm thanh toán của mỗi kỳ là đầu hay cuối kỳ.' },
},
},
PRICE: {
@@ -557,8 +622,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất theo từng thời kỳ.' },
+ nper: { name: 'tổng số kỳ', detail: 'Tổng số kỳ thanh toán.' },
+ pmt: { name: 'số tiền', detail: 'Số tiền phải trả trong mỗi kỳ không thay đổi trong suốt thời hạn niên kim.' },
+ fv: { name: 'số dư tiền mặt', detail: 'Giá trị tương lai hoặc số dư tiền mặt mong muốn sau khi thực hiện khoản thanh toán cuối cùng.' },
+ type: { name: 'loại', detail: 'Số 0 hoặc 1, dùng để xác định thời điểm thanh toán của mỗi kỳ là đầu hay cuối kỳ.' },
},
},
RATE: {
@@ -571,8 +639,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nper: { name: 'tổng số kỳ', detail: 'Tổng số kỳ thanh toán.' },
+ pmt: { name: 'số tiền', detail: 'Số tiền phải trả trong mỗi kỳ không thay đổi trong suốt thời hạn niên kim.' },
+ pv: { name: 'giá trị hiện tại', detail: 'Giá trị hiện tại.' },
+ fv: { name: 'số dư tiền mặt', detail: 'Giá trị tương lai hoặc số dư tiền mặt mong muốn sau khi thực hiện khoản thanh toán cuối cùng.' },
+ type: { name: 'loại', detail: 'Số 0 hoặc 1, dùng để xác định thời điểm thanh toán của mỗi kỳ là đầu hay cuối kỳ.' },
+ guess: { name: 'giá trị đoán', detail: 'lãi suất kỳ vọng.' },
},
},
RECEIVED: {
diff --git a/packages/sheets-formula/src/locale/function-list/financial/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/financial/zh-CN.ts
index 025dfca942..89995ea9b3 100644
--- a/packages/sheets-formula/src/locale/function-list/financial/zh-CN.ts
+++ b/packages/sheets-formula/src/locale/function-list/financial/zh-CN.ts
@@ -25,8 +25,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ issue: { name: '发行日', detail: '有价证券的发行日。' },
+ firstInterest: { name: '首次计息日', detail: '有价证券的首次计息日。' },
+ settlement: { name: '到期日', detail: '有价证券的到期日。' },
+ rate: { name: '利率', detail: '有价证券的年息票利率。' },
+ par: { name: '面值', detail: '有价证券的票面值。' },
+ frequency: { name: '频次', detail: '年付息次数。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
+ calcMethod: { name: '计算方法', detail: '是一个逻辑值:从发行日期开始的应计利息 = TRUE 或忽略;从最后票息支付日期开始计算 = FALSE。' },
},
},
ACCRINTM: {
@@ -39,8 +45,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ issue: { name: '发行日', detail: '有价证券的发行日。' },
+ settlement: { name: '到期日', detail: '有价证券的到期日。' },
+ rate: { name: '利率', detail: '有价证券的年息票利率。' },
+ par: { name: '面值', detail: '有价证券的票面值。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
AMORDEGRC: {
@@ -67,8 +76,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '成本', detail: '资产原值。' },
+ datePurchased: { name: '购买日期', detail: '购入资产的日期。' },
+ firstPeriod: { name: '首个期间', detail: '第一个期间结束时的日期。' },
+ salvage: { name: '残值', detail: '资产在使用寿命结束时的残值。' },
+ period: { name: '期间', detail: '期间。' },
+ rate: { name: '折旧率', detail: '折旧率。' },
+ basis: { name: '基准', detail: '要使用的年基准。' },
},
},
COUPDAYBS: {
@@ -81,8 +95,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ frequency: { name: '频次', detail: '年付息次数。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
COUPDAYS: {
@@ -95,8 +111,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ frequency: { name: '频次', detail: '年付息次数。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
COUPDAYSNC: {
@@ -109,8 +127,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ frequency: { name: '频次', detail: '年付息次数。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
COUPNCD: {
@@ -123,8 +143,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ frequency: { name: '频次', detail: '年付息次数。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
COUPNUM: {
@@ -137,8 +159,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ frequency: { name: '频次', detail: '年付息次数。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
COUPPCD: {
@@ -151,8 +175,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ frequency: { name: '频次', detail: '年付息次数。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
CUMIPMT: {
@@ -165,8 +191,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '利率。' },
+ nper: { name: '总期数', detail: '总付款期数。' },
+ pv: { name: '现值', detail: '现值。' },
+ startPeriod: { name: '首期', detail: '计算中的首期。付款期数从1开始计数。' },
+ endPeriod: { name: '末期', detail: '计算中的末期。' },
+ type: { name: '类型', detail: '付款时间类型。' },
},
},
CUMPRINC: {
@@ -179,8 +209,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '利率。' },
+ nper: { name: '总期数', detail: '总付款期数。' },
+ pv: { name: '现值', detail: '现值。' },
+ startPeriod: { name: '首期', detail: '计算中的首期。付款期数从1开始计数。' },
+ endPeriod: { name: '末期', detail: '计算中的末期。' },
+ type: { name: '类型', detail: '付款时间类型。' },
},
},
DB: {
@@ -193,8 +227,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '成本', detail: '资产原值。' },
+ salvage: { name: '残值', detail: '折旧末尾时的值(有时也称为资产残值)。' },
+ life: { name: '使用寿命', detail: '资产的折旧期数(有时也称作资产的使用寿命)。' },
+ period: { name: '期间', detail: '您要计算折旧的时期。' },
+ month: { name: '月份', detail: '第一年的月份数。如果省略月份,则假定其值为12。' },
},
},
DDB: {
@@ -207,8 +244,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '成本', detail: '资产原值。' },
+ salvage: { name: '残值', detail: '折旧末尾时的值(有时也称为资产残值)。' },
+ life: { name: '使用寿命', detail: '资产的折旧期数(有时也称作资产的使用寿命)。' },
+ period: { name: '期间', detail: '您要计算折旧的时期。' },
+ factor: { name: '速率', detail: '余额递减速率。如果省略影响因素,则假定为2(双倍余额递减法)。' },
},
},
DISC: {
@@ -221,8 +261,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ pr: { name: '价格', detail: '有价证券的价格(按面值为¥100计算)。' },
+ redemption: { name: '清偿价', detail: '面值¥100的有价证券的清偿价值。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
DOLLARDE: {
@@ -235,8 +278,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ fractionalDollar: { name: '分数', detail: '以整数部份和分数部分表示的数字,用小数点隔开。' },
+ fraction: { name: '分母', detail: '用作分数中的分母的整数。' },
},
},
DOLLARFR: {
@@ -249,8 +292,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ decimalDollar: { name: '小数', detail: '小数。' },
+ fraction: { name: '分母', detail: '用作分数中的分母的整数。' },
},
},
DURATION: {
@@ -277,8 +320,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nominalRate: { name: '名义利率', detail: '名义利率。' },
+ npery: { name: '期数', detail: '每年的复利期数。' },
},
},
FV: {
@@ -291,8 +334,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '各期利率。' },
+ nper: { name: '总期数', detail: '年金的付款总期数。' },
+ pmt: { name: '金额', detail: '各期所应支付的金额,在整个年金期间保持不变。' },
+ pv: { name: '现值', detail: '现值,或一系列未来付款的当前值的累积和。' },
+ type: { name: '类型', detail: '数字0或1,用以指定各期的付款时间是在期初还是期末。' },
},
},
FVSCHEDULE: {
@@ -305,8 +351,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ principal: { name: '本金', detail: '现值。' },
+ schedule: { name: '利率数组', detail: '要应用的利率数组。' },
},
},
INTRATE: {
@@ -319,8 +365,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ investment: { name: '投资额', detail: '有价证券的投资额。' },
+ redemption: { name: '清偿价', detail: '有价证券到期时的兑换值。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
IPMT: {
@@ -333,8 +382,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '各期利率。' },
+ per: { name: '期数', detail: '用于计算其利息数额的期数,必须在1到nper之间。' },
+ nper: { name: '总期数', detail: '年金的付款总期数。' },
+ pv: { name: '现值', detail: '现值,或一系列未来付款的当前值的累积和。' },
+ fv: { name: '余额', detail: '未来值,或在最后一次付款后希望得到的现金余额。' },
+ type: { name: '类型', detail: '数字0或1,用以指定各期的付款时间是在期初还是期末。' },
},
},
IRR: {
@@ -361,8 +414,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '投资的利率。' },
+ per: { name: '期数', detail: '要查找兴趣的时间段,并且必须介于1和Nper之间。' },
+ nper: { name: '总期数', detail: '投资的总支付期数。' },
+ pv: { name: '现值', detail: '投资的现值。对于贷款,Pv是贷款金额。' },
},
},
MDURATION: {
@@ -403,8 +458,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ effectRate: { name: '实际利率', detail: '实际利率。' },
+ npery: { name: '期数', detail: '每年的复利期数。' },
},
},
NPER: {
@@ -417,8 +472,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '各期利率。' },
+ pmt: { name: '金额', detail: '各期所应支付的金额,在整个年金期间保持不变。' },
+ pv: { name: '现值', detail: '现值,或一系列未来付款的当前值的累积和。' },
+ fv: { name: '余额', detail: '未来值,或在最后一次付款后希望得到的现金余额。' },
+ type: { name: '类型', detail: '数字0或1,用以指定各期的付款时间是在期初还是期末。' },
},
},
NPV: {
@@ -515,8 +573,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '各期利率。' },
+ nper: { name: '总期数', detail: '年金的付款总期数。' },
+ pv: { name: '现值', detail: '现值,或一系列未来付款的当前值的累积和。' },
+ fv: { name: '余额', detail: '未来值,或在最后一次付款后希望得到的现金余额。' },
+ type: { name: '类型', detail: '数字0或1,用以指定各期的付款时间是在期初还是期末。' },
},
},
PPMT: {
@@ -529,8 +590,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '各期利率。' },
+ per: { name: '期数', detail: '用于计算其利息数额的期数,必须在1到nper之间。' },
+ nper: { name: '总期数', detail: '年金的付款总期数。' },
+ pv: { name: '现值', detail: '现值,或一系列未来付款的当前值的累积和。' },
+ fv: { name: '余额', detail: '未来值,或在最后一次付款后希望得到的现金余额。' },
+ type: { name: '类型', detail: '数字0或1,用以指定各期的付款时间是在期初还是期末。' },
},
},
PRICE: {
@@ -585,8 +650,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '各期利率。' },
+ nper: { name: '总期数', detail: '年金的付款总期数。' },
+ pmt: { name: '金额', detail: '各期所应支付的金额,在整个年金期间保持不变。' },
+ fv: { name: '余额', detail: '未来值,或在最后一次付款后希望得到的现金余额。' },
+ type: { name: '类型', detail: '数字0或1,用以指定各期的付款时间是在期初还是期末。' },
},
},
RATE: {
@@ -599,8 +667,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nper: { name: '总期数', detail: '年金的付款总期数。' },
+ pmt: { name: '金额', detail: '各期所应支付的金额,在整个年金期间保持不变。' },
+ pv: { name: '现值', detail: '现值,或一系列未来付款的当前值的累积和。' },
+ fv: { name: '余额', detail: '未来值,或在最后一次付款后希望得到的现金余额。' },
+ type: { name: '类型', detail: '数字0或1,用以指定各期的付款时间是在期初还是期末。' },
+ guess: { name: '猜测值', detail: '预期利率。' },
},
},
RECEIVED: {
diff --git a/packages/sheets-formula/src/locale/function-list/financial/zh-TW.ts b/packages/sheets-formula/src/locale/function-list/financial/zh-TW.ts
index 8c8bf4f5e0..167e6cdd33 100644
--- a/packages/sheets-formula/src/locale/function-list/financial/zh-TW.ts
+++ b/packages/sheets-formula/src/locale/function-list/financial/zh-TW.ts
@@ -25,8 +25,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ issue: { name: '發行日', detail: '這是證券的發行日期。' },
+ firstInterest: { name: '首次計息日', detail: '這是證券的第一個利率日期。' },
+ settlement: { name: '到期日', detail: '這是證券的到期日期。' },
+ rate: { name: '利率', detail: '這是證券的年度票息率。' },
+ par: { name: '面值', detail: '這是證券的票面價值。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
+ calcMethod: { name: '計算方法', detail: '是一個邏輯值:從發行日期開始的應計利息 = TRUE 或忽略;從最後票據支付日期開始計算 = FALSE。' },
},
},
ACCRINTM: {
@@ -39,8 +45,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ issue: { name: '發行日', detail: '這是證券的發行日期。' },
+ settlement: { name: '到期日', detail: '這是證券的到期日期。' },
+ rate: { name: '利率', detail: '這是證券的年度票息率。' },
+ par: { name: '面值', detail: '這是證券的票面價值。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
AMORDEGRC: {
@@ -67,8 +76,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '成本', detail: '這是資產的成本。' },
+ datePurchased: { name: '購買日期', detail: '這是資產的購買日期。' },
+ firstPeriod: { name: '首個週期', detail: '這是第一個週期結束的日期。' },
+ salvage: { name: '殘值', detail: '資產耐用年限終了時的殘餘價值。' },
+ period: { name: '週期', detail: '這是週期。' },
+ rate: { name: '折舊率', detail: '這是折舊率。' },
+ basis: { name: '基礎', detail: '這是要使用的年計數基礎。' },
},
},
COUPDAYBS: {
@@ -81,8 +95,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
COUPDAYS: {
@@ -95,8 +111,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
COUPDAYSNC: {
@@ -109,8 +127,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
COUPNCD: {
@@ -123,8 +143,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
COUPNUM: {
@@ -137,8 +159,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
COUPPCD: {
@@ -151,8 +175,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
CUMIPMT: {
@@ -165,8 +191,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '這是利率。' },
+ nper: { name: '總期數', detail: '這是總付款期數。' },
+ pv: { name: '現值', detail: '這是現值。' },
+ startPeriod: { name: '首期', detail: '這是計算中的第一個週期。付款週期的編號由1開始。' },
+ endPeriod: { name: '末期', detail: '這是計算中的最後一個週期。' },
+ type: { name: '類型', detail: '這是付款的時機。' },
},
},
CUMPRINC: {
@@ -179,8 +209,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '這是利率。' },
+ nper: { name: '總期數', detail: '這是總付款期數。' },
+ pv: { name: '現值', detail: '這是現值。' },
+ startPeriod: { name: '首期', detail: '這是計算中的第一個週期。付款週期的編號由1開始。' },
+ endPeriod: { name: '末期', detail: '這是計算中的最後一個週期。' },
+ type: { name: '類型', detail: '這是付款的時機。' },
},
},
DB: {
@@ -193,8 +227,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '成本', detail: '這是資產的原始成本。' },
+ salvage: { name: '殘值', detail: '這是折舊最後的值 (有時稱為資產的殘餘價值)。' },
+ life: { name: '使用年限', detail: '這是資產折舊的期數 (有時稱為資產的使用年限)。' },
+ period: { name: '期間', detail: '這是要計算折舊的期間。' },
+ month: { name: '月份', detail: '第一年的月份數。如果省略 month,則假設其值為12。' },
},
},
DDB: {
@@ -207,8 +244,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '成本', detail: '這是資產的原始成本。' },
+ salvage: { name: '殘值', detail: '這是折舊最後的值 (有時稱為資產的殘餘價值)。' },
+ life: { name: '使用年限', detail: '這是資產折舊的期數 (有時稱為資產的使用年限)。' },
+ period: { name: '期間', detail: '這是要計算折舊的期間。' },
+ factor: { name: '速率', detail: '這是餘額遞減的速率。如果省略factor,將假設其值為2(倍率遞減法)。' },
},
},
DISC: {
@@ -221,8 +261,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ pr: { name: '價格', detail: '這是證券每$100面額的價格。' },
+ redemption: { name: '贖回價', detail: '這是證券每$100面額的贖回價值。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
DOLLARDE: {
@@ -235,8 +278,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ fractionalDollar: { name: '分數', detail: '這是以整數部分和分數部分表示,並以小數點符號分隔的數字。' },
+ fraction: { name: '分母', detail: '這是用於分數之分母的整數。' },
},
},
DOLLARFR: {
@@ -249,8 +292,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ decimalDollar: { name: '小數', detail: '這是小數。' },
+ fraction: { name: '分母', detail: '這是用於分數之分母的整數。' },
},
},
DURATION: {
@@ -277,8 +320,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nominalRate: { name: '名義利率', detail: '這是名義利率。' },
+ npery: { name: '期數', detail: '每年以複利計算之期數。' },
},
},
FV: {
@@ -291,8 +334,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '這是各期的利率。' },
+ nper: { name: '總期數', detail: '這是年金的總付款期數。' },
+ pmt: { name: '金額', detail: '這是各期給付的金額;不得在年金期限內變更。' },
+ pv: { name: '現值', detail: '一系列未來付款的現值或目前總額。' },
+ type: { name: '類型', detail: '數字0或1,指出付款期限。' },
},
},
FVSCHEDULE: {
@@ -305,8 +351,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ principal: { name: '初始資金', detail: '這是現值。' },
+ schedule: { name: '利率陣列', detail: '這是要套用的利率陣列。' },
},
},
INTRATE: {
@@ -319,8 +365,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ investment: { name: '投資額', detail: '這是證券的投資額。' },
+ redemption: { name: '贖回價', detail: '這是證券到期時的贖回價值。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
IPMT: {
@@ -333,8 +382,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '這是各期的利率。' },
+ per: { name: '期數', detail: '這是求算利息的期次,其值必須介於1到nper之間。' },
+ nper: { name: '總期數', detail: '這是年金的總付款期數。' },
+ pv: { name: '現值', detail: '一系列未來付款的現值或目前總額。' },
+ fv: { name: '餘額', detail: '這是最後一次付款完成後,所能獲得的未來值或現金餘額。' },
+ type: { name: '類型', detail: '數字0或1,指出付款期限。' },
},
},
IRR: {
@@ -361,8 +414,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '這是投資的利率。' },
+ per: { name: '期數', detail: '這是要尋找利息的期間,其值必須介於1到Nper之間。' },
+ nper: { name: '總期數', detail: '這是投資的總付款期數。' },
+ pv: { name: '現值', detail: '這是投資的現值。若為貸款,Pv為貸款金額。' },
},
},
MDURATION: {
@@ -403,8 +458,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ effectRate: { name: '實質利率', detail: '這是實質利率。' },
+ npery: { name: '期數', detail: '每年以複利計算之期數。' },
},
},
NPER: {
@@ -417,8 +472,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '這是各期的利率。' },
+ pmt: { name: '金額', detail: '這是各期給付的金額;不得在年金期限內變更。' },
+ pv: { name: '現值', detail: '一系列未來付款的現值或目前總額。' },
+ fv: { name: '餘額', detail: '這是最後一次付款完成後,所能獲得的未來值或現金餘額。' },
+ type: { name: '類型', detail: '數字0或1,指出付款期限。' },
},
},
NPV: {
@@ -514,8 +572,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '這是各期的利率。' },
+ nper: { name: '總期數', detail: '這是年金的總付款期數。' },
+ pv: { name: '現值', detail: '一系列未來付款的現值或目前總額。' },
+ fv: { name: '餘額', detail: '這是最後一次付款完成後,所能獲得的未來值或現金餘額。' },
+ type: { name: '類型', detail: '數字0或1,指出付款期限。' },
},
},
PPMT: {
@@ -528,8 +589,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '這是各期的利率。' },
+ per: { name: '期數', detail: '這是求算利息的期次,其值必須介於1到nper之間。' },
+ nper: { name: '總期數', detail: '這是年金的總付款期數。' },
+ pv: { name: '現值', detail: '一系列未來付款的現值或目前總額。' },
+ fv: { name: '餘額', detail: '這是最後一次付款完成後,所能獲得的未來值或現金餘額。' },
+ type: { name: '類型', detail: '數字0或1,指出付款期限。' },
},
},
PRICE: {
@@ -584,8 +649,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '這是各期的利率。' },
+ nper: { name: '總期數', detail: '這是年金的總付款期數。' },
+ pmt: { name: '金額', detail: '這是各期給付的金額;不得在年金期限內變更。' },
+ fv: { name: '餘額', detail: '這是最後一次付款完成後,所能獲得的未來值或現金餘額。' },
+ type: { name: '類型', detail: '數字0或1,指出付款期限。' },
},
},
RATE: {
@@ -598,8 +666,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nper: { name: '總期數', detail: '這是年金的總付款期數。' },
+ pmt: { name: '金額', detail: '這是各期給付的金額;不得在年金期限內變更。' },
+ pv: { name: '現值', detail: '一系列未來付款的現值或目前總額。' },
+ fv: { name: '餘額', detail: '這是最後一次付款完成後,所能獲得的未來值或現金餘額。' },
+ type: { name: '類型', detail: '數字0或1,指出付款期限。' },
+ guess: { name: '猜測值', detail: '這是對利率的猜測值。' },
},
},
RECEIVED: {
diff --git a/packages/sheets-formula/src/services/function-list/financial.ts b/packages/sheets-formula/src/services/function-list/financial.ts
index 1e487435ad..57c763f823 100644
--- a/packages/sheets-formula/src/services/function-list/financial.ts
+++ b/packages/sheets-formula/src/services/function-list/financial.ts
@@ -24,19 +24,61 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.ACCRINT.abstract',
functionParameter: [
{
- name: 'formula.functionList.ACCRINT.functionParameter.number1.name',
- detail: 'formula.functionList.ACCRINT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ACCRINT.functionParameter.issue.name',
+ detail: 'formula.functionList.ACCRINT.functionParameter.issue.detail',
+ example: '39508',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.ACCRINT.functionParameter.number2.name',
- detail: 'formula.functionList.ACCRINT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ACCRINT.functionParameter.firstInterest.name',
+ detail: 'formula.functionList.ACCRINT.functionParameter.firstInterest.detail',
+ example: '39691',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ACCRINT.functionParameter.settlement.name',
+ detail: 'formula.functionList.ACCRINT.functionParameter.settlement.detail',
+ example: '39569',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ACCRINT.functionParameter.rate.name',
+ detail: 'formula.functionList.ACCRINT.functionParameter.rate.detail',
+ example: '0.1',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.ACCRINT.functionParameter.par.name',
+ detail: 'formula.functionList.ACCRINT.functionParameter.par.detail',
+ example: '1000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ACCRINT.functionParameter.frequency.name',
+ detail: 'formula.functionList.ACCRINT.functionParameter.frequency.detail',
+ example: '2',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ACCRINT.functionParameter.basis.name',
+ detail: 'formula.functionList.ACCRINT.functionParameter.basis.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ACCRINT.functionParameter.calcMethod.name',
+ detail: 'formula.functionList.ACCRINT.functionParameter.calcMethod.detail',
+ example: 'true',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -46,19 +88,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.ACCRINTM.abstract',
functionParameter: [
{
- name: 'formula.functionList.ACCRINTM.functionParameter.number1.name',
- detail: 'formula.functionList.ACCRINTM.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ACCRINTM.functionParameter.issue.name',
+ detail: 'formula.functionList.ACCRINTM.functionParameter.issue.detail',
+ example: '"2008-4-1"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.ACCRINTM.functionParameter.number2.name',
- detail: 'formula.functionList.ACCRINTM.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ACCRINTM.functionParameter.settlement.name',
+ detail: 'formula.functionList.ACCRINTM.functionParameter.settlement.detail',
+ example: '"2008-6-15"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ACCRINTM.functionParameter.rate.name',
+ detail: 'formula.functionList.ACCRINTM.functionParameter.rate.detail',
+ example: '0.1',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.ACCRINTM.functionParameter.par.name',
+ detail: 'formula.functionList.ACCRINTM.functionParameter.par.detail',
+ example: '1000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ACCRINTM.functionParameter.basis.name',
+ detail: 'formula.functionList.ACCRINTM.functionParameter.basis.detail',
+ example: '3',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -90,19 +153,54 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.AMORLINC.abstract',
functionParameter: [
{
- name: 'formula.functionList.AMORLINC.functionParameter.number1.name',
- detail: 'formula.functionList.AMORLINC.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.AMORLINC.functionParameter.cost.name',
+ detail: 'formula.functionList.AMORLINC.functionParameter.cost.detail',
+ example: '2400',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.AMORLINC.functionParameter.number2.name',
- detail: 'formula.functionList.AMORLINC.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.AMORLINC.functionParameter.datePurchased.name',
+ detail: 'formula.functionList.AMORLINC.functionParameter.datePurchased.detail',
+ example: '39679',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.AMORLINC.functionParameter.firstPeriod.name',
+ detail: 'formula.functionList.AMORLINC.functionParameter.firstPeriod.detail',
+ example: '39813',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.AMORLINC.functionParameter.salvage.name',
+ detail: 'formula.functionList.AMORLINC.functionParameter.salvage.detail',
+ example: '300',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.AMORLINC.functionParameter.period.name',
+ detail: 'formula.functionList.AMORLINC.functionParameter.period.detail',
+ example: '1',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.AMORLINC.functionParameter.rate.name',
+ detail: 'formula.functionList.AMORLINC.functionParameter.rate.detail',
+ example: '0.15',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.AMORLINC.functionParameter.basis.name',
+ detail: 'formula.functionList.AMORLINC.functionParameter.basis.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -112,19 +210,33 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.COUPDAYBS.abstract',
functionParameter: [
{
- name: 'formula.functionList.COUPDAYBS.functionParameter.number1.name',
- detail: 'formula.functionList.COUPDAYBS.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPDAYBS.functionParameter.settlement.name',
+ detail: 'formula.functionList.COUPDAYBS.functionParameter.settlement.detail',
+ example: '"2011-1-25"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.COUPDAYBS.functionParameter.number2.name',
- detail: 'formula.functionList.COUPDAYBS.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPDAYBS.functionParameter.maturity.name',
+ detail: 'formula.functionList.COUPDAYBS.functionParameter.maturity.detail',
+ example: '"2011-11-15"',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.COUPDAYBS.functionParameter.frequency.name',
+ detail: 'formula.functionList.COUPDAYBS.functionParameter.frequency.detail',
+ example: '2',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.COUPDAYBS.functionParameter.basis.name',
+ detail: 'formula.functionList.COUPDAYBS.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -134,19 +246,33 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.COUPDAYS.abstract',
functionParameter: [
{
- name: 'formula.functionList.COUPDAYS.functionParameter.number1.name',
- detail: 'formula.functionList.COUPDAYS.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPDAYS.functionParameter.settlement.name',
+ detail: 'formula.functionList.COUPDAYS.functionParameter.settlement.detail',
+ example: '"2011-1-25"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.COUPDAYS.functionParameter.number2.name',
- detail: 'formula.functionList.COUPDAYS.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPDAYS.functionParameter.maturity.name',
+ detail: 'formula.functionList.COUPDAYS.functionParameter.maturity.detail',
+ example: '"2011-11-15"',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.COUPDAYS.functionParameter.frequency.name',
+ detail: 'formula.functionList.COUPDAYS.functionParameter.frequency.detail',
+ example: '2',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.COUPDAYS.functionParameter.basis.name',
+ detail: 'formula.functionList.COUPDAYS.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -156,19 +282,33 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.COUPDAYSNC.abstract',
functionParameter: [
{
- name: 'formula.functionList.COUPDAYSNC.functionParameter.number1.name',
- detail: 'formula.functionList.COUPDAYSNC.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPDAYSNC.functionParameter.settlement.name',
+ detail: 'formula.functionList.COUPDAYSNC.functionParameter.settlement.detail',
+ example: '"2011-1-25"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.COUPDAYSNC.functionParameter.number2.name',
- detail: 'formula.functionList.COUPDAYSNC.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPDAYSNC.functionParameter.maturity.name',
+ detail: 'formula.functionList.COUPDAYSNC.functionParameter.maturity.detail',
+ example: '"2011-11-15"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.COUPDAYSNC.functionParameter.frequency.name',
+ detail: 'formula.functionList.COUPDAYSNC.functionParameter.frequency.detail',
+ example: '2',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.COUPDAYSNC.functionParameter.basis.name',
+ detail: 'formula.functionList.COUPDAYSNC.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -178,19 +318,33 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.COUPNCD.abstract',
functionParameter: [
{
- name: 'formula.functionList.COUPNCD.functionParameter.number1.name',
- detail: 'formula.functionList.COUPNCD.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPNCD.functionParameter.settlement.name',
+ detail: 'formula.functionList.COUPNCD.functionParameter.settlement.detail',
+ example: '"2011-1-25"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.COUPNCD.functionParameter.number2.name',
- detail: 'formula.functionList.COUPNCD.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPNCD.functionParameter.maturity.name',
+ detail: 'formula.functionList.COUPNCD.functionParameter.maturity.detail',
+ example: '"2011-11-15"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.COUPNCD.functionParameter.frequency.name',
+ detail: 'formula.functionList.COUPNCD.functionParameter.frequency.detail',
+ example: '2',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.COUPNCD.functionParameter.basis.name',
+ detail: 'formula.functionList.COUPNCD.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -200,19 +354,33 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.COUPNUM.abstract',
functionParameter: [
{
- name: 'formula.functionList.COUPNUM.functionParameter.number1.name',
- detail: 'formula.functionList.COUPNUM.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPNUM.functionParameter.settlement.name',
+ detail: 'formula.functionList.COUPNUM.functionParameter.settlement.detail',
+ example: '"2011-1-25"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.COUPNUM.functionParameter.number2.name',
- detail: 'formula.functionList.COUPNUM.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPNUM.functionParameter.maturity.name',
+ detail: 'formula.functionList.COUPNUM.functionParameter.maturity.detail',
+ example: '"2011-11-15"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.COUPNUM.functionParameter.frequency.name',
+ detail: 'formula.functionList.COUPNUM.functionParameter.frequency.detail',
+ example: '2',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.COUPNUM.functionParameter.basis.name',
+ detail: 'formula.functionList.COUPNUM.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -222,19 +390,33 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.COUPPCD.abstract',
functionParameter: [
{
- name: 'formula.functionList.COUPPCD.functionParameter.number1.name',
- detail: 'formula.functionList.COUPPCD.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPPCD.functionParameter.settlement.name',
+ detail: 'formula.functionList.COUPPCD.functionParameter.settlement.detail',
+ example: '"2011-1-25"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.COUPPCD.functionParameter.number2.name',
- detail: 'formula.functionList.COUPPCD.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.COUPPCD.functionParameter.maturity.name',
+ detail: 'formula.functionList.COUPPCD.functionParameter.maturity.detail',
+ example: '"2011-11-15"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.COUPPCD.functionParameter.frequency.name',
+ detail: 'formula.functionList.COUPPCD.functionParameter.frequency.detail',
+ example: '2',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.COUPPCD.functionParameter.basis.name',
+ detail: 'formula.functionList.COUPPCD.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -244,16 +426,44 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.CUMIPMT.abstract',
functionParameter: [
{
- name: 'formula.functionList.CUMIPMT.functionParameter.number1.name',
- detail: 'formula.functionList.CUMIPMT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.CUMIPMT.functionParameter.rate.name',
+ detail: 'formula.functionList.CUMIPMT.functionParameter.rate.detail',
+ example: '0.09/12',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.CUMIPMT.functionParameter.number2.name',
- detail: 'formula.functionList.CUMIPMT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.CUMIPMT.functionParameter.nper.name',
+ detail: 'formula.functionList.CUMIPMT.functionParameter.nper.detail',
+ example: '30*12',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.CUMIPMT.functionParameter.pv.name',
+ detail: 'formula.functionList.CUMIPMT.functionParameter.pv.detail',
+ example: '125000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.CUMIPMT.functionParameter.startPeriod.name',
+ detail: 'formula.functionList.CUMIPMT.functionParameter.startPeriod.detail',
+ example: '13',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.CUMIPMT.functionParameter.endPeriod.name',
+ detail: 'formula.functionList.CUMIPMT.functionParameter.endPeriod.detail',
+ example: '24',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.CUMIPMT.functionParameter.type.name',
+ detail: 'formula.functionList.CUMIPMT.functionParameter.type.detail',
+ example: '0',
require: 1,
repeat: 0,
},
@@ -266,16 +476,44 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.CUMPRINC.abstract',
functionParameter: [
{
- name: 'formula.functionList.CUMPRINC.functionParameter.number1.name',
- detail: 'formula.functionList.CUMPRINC.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.CUMPRINC.functionParameter.rate.name',
+ detail: 'formula.functionList.CUMPRINC.functionParameter.rate.detail',
+ example: '0.09/12',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.CUMPRINC.functionParameter.number2.name',
- detail: 'formula.functionList.CUMPRINC.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.CUMPRINC.functionParameter.nper.name',
+ detail: 'formula.functionList.CUMPRINC.functionParameter.nper.detail',
+ example: '30*12',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.CUMPRINC.functionParameter.pv.name',
+ detail: 'formula.functionList.CUMPRINC.functionParameter.pv.detail',
+ example: '125000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.CUMPRINC.functionParameter.startPeriod.name',
+ detail: 'formula.functionList.CUMPRINC.functionParameter.startPeriod.detail',
+ example: '13',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.CUMPRINC.functionParameter.endPeriod.name',
+ detail: 'formula.functionList.CUMPRINC.functionParameter.endPeriod.detail',
+ example: '24',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.CUMPRINC.functionParameter.type.name',
+ detail: 'formula.functionList.CUMPRINC.functionParameter.type.detail',
+ example: '0',
require: 1,
repeat: 0,
},
@@ -288,19 +526,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.DB.abstract',
functionParameter: [
{
- name: 'formula.functionList.DB.functionParameter.number1.name',
- detail: 'formula.functionList.DB.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DB.functionParameter.cost.name',
+ detail: 'formula.functionList.DB.functionParameter.cost.detail',
+ example: '10000000',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DB.functionParameter.number2.name',
- detail: 'formula.functionList.DB.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DB.functionParameter.salvage.name',
+ detail: 'formula.functionList.DB.functionParameter.salvage.detail',
+ example: '1000000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DB.functionParameter.life.name',
+ detail: 'formula.functionList.DB.functionParameter.life.detail',
+ example: '6',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DB.functionParameter.period.name',
+ detail: 'formula.functionList.DB.functionParameter.period.detail',
+ example: '1',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.DB.functionParameter.month.name',
+ detail: 'formula.functionList.DB.functionParameter.month.detail',
+ example: '7',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -310,19 +569,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.DDB.abstract',
functionParameter: [
{
- name: 'formula.functionList.DDB.functionParameter.number1.name',
- detail: 'formula.functionList.DDB.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DDB.functionParameter.cost.name',
+ detail: 'formula.functionList.DDB.functionParameter.cost.detail',
+ example: '24000',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DDB.functionParameter.number2.name',
- detail: 'formula.functionList.DDB.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DDB.functionParameter.salvage.name',
+ detail: 'formula.functionList.DDB.functionParameter.salvage.detail',
+ example: '3000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DDB.functionParameter.life.name',
+ detail: 'formula.functionList.DDB.functionParameter.life.detail',
+ example: '10',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DDB.functionParameter.period.name',
+ detail: 'formula.functionList.DDB.functionParameter.period.detail',
+ example: '1',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.DDB.functionParameter.factor.name',
+ detail: 'formula.functionList.DDB.functionParameter.factor.detail',
+ example: '2',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -332,19 +612,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.DISC.abstract',
functionParameter: [
{
- name: 'formula.functionList.DISC.functionParameter.number1.name',
- detail: 'formula.functionList.DISC.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DISC.functionParameter.settlement.name',
+ detail: 'formula.functionList.DISC.functionParameter.settlement.detail',
+ example: '"2018-7-1"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DISC.functionParameter.number2.name',
- detail: 'formula.functionList.DISC.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DISC.functionParameter.maturity.name',
+ detail: 'formula.functionList.DISC.functionParameter.maturity.detail',
+ example: '"2048-1-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DISC.functionParameter.pr.name',
+ detail: 'formula.functionList.DISC.functionParameter.pr.detail',
+ example: '97.975',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DISC.functionParameter.redemption.name',
+ detail: 'formula.functionList.DISC.functionParameter.redemption.detail',
+ example: '100',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.DISC.functionParameter.basis.name',
+ detail: 'formula.functionList.DISC.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -354,16 +655,16 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.DOLLARDE.abstract',
functionParameter: [
{
- name: 'formula.functionList.DOLLARDE.functionParameter.number1.name',
- detail: 'formula.functionList.DOLLARDE.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DOLLARDE.functionParameter.fractionalDollar.name',
+ detail: 'formula.functionList.DOLLARDE.functionParameter.fractionalDollar.detail',
+ example: '1.02',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DOLLARDE.functionParameter.number2.name',
- detail: 'formula.functionList.DOLLARDE.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DOLLARDE.functionParameter.fraction.name',
+ detail: 'formula.functionList.DOLLARDE.functionParameter.fraction.detail',
+ example: '16',
require: 1,
repeat: 0,
},
@@ -376,16 +677,16 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.DOLLARFR.abstract',
functionParameter: [
{
- name: 'formula.functionList.DOLLARFR.functionParameter.number1.name',
- detail: 'formula.functionList.DOLLARFR.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DOLLARFR.functionParameter.decimalDollar.name',
+ detail: 'formula.functionList.DOLLARFR.functionParameter.decimalDollar.detail',
+ example: '1.125',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DOLLARFR.functionParameter.number2.name',
- detail: 'formula.functionList.DOLLARFR.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DOLLARFR.functionParameter.fraction.name',
+ detail: 'formula.functionList.DOLLARFR.functionParameter.fraction.detail',
+ example: '16',
require: 1,
repeat: 0,
},
@@ -420,16 +721,16 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.EFFECT.abstract',
functionParameter: [
{
- name: 'formula.functionList.EFFECT.functionParameter.number1.name',
- detail: 'formula.functionList.EFFECT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.EFFECT.functionParameter.nominalRate.name',
+ detail: 'formula.functionList.EFFECT.functionParameter.nominalRate.detail',
+ example: '0.0525',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.EFFECT.functionParameter.number2.name',
- detail: 'formula.functionList.EFFECT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.EFFECT.functionParameter.npery.name',
+ detail: 'formula.functionList.EFFECT.functionParameter.npery.detail',
+ example: '4',
require: 1,
repeat: 0,
},
@@ -442,19 +743,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.FV.abstract',
functionParameter: [
{
- name: 'formula.functionList.FV.functionParameter.number1.name',
- detail: 'formula.functionList.FV.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.FV.functionParameter.rate.name',
+ detail: 'formula.functionList.FV.functionParameter.rate.detail',
+ example: '0.06/12',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.FV.functionParameter.number2.name',
- detail: 'formula.functionList.FV.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.FV.functionParameter.nper.name',
+ detail: 'formula.functionList.FV.functionParameter.nper.detail',
+ example: '10',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.FV.functionParameter.pmt.name',
+ detail: 'formula.functionList.FV.functionParameter.pmt.detail',
+ example: '-200',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.FV.functionParameter.pv.name',
+ detail: 'formula.functionList.FV.functionParameter.pv.detail',
+ example: '-500',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.FV.functionParameter.type.name',
+ detail: 'formula.functionList.FV.functionParameter.type.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -464,16 +786,16 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.FVSCHEDULE.abstract',
functionParameter: [
{
- name: 'formula.functionList.FVSCHEDULE.functionParameter.number1.name',
- detail: 'formula.functionList.FVSCHEDULE.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.FVSCHEDULE.functionParameter.principal.name',
+ detail: 'formula.functionList.FVSCHEDULE.functionParameter.principal.detail',
+ example: '1',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.FVSCHEDULE.functionParameter.number2.name',
- detail: 'formula.functionList.FVSCHEDULE.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.FVSCHEDULE.functionParameter.schedule.name',
+ detail: 'formula.functionList.FVSCHEDULE.functionParameter.schedule.detail',
+ example: '{0.09,0.11,0.1}',
require: 1,
repeat: 0,
},
@@ -486,19 +808,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.INTRATE.abstract',
functionParameter: [
{
- name: 'formula.functionList.INTRATE.functionParameter.number1.name',
- detail: 'formula.functionList.INTRATE.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.INTRATE.functionParameter.settlement.name',
+ detail: 'formula.functionList.INTRATE.functionParameter.settlement.detail',
+ example: '"2008-2-15"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.INTRATE.functionParameter.number2.name',
- detail: 'formula.functionList.INTRATE.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.INTRATE.functionParameter.maturity.name',
+ detail: 'formula.functionList.INTRATE.functionParameter.maturity.detail',
+ example: '"2008-5-15"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.INTRATE.functionParameter.investment.name',
+ detail: 'formula.functionList.INTRATE.functionParameter.investment.detail',
+ example: '10000000',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.INTRATE.functionParameter.redemption.name',
+ detail: 'formula.functionList.INTRATE.functionParameter.redemption.detail',
+ example: '10144200',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.INTRATE.functionParameter.basis.name',
+ detail: 'formula.functionList.INTRATE.functionParameter.basis.detail',
+ example: '2',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -508,19 +851,47 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.IPMT.abstract',
functionParameter: [
{
- name: 'formula.functionList.IPMT.functionParameter.number1.name',
- detail: 'formula.functionList.IPMT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.IPMT.functionParameter.rate.name',
+ detail: 'formula.functionList.IPMT.functionParameter.rate.detail',
+ example: '0.1/12',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.IPMT.functionParameter.number2.name',
- detail: 'formula.functionList.IPMT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.IPMT.functionParameter.per.name',
+ detail: 'formula.functionList.IPMT.functionParameter.per.detail',
+ example: '1',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.IPMT.functionParameter.nper.name',
+ detail: 'formula.functionList.IPMT.functionParameter.nper.detail',
+ example: '3*12',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.IPMT.functionParameter.pv.name',
+ detail: 'formula.functionList.IPMT.functionParameter.pv.detail',
+ example: '80000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.IPMT.functionParameter.fv.name',
+ detail: 'formula.functionList.IPMT.functionParameter.fv.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.IPMT.functionParameter.type.name',
+ detail: 'formula.functionList.IPMT.functionParameter.type.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -552,16 +923,30 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.ISPMT.abstract',
functionParameter: [
{
- name: 'formula.functionList.ISPMT.functionParameter.number1.name',
- detail: 'formula.functionList.ISPMT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ISPMT.functionParameter.rate.name',
+ detail: 'formula.functionList.ISPMT.functionParameter.rate.detail',
+ example: '0.1',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.ISPMT.functionParameter.number2.name',
- detail: 'formula.functionList.ISPMT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ISPMT.functionParameter.per.name',
+ detail: 'formula.functionList.ISPMT.functionParameter.per.detail',
+ example: '2',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ISPMT.functionParameter.nper.name',
+ detail: 'formula.functionList.ISPMT.functionParameter.nper.detail',
+ example: '5',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ISPMT.functionParameter.pv.name',
+ detail: 'formula.functionList.ISPMT.functionParameter.pv.detail',
+ example: '1000',
require: 1,
repeat: 0,
},
@@ -618,16 +1003,16 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.NOMINAL.abstract',
functionParameter: [
{
- name: 'formula.functionList.NOMINAL.functionParameter.number1.name',
- detail: 'formula.functionList.NOMINAL.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.NOMINAL.functionParameter.effectRate.name',
+ detail: 'formula.functionList.NOMINAL.functionParameter.effectRate.detail',
+ example: '0.053543',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.NOMINAL.functionParameter.number2.name',
- detail: 'formula.functionList.NOMINAL.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.NOMINAL.functionParameter.npery.name',
+ detail: 'formula.functionList.NOMINAL.functionParameter.npery.detail',
+ example: '4',
require: 1,
repeat: 0,
},
@@ -640,19 +1025,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.NPER.abstract',
functionParameter: [
{
- name: 'formula.functionList.NPER.functionParameter.number1.name',
- detail: 'formula.functionList.NPER.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.NPER.functionParameter.rate.name',
+ detail: 'formula.functionList.NPER.functionParameter.rate.detail',
+ example: '0.12/12',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.NPER.functionParameter.number2.name',
- detail: 'formula.functionList.NPER.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.NPER.functionParameter.pmt.name',
+ detail: 'formula.functionList.NPER.functionParameter.pmt.detail',
+ example: '-100',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.NPER.functionParameter.pv.name',
+ detail: 'formula.functionList.NPER.functionParameter.pv.detail',
+ example: '-1000',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.NPER.functionParameter.fv.name',
+ detail: 'formula.functionList.NPER.functionParameter.fv.detail',
+ example: '10000',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.NPER.functionParameter.type.name',
+ detail: 'formula.functionList.NPER.functionParameter.type.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -794,19 +1200,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.PMT.abstract',
functionParameter: [
{
- name: 'formula.functionList.PMT.functionParameter.number1.name',
- detail: 'formula.functionList.PMT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PMT.functionParameter.rate.name',
+ detail: 'formula.functionList.PMT.functionParameter.rate.detail',
+ example: '0.08/12',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.PMT.functionParameter.number2.name',
- detail: 'formula.functionList.PMT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PMT.functionParameter.nper.name',
+ detail: 'formula.functionList.PMT.functionParameter.nper.detail',
+ example: '10',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.PMT.functionParameter.pv.name',
+ detail: 'formula.functionList.PMT.functionParameter.pv.detail',
+ example: '10000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PMT.functionParameter.fv.name',
+ detail: 'formula.functionList.PMT.functionParameter.fv.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PMT.functionParameter.type.name',
+ detail: 'formula.functionList.PMT.functionParameter.type.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -816,19 +1243,47 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.PPMT.abstract',
functionParameter: [
{
- name: 'formula.functionList.PPMT.functionParameter.number1.name',
- detail: 'formula.functionList.PPMT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PPMT.functionParameter.rate.name',
+ detail: 'formula.functionList.PPMT.functionParameter.rate.detail',
+ example: '0.1/12',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.PPMT.functionParameter.number2.name',
- detail: 'formula.functionList.PPMT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PPMT.functionParameter.per.name',
+ detail: 'formula.functionList.PPMT.functionParameter.per.detail',
+ example: '1',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PPMT.functionParameter.nper.name',
+ detail: 'formula.functionList.PPMT.functionParameter.nper.detail',
+ example: '3*12',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PPMT.functionParameter.pv.name',
+ detail: 'formula.functionList.PPMT.functionParameter.pv.detail',
+ example: '80000',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.PPMT.functionParameter.fv.name',
+ detail: 'formula.functionList.PPMT.functionParameter.fv.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PPMT.functionParameter.type.name',
+ detail: 'formula.functionList.PPMT.functionParameter.type.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -904,19 +1359,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.PV.abstract',
functionParameter: [
{
- name: 'formula.functionList.PV.functionParameter.number1.name',
- detail: 'formula.functionList.PV.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PV.functionParameter.rate.name',
+ detail: 'formula.functionList.PV.functionParameter.rate.detail',
+ example: '0.02',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.PV.functionParameter.number2.name',
- detail: 'formula.functionList.PV.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PV.functionParameter.nper.name',
+ detail: 'formula.functionList.PV.functionParameter.nper.detail',
+ example: '12',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PV.functionParameter.pmt.name',
+ detail: 'formula.functionList.PV.functionParameter.pmt.detail',
+ example: '100',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.PV.functionParameter.fv.name',
+ detail: 'formula.functionList.PV.functionParameter.fv.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PV.functionParameter.type.name',
+ detail: 'formula.functionList.PV.functionParameter.type.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -926,19 +1402,47 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.RATE.abstract',
functionParameter: [
{
- name: 'formula.functionList.RATE.functionParameter.number1.name',
- detail: 'formula.functionList.RATE.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.RATE.functionParameter.nper.name',
+ detail: 'formula.functionList.RATE.functionParameter.nper.detail',
+ example: '4*12',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.RATE.functionParameter.number2.name',
- detail: 'formula.functionList.RATE.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.RATE.functionParameter.pmt.name',
+ detail: 'formula.functionList.RATE.functionParameter.pmt.detail',
+ example: '-200',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.RATE.functionParameter.pv.name',
+ detail: 'formula.functionList.RATE.functionParameter.pv.detail',
+ example: '8000',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.RATE.functionParameter.fv.name',
+ detail: 'formula.functionList.RATE.functionParameter.fv.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.RATE.functionParameter.type.name',
+ detail: 'formula.functionList.RATE.functionParameter.type.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.RATE.functionParameter.guess.name',
+ detail: 'formula.functionList.RATE.functionParameter.guess.detail',
+ example: '0.1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
diff --git a/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts b/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts
index 1c15af3bcc..9503e75e9b 100644
--- a/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts
+++ b/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts
@@ -226,8 +226,17 @@ export class SheetSkeletonManagerService extends Disposable implements IRenderMo
export function attachRangeWithCoord(skeleton: SpreadsheetSkeleton, range: IRange): IRangeWithCoord {
const { startRow, startColumn, endRow, endColumn, rangeType } = range;
- const startCell = skeleton.getNoMergeCellPositionByIndex(startRow, startColumn);
- const endCell = skeleton.getNoMergeCellPositionByIndex(endRow, endColumn);
+
+ // after the selection is moved, it may be stored endRow < startRow or endColumn < startColumn
+ // so startCell and endCell need get min value to draw the selection
+ const _startRow = endRow < startRow ? endRow : startRow;
+ const _endRow = endRow < startRow ? startRow : endRow;
+
+ const _startColumn = endColumn < startColumn ? endColumn : startColumn;
+ const _endColumn = endColumn < startColumn ? startColumn : endColumn;
+
+ const startCell = skeleton.getNoMergeCellPositionByIndex(_startRow, _startColumn);
+ const endCell = skeleton.getNoMergeCellPositionByIndex(_endRow, _endColumn);
return {
startRow,