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 functions (#3137)

wpxp12345662bb41bf1236
diff --git a/packages/engine-formula/src/basics/date.ts b/packages/engine-formula/src/basics/date.ts
index a0fb5c3773..6913da6c68 100644
--- a/packages/engine-formula/src/basics/date.ts
+++ b/packages/engine-formula/src/basics/date.ts
@@ -349,7 +349,12 @@ 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) {
+interface ITwoDateDaysType {
+ days: number;
+ yearDays: number;
+}
+
+export function getTwoDateDaysByBasis(startDateSerialNumber: number, endDateSerialNumber: number, basis: number): ITwoDateDaysType {
switch (basis) {
case 0:
// U.S. (NASD) method 30/360.
@@ -380,7 +385,7 @@ export function getTwoDateDaysByBasis(startDateSerialNumber: number, endDateSeri
}
}
-function getDaysByNASD(startDateSerialNumber: number, endDateSerialNumber: number) {
+function getDaysByNASD(startDateSerialNumber: number, endDateSerialNumber: number): ITwoDateDaysType {
const startDateDate = excelSerialToDate(startDateSerialNumber);
const startYear = startDateSerialNumber > 0 ? startDateDate.getUTCFullYear() : 1900;
const startMonth = startDateSerialNumber > 0 ? startDateDate.getUTCMonth() + 1 : 1;
@@ -426,7 +431,7 @@ function getDaysByNASD(startDateSerialNumber: number, endDateSerialNumber: numbe
};
}
-function getDaysByActual(startDateSerialNumber: number, endDateSerialNumber: number) {
+function getDaysByActual(startDateSerialNumber: number, endDateSerialNumber: number): ITwoDateDaysType {
const startDateDate = excelSerialToDate(startDateSerialNumber);
const startYear = startDateSerialNumber > 0 ? startDateDate.getUTCFullYear() : 1900;
@@ -467,7 +472,7 @@ function getDaysByActual(startDateSerialNumber: number, endDateSerialNumber: num
};
}
-function getDaysByEuropean(startDateSerialNumber: number, endDateSerialNumber: number) {
+function getDaysByEuropean(startDateSerialNumber: number, endDateSerialNumber: number): ITwoDateDaysType {
const startDateDate = excelSerialToDate(startDateSerialNumber);
const startYear = startDateSerialNumber > 0 ? startDateDate.getUTCFullYear() : 1900;
const startMonth = startDateSerialNumber > 0 ? startDateDate.getUTCMonth() + 1 : 1;
@@ -498,3 +503,60 @@ function getDaysByEuropean(startDateSerialNumber: number, endDateSerialNumber: n
yearDays: 360,
};
}
+
+export function isLeapYear(year: number): boolean {
+ return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
+}
+
+export function isLeapYear1900(year: number): boolean {
+ return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0 || year === 1900;
+}
+
+const daysInMonthL = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+const daysInMonthR = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+
+export function getDaysInMonth(year: number, month: number): number {
+ return isLeapYear(year) ? daysInMonthL[month] : daysInMonthR[month];
+}
+
+export function getDaysInYear(year: number): number {
+ return isLeapYear1900(year) ? 366 : 365;
+}
+
+export function getNormalYearDaysByBasis(dateSerialNumber: number, basis: number): number {
+ switch (basis) {
+ case 0:
+ case 2:
+ case 4:
+ return 360;
+ case 1:
+ return getDaysInYear(excelSerialToDate(dateSerialNumber).getUTCFullYear());
+ case 3:
+ return 365;
+ default:
+ return -1;
+ }
+}
+
+export function lastDayOfMonth(year: number, month: number, day: number): boolean {
+ return getDaysInMonth(year, month) === day;
+}
+
+export function dateAddMonths(date: Date, months: number): Date {
+ let year = date.getUTCFullYear();
+ let month = date.getUTCMonth();
+ const day = date.getUTCDate();
+
+ if (lastDayOfMonth(year, month, day)) {
+ date.setUTCDate(1);
+ date.setUTCMonth(date.getUTCMonth() + months);
+
+ year = date.getUTCFullYear();
+ month = date.getUTCMonth();
+ date.setUTCDate(getDaysInMonth(year, month));
+ } else {
+ date.setUTCMonth(date.getUTCMonth() + months);
+ }
+
+ return date;
+}
diff --git a/packages/engine-formula/src/basics/financial.ts b/packages/engine-formula/src/basics/financial.ts
index 8f3ea6e268..90f2000561 100644
--- a/packages/engine-formula/src/basics/financial.ts
+++ b/packages/engine-formula/src/basics/financial.ts
@@ -14,6 +14,127 @@
* limitations under the License.
*/
+import { ErrorValueObject } from '../engine/value-object/base-value-object';
+import { dateAddMonths, excelDateSerial, excelSerialToDate, getDaysInMonth, getTwoDateDaysByBasis, lastDayOfMonth } from './date';
+import { ErrorType } from './error-type';
+
+export function calculateCoupdaybs(settlementSerialNumber: number, maturitySerialNumber: number, frequency: number, basis: number): number {
+ const coupDateSerialNumber = calculateCouppcd(settlementSerialNumber, maturitySerialNumber, frequency);
+
+ const { days } = getTwoDateDaysByBasis(coupDateSerialNumber, settlementSerialNumber, basis);
+
+ return days;
+}
+
+export function calculateCoupdays(settlementSerialNumber: number, maturitySerialNumber: number, frequency: number, basis: number): number {
+ let result;
+
+ if (basis === 1) {
+ const beforeSettlementDateSerialNumber = calculateCouppcd(settlementSerialNumber, maturitySerialNumber, frequency);
+
+ let coupDate = excelSerialToDate(beforeSettlementDateSerialNumber);
+ coupDate = dateAddMonths(coupDate, 12 / frequency);
+
+ const afterSettlementDateSerialNumber = excelDateSerial(coupDate);
+
+ // special handle for excel
+ if (beforeSettlementDateSerialNumber < 0 && frequency === 1) {
+ result = 365;
+ } else {
+ result = afterSettlementDateSerialNumber - beforeSettlementDateSerialNumber;
+ }
+ } else if (basis === 3) {
+ result = 365 / frequency;
+ } else {
+ result = 360 / frequency;
+ }
+
+ return result;
+}
+
+export function calculateCoupncd(settlementSerialNumber: number, maturitySerialNumber: number, frequency: number): number {
+ const settlementDate = excelSerialToDate(settlementSerialNumber);
+ let coupDate = excelSerialToDate(maturitySerialNumber);
+
+ coupDate.setUTCFullYear(settlementDate.getUTCFullYear());
+
+ if (coupDate < settlementDate) {
+ coupDate.setUTCFullYear(coupDate.getUTCFullYear() + 1);
+ }
+
+ while (coupDate > settlementDate) {
+ coupDate = dateAddMonths(coupDate, -12 / frequency);
+ }
+
+ coupDate = dateAddMonths(coupDate, 12 / frequency);
+
+ const coupDateSerialNumber = excelDateSerial(coupDate);
+
+ return coupDateSerialNumber;
+}
+
+export function calculateCoupnum(settlementSerialNumber: number, maturitySerialNumber: number, frequency: number): number {
+ let result = 0;
+
+ const settlementDate = excelSerialToDate(settlementSerialNumber);
+ let coupDate = excelSerialToDate(maturitySerialNumber);
+
+ while (coupDate > settlementDate) {
+ coupDate = dateAddMonths(coupDate, -12 / frequency);
+ result++;
+ }
+
+ return result;
+}
+
+export function calculateCouppcd(settlementSerialNumber: number, maturitySerialNumber: number, frequency: number): number {
+ const settlementDate = excelSerialToDate(settlementSerialNumber);
+ let coupDate = excelSerialToDate(maturitySerialNumber);
+
+ coupDate.setUTCFullYear(settlementDate.getUTCFullYear());
+
+ if (coupDate < settlementDate) {
+ coupDate.setUTCFullYear(coupDate.getUTCFullYear() + 1);
+ }
+
+ while (coupDate > settlementDate) {
+ coupDate = dateAddMonths(coupDate, -12 / frequency);
+ }
+
+ const coupDateSerialNumber = excelDateSerial(coupDate);
+
+ return coupDateSerialNumber;
+}
+
+export function calculateDuration(settlementSerialNumber: number, maturitySerialNumber: number, coupon: number, yld: number, frequency: number, basis: number): number {
+ const coupdaybs = calculateCoupdaybs(settlementSerialNumber, maturitySerialNumber, frequency, basis);
+ const coupdays = calculateCoupdays(settlementSerialNumber, maturitySerialNumber, frequency, basis);
+ const coupnum = calculateCoupnum(settlementSerialNumber, maturitySerialNumber, frequency);
+
+ const coupdaysDiff = (coupdays - coupdaybs) / coupdays - 1;
+ const _yld = yld / frequency + 1;
+ const _coupon = coupon * 100 / frequency;
+
+ let duration = 0;
+ let den = 0;
+
+ for (let i = 1; i <= coupnum; i++) {
+ const index = i + coupdaysDiff;
+ const num = _coupon / (_yld ** index);
+
+ duration += index * num;
+ den += num;
+ }
+
+ const index = coupnum + coupdaysDiff;
+ const num = 100 / (_yld ** index);
+
+ duration += index * num;
+ den += num;
+
+ return duration / den / frequency;
+}
+
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
@@ -40,6 +161,10 @@ export function calculateFV(rate: number, nper: number, pmt: number, pv: number,
if (rate === 0) {
result = pv + pmt * nper;
} else {
+ if (rate === -1 && nper === 0) {
+ return Number.NaN;
+ }
+
const term = (1 + rate) ** nper;
result = type === 1
@@ -61,3 +186,421 @@ export function calculateIPMT(rate: number, per: number, nper: number, pv: numbe
return result * rate;
}
+
+export function calculateNpv(rate: number, values: number[]): number {
+ let res = 0;
+
+ for (let i = 1; i <= values.length; i++) {
+ res += values[i - 1] / ((1 + rate) ** i);
+ }
+
+ return res;
+}
+
+export function calculateOddFPrice(
+ settlementSerialNumber: number,
+ maturitySerialNumber: number,
+ issueSerialNumber: number,
+ firstCouponSerialNumber: number,
+ rate: number,
+ yld: number,
+ redemption: number,
+ frequency: number,
+ basis: number
+): number {
+ // DFC = number of days from the beginning of the odd first coupon to the first coupon date.
+ const DFC = getPositiveDaysBetween(issueSerialNumber, firstCouponSerialNumber, basis);
+
+ // E = number of days in the coupon period.
+ const E = calculateCoupdays(settlementSerialNumber, firstCouponSerialNumber, frequency, basis);
+
+ if (DFC < E) {
+ return calculateOddShortFirstCoupon(
+ settlementSerialNumber,
+ maturitySerialNumber,
+ issueSerialNumber,
+ firstCouponSerialNumber,
+ rate,
+ yld,
+ redemption,
+ frequency,
+ basis,
+ DFC,
+ E
+ );
+ } else {
+ return calculateOddLongFirstCoupon(
+ settlementSerialNumber,
+ maturitySerialNumber,
+ issueSerialNumber,
+ firstCouponSerialNumber,
+ rate,
+ yld,
+ redemption,
+ frequency,
+ basis,
+ E
+ );
+ }
+}
+
+function calculateOddShortFirstCoupon(
+ settlementSerialNumber: number,
+ maturitySerialNumber: number,
+ issueSerialNumber: number,
+ firstCouponSerialNumber: number,
+ rate: number,
+ yld: number,
+ redemption: number,
+ frequency: number,
+ basis: number,
+ DFC: number,
+ E: number
+): number {
+ // calculate method from
+ // https://support.microsoft.com/en-us/office/oddfprice-function-d7d664a8-34df-4233-8d2b-922bcf6a69e1
+ // Odd short first coupon:
+ let result = 0;
+
+ // N = number of coupons payable between the settlement date and the redemption date. (If this number contains a fraction, it is raised to the next whole number.)
+ const N = calculateCoupnum(settlementSerialNumber, maturitySerialNumber, frequency);
+
+ // DSC = number of days from the settlement to the next coupon date.
+ const DSC = getPositiveDaysBetween(settlementSerialNumber, firstCouponSerialNumber, basis);
+
+ result += redemption / ((1 + yld / frequency) ** (N - 1 + DSC / E));
+
+ result += (100 * rate / frequency * DFC / E) / ((1 + yld / frequency) ** (DSC / E));
+
+ for (let k = 2; k <= N; k++) {
+ result += (100 * rate / frequency) / ((1 + yld / frequency) ** (k - 1 + DSC / E));
+ }
+
+ // A = number of days from the beginning of the coupon period to the settlement date (accrued days).
+ const A = getPositiveDaysBetween(issueSerialNumber, settlementSerialNumber, basis);
+
+ result -= 100 * rate / frequency * A / E;
+
+ return result;
+}
+
+function calculateOddLongFirstCoupon(
+ settlementSerialNumber: number,
+ maturitySerialNumber: number,
+ issueSerialNumber: number,
+ firstCouponSerialNumber: number,
+ rate: number,
+ yld: number,
+ redemption: number,
+ frequency: number,
+ basis: number,
+ E: number
+): number {
+ // calculate method from
+ // https://support.microsoft.com/en-us/office/oddfprice-function-d7d664a8-34df-4233-8d2b-922bcf6a69e1
+ // Odd long first coupon:
+ let result = 0;
+
+ // N = number of coupons payable between the first real coupon date and redemption date. (If this number contains a fraction, it is raised to the next whole number.)
+ const N = calculateCoupnum(firstCouponSerialNumber, maturitySerialNumber, frequency);
+
+ // Nq = number of whole quasi-coupon periods between settlement date and first coupon.
+ const Nq = getCouponsNumber(firstCouponSerialNumber, settlementSerialNumber, 12 / frequency, true);
+
+ // DSC = number of days from the settlement to the next coupon date.
+ let DSC;
+
+ if (basis === 2 || basis === 3) {
+ const coupncd = calculateCoupncd(settlementSerialNumber, firstCouponSerialNumber, frequency);
+ DSC = getPositiveDaysBetween(settlementSerialNumber, coupncd, basis);
+ } else {
+ const couppcd = calculateCouppcd(settlementSerialNumber, firstCouponSerialNumber, frequency);
+ const { days } = getTwoDateDaysByBasis(couppcd, settlementSerialNumber, basis);
+ DSC = E - days;
+ }
+
+ result += redemption / ((1 + yld / frequency) ** (N + Nq + DSC / E));
+
+ // NC = number of quasi-coupon periods that fit in odd period. (If this number contains a fraction, it is raised to the next whole number.)
+ const NC = calculateCoupnum(issueSerialNumber, firstCouponSerialNumber, frequency);
+
+ let lateCoupon = firstCouponSerialNumber;
+ let DCiDivNLiSum = 0;
+ let AiDivNLiSum = 0;
+
+ for (let index = NC; index >= 1; index--) {
+ const earlyCoupon = getDateSerialNumberByMonths(lateCoupon, -12 / frequency, false);
+ const NLi = basis === 1 ? getPositiveDaysBetween(earlyCoupon, lateCoupon, basis) : E;
+ const DCi = index > 1 ? NLi : getPositiveDaysBetween(issueSerialNumber, lateCoupon, basis);
+
+ DCiDivNLiSum += DCi / NLi;
+
+ const startDate = issueSerialNumber > earlyCoupon ? issueSerialNumber : earlyCoupon;
+ const endDate = settlementSerialNumber < lateCoupon ? settlementSerialNumber : lateCoupon;
+ const Ai = getPositiveDaysBetween(startDate, endDate, basis);
+
+ AiDivNLiSum += Ai / NLi;
+
+ lateCoupon = earlyCoupon;
+ }
+
+ result += (100 * rate / frequency * DCiDivNLiSum) / ((1 + yld / frequency) ** (Nq + DSC / E));
+
+ for (let k = 1; k <= N; k++) {
+ result += (100 * rate / frequency) / ((1 + yld / frequency) ** (k + Nq + DSC / E));
+ }
+
+ result -= 100 * rate / frequency * AiDivNLiSum;
+
+ return result;
+}
+
+function getPositiveDaysBetween(startDateSerialNumber: number, endDateSerialNumber: number, basis: number): number {
+ const { days } = getTwoDateDaysByBasis(startDateSerialNumber, endDateSerialNumber, basis);
+
+ return startDateSerialNumber < endDateSerialNumber ? days : 0;
+}
+
+export function validDaysBetweenIsWholeFrequencyByTwoDate(date1SerialNumber: number, date2SerialNumber: number, frequency: number): boolean {
+ const date1 = excelSerialToDate(date1SerialNumber);
+ const date1Year = date1.getUTCFullYear();
+ const date1Month = date1.getUTCMonth();
+ const date1Day = date1.getUTCDate();
+ const date1LastDayOfMonth = lastDayOfMonth(date1Year, date1Month, date1Day);
+
+ const date2 = excelSerialToDate(date2SerialNumber);
+ const date2Year = date2.getUTCFullYear();
+ const date2Month = date2.getUTCMonth();
+ const date2Day = date2.getUTCDate();
+ const date2LastDayOfMonth = lastDayOfMonth(date2Year, date2Month, date2Day);
+
+ if (date1Day !== date2Day && !(date1LastDayOfMonth && date2LastDayOfMonth)) {
+ return false;
+ }
+
+ const months = Math.abs((date2Year - date1Year) * 12 + (date2Month - date1Month));
+
+ if (months % (12 / frequency) !== 0) {
+ return false;
+ }
+
+ return true;
+}
+
+export function validCouppcdIsGte0ByTwoDate(date1SerialNumber: number, date2SerialNumber: number, frequency: number): boolean {
+ const couppcd = calculateCouppcd(date1SerialNumber, date2SerialNumber, frequency);
+ return couppcd >= 0;
+}
+
+export function getDateSerialNumberByMonths(serialNumber: number, months: number, returnLastDay: boolean): number {
+ let date = excelSerialToDate(serialNumber);
+ date = dateAddMonths(date, months);
+
+ if (returnLastDay) {
+ const year = date.getUTCFullYear();
+ const month = date.getUTCMonth();
+ const daysInMonth = getDaysInMonth(year, month);
+ date.setUTCDate(daysInMonth);
+ }
+
+ return excelDateSerial(date);
+}
+
+function getCouponsNumber(startDateSerialNumber: number, endDateSerialNumber: number, months: number, isWholeNumber: boolean): number {
+ const startDate = excelSerialToDate(startDateSerialNumber);
+ const endDate = excelSerialToDate(endDateSerialNumber);
+
+ const startDateYear = startDate.getUTCFullYear();
+ const startDateMonth = startDate.getUTCMonth();
+ const startDateDay = startDate.getUTCDate();
+
+ const endDateYear = endDate.getUTCFullYear();
+ const endDateMonth = endDate.getUTCMonth();
+ const endDateDay = endDate.getUTCDate();
+
+ const endOfMonthTemp = lastDayOfMonth(startDateYear, startDateMonth, startDateDay);
+ const endOfMonth = (!endOfMonthTemp && startDateMonth !== 1 && startDateDay > 28 && startDateDay < getDaysInMonth(startDateYear, startDateMonth))
+ ? lastDayOfMonth(endDateYear, endDateMonth, endDateDay)
+ : endOfMonthTemp;
+
+ const newDateSerialNumber = getDateSerialNumberByMonths(endDateSerialNumber, 0, endOfMonth);
+
+ let coupons = (+isWholeNumber - 0) + +(endDateSerialNumber < newDateSerialNumber);
+ let frontDateSerialNumber = getDateSerialNumberByMonths(newDateSerialNumber, months, endOfMonth);
+
+ while (!(months > 0 ? frontDateSerialNumber >= endDateSerialNumber : frontDateSerialNumber <= endDateSerialNumber)) {
+ frontDateSerialNumber = getDateSerialNumberByMonths(frontDateSerialNumber, months, endOfMonth);
+ coupons++;
+ }
+
+ return coupons;
+}
+
+interface IIterFFunctionType {
+ (x: number): number;
+}
+
+export function getResultByGuessIterF(guess: number, iterF: IIterFFunctionType): number | ErrorValueObject {
+ const g_Eps = 1e-7;
+ const g_Eps2 = g_Eps * 2;
+ const nIM = 500;
+
+ let eps = 1;
+ let nMC = 0;
+ let x = guess;
+ let xN;
+
+ while (eps > g_Eps && nMC < nIM) {
+ const den = (iterF(x + g_Eps) - iterF(x - g_Eps)) / g_Eps2;
+ xN = x - iterF(x) / den;
+ nMC++;
+ eps = Math.abs(xN - x);
+ x = xN;
+ }
+
+ if (Number.isNaN(x) || Infinity === Math.abs(x) || nMC === nIM) {
+ return guessIsNaNorInfinity(guess, iterF);
+ }
+
+ return x;
+}
+
+function guessIsNaNorInfinity(guess: number, iterF: IIterFFunctionType): number | ErrorValueObject {
+ const g_Eps = 1e-7;
+ const nIM = 60;
+
+ const max = Number.MAX_VALUE;
+ const min = -1;
+ const step = 1.6;
+
+ let low = guess - 0.01 <= min ? min + g_Eps : guess - 0.01;
+ let high = guess + 0.01 >= max ? max - g_Eps : guess + 0.01;
+ let xBegin;
+ let xEnd;
+ let currentIter = 0;
+
+ if (guess <= min || guess >= max) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ for (let i = 0; i < nIM; i++) {
+ xBegin = low <= min ? min + g_Eps : low;
+ xEnd = high >= max ? max - g_Eps : high;
+
+ const x = iterF(xBegin);
+ const y = iterF(xEnd);
+
+ if (x * y <= 0) {
+ break;
+ } else if (x * y > 0) {
+ low = (xBegin + step * (xBegin - xEnd));
+ high = (xEnd + step * (xEnd - xBegin));
+ } else {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (i === nIM - 1) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+ }
+
+ xBegin = xBegin as number;
+ xEnd = xEnd as number;
+
+ let fXbegin = iterF(xBegin);
+ const fXend = iterF(xEnd);
+ let fXi;
+ let xI;
+
+ if (Math.abs(fXbegin) < g_Eps) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (Math.abs(fXend) < g_Eps) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ do {
+ xI = xBegin + (xEnd - xBegin) / 2;
+ fXi = iterF(xI);
+
+ if (fXbegin * fXi < 0) {
+ xEnd = xI;
+ } else {
+ xBegin = xI;
+ }
+
+ fXbegin = iterF(xBegin);
+ currentIter++;
+ } while (Math.abs(fXi) > g_Eps && currentIter < nIM);
+
+ return xI;
+}
+
+export function calculatePrice(
+ settlementSerialNumber: number,
+ maturitySerialNumber: number,
+ rate: number,
+ yld: number,
+ redemption: number,
+ frequency: number,
+ basis: number
+): number {
+ // N is the number of coupons payable between the settlement date and redemption date
+ const N = calculateCoupnum(settlementSerialNumber, maturitySerialNumber, frequency);
+
+ // E = number of days in coupon period in which the settlement date falls.
+ const E = calculateCoupdays(settlementSerialNumber, maturitySerialNumber, frequency, basis);
+
+ // A = number of days from beginning of coupon period to settlement date.
+ const A = calculateCoupdaybs(settlementSerialNumber, maturitySerialNumber, frequency, basis);
+
+ if (N === 1) {
+ const DSR = E - A;
+ const T1 = 100 * rate / frequency + redemption;
+ const T2 = yld / frequency * DSR / E + 1;
+ const T3 = 100 * rate / frequency * A / E;
+
+ return T1 / T2 - T3;
+ }
+
+ const DSC = E - A;
+
+ let result = redemption / ((1 + yld / frequency) ** (N - 1 + DSC / E));
+
+ for (let k = 1; k <= N; k++) {
+ result += (100 * rate / frequency) / ((1 + yld / frequency) ** (k - 1 + DSC / E));
+ }
+
+ result -= 100 * rate / frequency * A / E;
+
+ return result;
+}
+
+export function calculateDDB(cost: number, salvage: number, life: number, period: number, factor: number): number {
+ let oldCost = 0;
+ let fdl = factor / life;
+
+ if (fdl >= 1) {
+ fdl = 1;
+ oldCost = period === 1 ? cost : 0;
+ } else {
+ oldCost = cost * ((1 - fdl) ** (period - 1));
+ }
+
+ const newCost = cost * ((1 - fdl) ** period);
+
+ let result = 0;
+
+ if (newCost < salvage) {
+ result = oldCost - salvage;
+ } else {
+ result = oldCost - newCost;
+ }
+
+ if (result < 0) {
+ result = 0;
+ }
+
+ return result;
+}
diff --git a/packages/engine-formula/src/engine/utils/check-variant-error.ts b/packages/engine-formula/src/engine/utils/check-variant-error.ts
index 103806b910..dac96f7c2a 100644
--- a/packages/engine-formula/src/engine/utils/check-variant-error.ts
+++ b/packages/engine-formula/src/engine/utils/check-variant-error.ts
@@ -66,6 +66,50 @@ export function checkVariantsErrorIsArrayOrBoolean(...variants: BaseValueObject[
};
}
+// All variants cannot be null.
+export function checkVariantsErrorIsNullorArrayOrBoolean(...variants: BaseValueObject[]) {
+ for (let i = 0; i < variants.length; i++) {
+ let variant = variants[i];
+
+ if (variant.isError()) {
+ return {
+ isError: true,
+ errorObject: variant,
+ };
+ }
+
+ if (variant.isNull()) {
+ return {
+ isError: true,
+ errorObject: ErrorValueObject.create(ErrorType.NA),
+ };
+ }
+
+ 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];
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
index 4123bbca82..6436bbf897 100644
--- a/packages/engine-formula/src/functions/financial/accrint/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/accrint/__tests__/index.spec.ts
@@ -40,7 +40,7 @@ describe('Test accrint function', () => {
const basis = NumberValueObject.create(1);
result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency, basis);
- expect(result.getValue()).toStrictEqual(16.939890710382514);
+ expect(result.getValue()).toStrictEqual(16.847826086956523);
});
it('value is normal, endDate < startDate', () => {
@@ -54,6 +54,30 @@ describe('Test accrint function', () => {
expect(result.getValue()).toStrictEqual(ErrorType.NUM);
});
+ it('Issue firstInterest settlement test', () => {
+ const issue = StringValueObject.create('1900/1/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 result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency);
+ expect(result.getValue()).toStrictEqual(0);
+
+ const issue2 = StringValueObject.create('2008/2/29');
+ const settlement2 = StringValueObject.create('2008/11/1');
+ const result2 = testFunction.calculate(issue2, firstInterest, settlement2, rate, par, frequency);
+ expect(result2.getValue()).toStrictEqual(66.94444444444446);
+
+ const basis = NumberValueObject.create(3);
+ const result3 = testFunction.calculate(issue2, firstInterest, settlement2, rate, par, frequency, basis);
+ expect(result3.getValue()).toStrictEqual(67.94520547945206);
+
+ const basis2 = NumberValueObject.create(1);
+ const result4 = testFunction.calculate(issue2, firstInterest, settlement2, rate, par, frequency, basis2);
+ expect(result4.getValue()).toStrictEqual(68.20652173913044);
+ });
+
it('value is error', () => {
const issue = NumberValueObject.create(1);
const firstInterest = StringValueObject.create('2008/8/31');
@@ -90,6 +114,19 @@ describe('Test accrint function', () => {
const frequency = NumberValueObject.create(2);
const result = testFunction.calculate(issue, firstInterest, settlement, rate, par, frequency);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const issue2 = StringValueObject.create('2008/2/29');
+ const firstInterest2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(issue2, firstInterest2, settlement, rate, par, frequency);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(issue2, firstInterest, settlement2, rate, par, frequency);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(issue2, firstInterest, settlement, rate2, par, frequency);
+ expect(result4.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('rate or par value less than or equal to 0', () => {
diff --git a/packages/engine-formula/src/functions/financial/accrint/index.ts b/packages/engine-formula/src/functions/financial/accrint/index.ts
index c23b107873..aa8d4518c6 100644
--- a/packages/engine-formula/src/functions/financial/accrint/index.ts
+++ b/packages/engine-formula/src/functions/financial/accrint/index.ts
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-import { getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
+import { excelSerialToDate, getDateSerialNumberByObject, getTwoDateDaysByBasis, lastDayOfMonth } from '../../../basics/date';
import { ErrorType } from '../../../basics/error-type';
+import { calculateCoupdays, calculateCouppcd, getDateSerialNumberByMonths } from '../../../basics/financial';
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';
@@ -35,7 +36,7 @@ export class Accrint extends BaseFunction {
frequency: BaseValueObject,
basis?: BaseValueObject,
calcMethod?: BaseValueObject
- ) {
+ ): BaseValueObject {
const _basis = basis ?? NumberValueObject.create(0);
const _calcMethod = calcMethod ?? BooleanValueObject.create(true);
@@ -99,31 +100,72 @@ export class Accrint extends BaseFunction {
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);
+ let couppcd = calculateCouppcd(issueSerialNumber, firstInterestSerialNumber, frequencyValue);
+ if (couppcd <= 0) {
+ return NumberValueObject.create(0);
+ }
+ couppcd = calculateCouppcd(settlementSerialNumber, firstInterestSerialNumber, frequencyValue);
+
+ const numMonths = 12 / frequencyValue;
+ const firstInterestDate = excelSerialToDate(firstInterestSerialNumber);
+ const firstInterestDateYear = firstInterestDate.getUTCFullYear();
+ const firstInterestDateMonth = firstInterestDate.getUTCMonth();
+ const firstInterestDateDay = firstInterestDate.getUTCDate();
+ const lastDayOfMonthF = lastDayOfMonth(firstInterestDateYear, firstInterestDateMonth, firstInterestDateDay);
+
+ let coupDateSerialNumber = getDateSerialNumberByMonths(firstInterestSerialNumber, -numMonths, lastDayOfMonthF);
+ if (settlementSerialNumber > firstInterestSerialNumber && calcMethodValue) {
+ coupDateSerialNumber = firstInterestSerialNumber;
+ while (coupDateSerialNumber < settlementSerialNumber) {
+ coupDateSerialNumber = getDateSerialNumberByMonths(coupDateSerialNumber, numMonths, lastDayOfMonthF);
+ }
}
- const { days, yearDays } = TwoDateDays;
+ let firstDateSerialNumber = issueSerialNumber > coupDateSerialNumber ? issueSerialNumber : coupDateSerialNumber;
- const NC = Math.ceil((days / yearDays) * frequencyValue);
- const NLi = yearDays / frequencyValue;
+ let { days } = getTwoDateDaysByBasis(firstDateSerialNumber, settlementSerialNumber, basisValue);
+ if (couppcd >= issueSerialNumber) {
+ const { days: DFS } = getTwoDateDaysByBasis(firstDateSerialNumber, settlementSerialNumber, !basisValue ? 0 : 4);
+ days = DFS;
+ }
+ if (settlementSerialNumber < firstDateSerialNumber) {
+ days = -days;
+ }
- let accruedDaysSum = 0;
- for (let i = 1; i <= NC; i++) {
- if (i * NLi > days) {
- const Ai = days - (i - 1) * NLi;
- accruedDaysSum += Ai / NLi;
+ let coupdays = calculateCoupdays(coupDateSerialNumber, firstInterestSerialNumber, frequencyValue, basisValue);
+ let accruedDaysSum = days / coupdays;
+ let startDateSerialNumber = coupDateSerialNumber;
+ let endDateSerialNumber = issueSerialNumber;
+
+ while (startDateSerialNumber > issueSerialNumber) {
+ endDateSerialNumber = startDateSerialNumber;
+ startDateSerialNumber = getDateSerialNumberByMonths(startDateSerialNumber, -numMonths, lastDayOfMonthF);
+ firstDateSerialNumber = issueSerialNumber > startDateSerialNumber ? issueSerialNumber : startDateSerialNumber;
+ const { days: DFE } = getTwoDateDaysByBasis(firstDateSerialNumber, endDateSerialNumber, basisValue);
+
+ if (basisValue === 0) {
+ if (endDateSerialNumber >= firstDateSerialNumber || issueSerialNumber <= startDateSerialNumber) {
+ days = DFE;
+ } else {
+ days = -DFE;
+ }
+
+ coupdays = calculateCoupdays(startDateSerialNumber, endDateSerialNumber, frequencyValue, basisValue);
} else {
- accruedDaysSum += 1;
+ days = endDateSerialNumber < firstDateSerialNumber ? -DFE : DFE;
+
+ if (basisValue === 3) {
+ coupdays = 365 / frequencyValue;
+ } else {
+ const { days: DSE } = getTwoDateDaysByBasis(startDateSerialNumber, endDateSerialNumber, basisValue);
+ coupdays = endDateSerialNumber < startDateSerialNumber ? -DSE : DSE;
+ }
}
+
+ accruedDaysSum += (issueSerialNumber <= startDateSerialNumber) ? (calcMethodValue ? 1 : 0) : days / coupdays;
}
- // TODO: The results are not very accurate now.
- const result = parValue * (rateValue / frequencyValue) * accruedDaysSum;
+ 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
index ca311965ca..642e573d96 100644
--- a/packages/engine-formula/src/functions/financial/accrintm/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/accrintm/__tests__/index.spec.ts
@@ -41,13 +41,18 @@ describe('Test accrintm function', () => {
expect(result.getValue()).toStrictEqual(910.2107856556255);
});
- it('value is normal, endDate < startDate', () => {
+ it('value is normal, settlement <= issue', () => {
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);
+
+ const issue2 = StringValueObject.create('2012/2/2');
+ const settlement2 = StringValueObject.create('2012/2/2');
+ const result2 = testFunction.calculate(issue2, settlement2, rate, par);
+ expect(result2.getValue()).toStrictEqual(0);
});
it('value is error', () => {
@@ -80,6 +85,15 @@ describe('Test accrintm function', () => {
const par = NumberValueObject.create(1000);
const result = testFunction.calculate(issue, settlement, rate, par);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const issue2 = StringValueObject.create('2012/2/2');
+ const settlement2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(issue2, settlement2, rate, par);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(issue2, settlement, rate2, par);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('rate or par value less than or equal to 0', () => {
diff --git a/packages/engine-formula/src/functions/financial/accrintm/index.ts b/packages/engine-formula/src/functions/financial/accrintm/index.ts
index 27ddb18c4b..c65192d0a2 100644
--- a/packages/engine-formula/src/functions/financial/accrintm/index.ts
+++ b/packages/engine-formula/src/functions/financial/accrintm/index.ts
@@ -26,7 +26,7 @@ export class Accrintm extends BaseFunction {
override maxParams = 5;
- override calculate(issue: BaseValueObject, settlement: BaseValueObject, rate: BaseValueObject, par: BaseValueObject, basis?: BaseValueObject) {
+ override calculate(issue: BaseValueObject, settlement: BaseValueObject, rate: BaseValueObject, par: BaseValueObject, basis?: BaseValueObject): BaseValueObject {
const _basis = basis ?? NumberValueObject.create(0);
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(issue, settlement, rate, par, _basis);
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
index fc7aacd38e..479f284775 100644
--- a/packages/engine-formula/src/functions/financial/amorlinc/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/amorlinc/__tests__/index.spec.ts
@@ -38,6 +38,18 @@ describe('Test amorlinc function', () => {
expect(result.getValue()).toStrictEqual(360);
});
+ it('Value is normal, life < 0', () => {
+ const cost = NumberValueObject.create(2400);
+ const datePurchased = StringValueObject.create('2008/8/19');
+ const firstPeriod = StringValueObject.create('2009/12/31');
+ const salvage = NumberValueObject.create(2100);
+ const period = NumberValueObject.create(1);
+ const rate = NumberValueObject.create(0.6);
+ const basis = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis);
+ expect(result.getValue()).toStrictEqual(0);
+ });
+
it('Cost is normal string', () => {
const cost = StringValueObject.create('test');
const datePurchased = StringValueObject.create('2008/8/19');
@@ -48,6 +60,15 @@ describe('Test amorlinc function', () => {
const basis = NumberValueObject.create(0);
const result = testFunction.calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const cost2 = NumberValueObject.create(2400);
+ const datePurchased2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(cost2, datePurchased2, firstPeriod, salvage, period, rate, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const firstPeriod2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(cost2, datePurchased, firstPeriod2, salvage, period, rate, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('Cost <= 0 or salvage < 0 or cost < salvage', () => {
diff --git a/packages/engine-formula/src/functions/financial/amorlinc/index.ts b/packages/engine-formula/src/functions/financial/amorlinc/index.ts
index 8b732a3f6c..b1c9c4c45f 100644
--- a/packages/engine-formula/src/functions/financial/amorlinc/index.ts
+++ b/packages/engine-formula/src/functions/financial/amorlinc/index.ts
@@ -34,7 +34,7 @@ export class Amorlinc extends BaseFunction {
period: BaseValueObject,
rate: BaseValueObject,
basis?: BaseValueObject
- ) {
+ ): BaseValueObject {
const _basis = basis ?? NumberValueObject.create(0);
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(cost, datePurchased, firstPeriod, salvage, period, rate, _basis);
@@ -104,7 +104,7 @@ export class Amorlinc extends BaseFunction {
const life = Math.ceil(totalDepreciation / baseDepreciation - firstPeriodYearsFraction);
if (life < 0) {
- return NumberValueObject.create(costValue);
+ return NumberValueObject.create(0);
}
let result = baseDepreciation;
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
index 8465b76c93..9f5773d1b8 100644
--- a/packages/engine-formula/src/functions/financial/coupdaybs/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/coupdaybs/__tests__/index.spec.ts
@@ -112,6 +112,15 @@ describe('Test coupdaybs function', () => {
const basis = NumberValueObject.create(1);
const result = testFunction.calculate(settlement, maturity, frequency, basis);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2011-1-25');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const frequency2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, frequency2, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('Value is array', () => {
diff --git a/packages/engine-formula/src/functions/financial/coupdaybs/index.ts b/packages/engine-formula/src/functions/financial/coupdaybs/index.ts
index 585fd13c0d..9488c10301 100644
--- a/packages/engine-formula/src/functions/financial/coupdaybs/index.ts
+++ b/packages/engine-formula/src/functions/financial/coupdaybs/index.ts
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
+import { getDateSerialNumberByObject } from '../../../basics/date';
import { ErrorType } from '../../../basics/error-type';
+import { calculateCoupdaybs } from '../../../basics/financial';
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';
@@ -26,7 +27,7 @@ export class Coupdaybs extends BaseFunction {
override maxParams = 4;
- override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject): BaseValueObject {
const _basis = basis ?? NumberValueObject.create(0);
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
@@ -65,29 +66,8 @@ export class Coupdaybs extends BaseFunction {
return ErrorValueObject.create(ErrorType.NUM);
}
- const settlementDate = excelSerialToDate(settlementSerialNumber);
- const coupDate = excelSerialToDate(maturitySerialNumber);
+ const result = calculateCoupdaybs(settlementSerialNumber, maturitySerialNumber, frequencyValue, basisValue);
- 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);
+ return NumberValueObject.create(result);
}
}
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
index a36e853662..e528e36bbf 100644
--- a/packages/engine-formula/src/functions/financial/coupdays/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/coupdays/__tests__/index.spec.ts
@@ -112,6 +112,15 @@ describe('Test coupdays function', () => {
const basis = NumberValueObject.create(1);
const result = testFunction.calculate(settlement, maturity, frequency, basis);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2011-1-25');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const frequency2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, frequency2, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('Value is array', () => {
diff --git a/packages/engine-formula/src/functions/financial/coupdays/index.ts b/packages/engine-formula/src/functions/financial/coupdays/index.ts
index 05377c7fd3..12a9a4bf35 100644
--- a/packages/engine-formula/src/functions/financial/coupdays/index.ts
+++ b/packages/engine-formula/src/functions/financial/coupdays/index.ts
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject } from '../../../basics/date';
+import { getDateSerialNumberByObject } from '../../../basics/date';
import { ErrorType } from '../../../basics/error-type';
+import { calculateCoupdays } from '../../../basics/financial';
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';
@@ -26,7 +27,7 @@ export class Coupdays extends BaseFunction {
override maxParams = 4;
- override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject): BaseValueObject {
const _basis = basis ?? NumberValueObject.create(0);
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
@@ -65,40 +66,7 @@ export class Coupdays extends BaseFunction {
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;
- }
+ const result = calculateCoupdays(settlementSerialNumber, maturitySerialNumber, frequencyValue, basisValue);
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
index a6a843a422..3cc75b90a1 100644
--- a/packages/engine-formula/src/functions/financial/coupdaysnc/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/coupdaysnc/__tests__/index.spec.ts
@@ -36,13 +36,20 @@ describe('Test coupdaysnc function', () => {
expect(result.getValue()).toStrictEqual(110);
});
- it('Value is normal, settlement >= maturity', () => {
+ it('Value is normal, settlement and maturity test', () => {
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);
+
+ const settlement2 = StringValueObject.create('2011-11-25');
+ const maturity2 = StringValueObject.create('2014-3-15');
+ const frequency2 = NumberValueObject.create(2);
+ const basis2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement2, maturity2, frequency2, basis2);
+ expect(result2.getValue()).toStrictEqual(111);
});
it('Frequency value test', () => {
@@ -112,6 +119,15 @@ describe('Test coupdaysnc function', () => {
const basis = NumberValueObject.create(1);
const result = testFunction.calculate(settlement, maturity, frequency, basis);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2011-1-25');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const frequency2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, frequency2, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('Value is array', () => {
diff --git a/packages/engine-formula/src/functions/financial/coupdaysnc/index.ts b/packages/engine-formula/src/functions/financial/coupdaysnc/index.ts
index b8c3038420..695752cb3f 100644
--- a/packages/engine-formula/src/functions/financial/coupdaysnc/index.ts
+++ b/packages/engine-formula/src/functions/financial/coupdaysnc/index.ts
@@ -26,7 +26,7 @@ export class Coupdaysnc extends BaseFunction {
override maxParams = 4;
- override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject): BaseValueObject {
const _basis = basis ?? NumberValueObject.create(0);
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
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
index 970bc2c811..92fc4816f7 100644
--- a/packages/engine-formula/src/functions/financial/coupncd/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/coupncd/__tests__/index.spec.ts
@@ -112,6 +112,15 @@ describe('Test coupncd function', () => {
const basis = NumberValueObject.create(1);
const result = testFunction.calculate(settlement, maturity, frequency, basis);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2011-1-25');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const frequency2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, frequency2, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('Value is array', () => {
diff --git a/packages/engine-formula/src/functions/financial/coupncd/index.ts b/packages/engine-formula/src/functions/financial/coupncd/index.ts
index 02adb58617..d9ab797e04 100644
--- a/packages/engine-formula/src/functions/financial/coupncd/index.ts
+++ b/packages/engine-formula/src/functions/financial/coupncd/index.ts
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject } from '../../../basics/date';
+import { getDateSerialNumberByObject } from '../../../basics/date';
import { ErrorType } from '../../../basics/error-type';
+import { calculateCoupncd } from '../../../basics/financial';
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';
@@ -26,7 +27,7 @@ export class Coupncd extends BaseFunction {
override maxParams = 4;
- override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject): BaseValueObject {
const _basis = basis ?? NumberValueObject.create(0);
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
@@ -65,24 +66,8 @@ export class Coupncd extends BaseFunction {
return ErrorValueObject.create(ErrorType.NUM);
}
- const settlementDate = excelSerialToDate(settlementSerialNumber);
- const coupDate = excelSerialToDate(maturitySerialNumber);
+ const result = calculateCoupncd(settlementSerialNumber, maturitySerialNumber, frequencyValue);
- 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);
+ return NumberValueObject.create(result);
}
}
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
index 1abaa249ae..0f66a57b36 100644
--- a/packages/engine-formula/src/functions/financial/coupnum/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/coupnum/__tests__/index.spec.ts
@@ -36,13 +36,20 @@ describe('Test coupnum function', () => {
expect(result.getValue()).toStrictEqual(2);
});
- it('Value is normal, settlement >= maturity', () => {
+ it('Value is normal, settlement and maturity test', () => {
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);
+
+ const settlement2 = NumberValueObject.create(1);
+ const maturity2 = StringValueObject.create('2011-11-15');
+ const frequency2 = NumberValueObject.create(2);
+ const basis2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement2, maturity2, frequency2, basis2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
});
it('Frequency value test', () => {
@@ -112,6 +119,15 @@ describe('Test coupnum function', () => {
const basis = NumberValueObject.create(1);
const result = testFunction.calculate(settlement, maturity, frequency, basis);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2011-1-25');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const frequency2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, frequency2, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('Value is array', () => {
diff --git a/packages/engine-formula/src/functions/financial/coupnum/index.ts b/packages/engine-formula/src/functions/financial/coupnum/index.ts
index 3512c73e98..7c174c4c5d 100644
--- a/packages/engine-formula/src/functions/financial/coupnum/index.ts
+++ b/packages/engine-formula/src/functions/financial/coupnum/index.ts
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject } from '../../../basics/date';
+import { getDateSerialNumberByObject } from '../../../basics/date';
import { ErrorType } from '../../../basics/error-type';
+import { calculateCoupnum, calculateCouppcd } from '../../../basics/financial';
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';
@@ -26,7 +27,7 @@ export class Coupnum extends BaseFunction {
override maxParams = 4;
- override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject): BaseValueObject {
const _basis = basis ?? NumberValueObject.create(0);
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
@@ -65,24 +66,15 @@ export class Coupnum extends BaseFunction {
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);
+ const coupDateSerialNumber = calculateCouppcd(settlementSerialNumber, maturitySerialNumber, frequencyValue);
// special handle for excel
if (coupDateSerialNumber < 0) {
return ErrorValueObject.create(ErrorType.NUM);
}
+ const result = calculateCoupnum(settlementSerialNumber, maturitySerialNumber, frequencyValue);
+
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
index 659c4745c9..c73a3bc78f 100644
--- a/packages/engine-formula/src/functions/financial/couppcd/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/couppcd/__tests__/index.spec.ts
@@ -36,13 +36,18 @@ describe('Test couppcd function', () => {
expect(result.getValue()).toStrictEqual(40497);
});
- it('Value is normal, settlement >= maturity', () => {
+ it('Value is normal, settlement and maturity test', () => {
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);
+
+ const settlement2 = NumberValueObject.create(1);
+ const maturity2 = StringValueObject.create('2011-11-15');
+ const result2 = testFunction.calculate(settlement2, maturity2, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(0);
});
it('Frequency value test', () => {
@@ -112,6 +117,15 @@ describe('Test couppcd function', () => {
const basis = NumberValueObject.create(1);
const result = testFunction.calculate(settlement, maturity, frequency, basis);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2011-1-25');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const frequency2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, frequency2, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('Value is array', () => {
diff --git a/packages/engine-formula/src/functions/financial/couppcd/index.ts b/packages/engine-formula/src/functions/financial/couppcd/index.ts
index 40e8b0e4e5..fe2c77134c 100644
--- a/packages/engine-formula/src/functions/financial/couppcd/index.ts
+++ b/packages/engine-formula/src/functions/financial/couppcd/index.ts
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-import { excelDateSerial, excelSerialToDate, getDateSerialNumberByObject } from '../../../basics/date';
+import { getDateSerialNumberByObject } from '../../../basics/date';
import { ErrorType } from '../../../basics/error-type';
+import { calculateCouppcd } from '../../../basics/financial';
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';
@@ -26,7 +27,7 @@ export class Couppcd extends BaseFunction {
override maxParams = 4;
- override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject) {
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, frequency: BaseValueObject, basis?: BaseValueObject): BaseValueObject {
const _basis = basis ?? NumberValueObject.create(0);
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, frequency, _basis);
@@ -65,27 +66,13 @@ export class Couppcd extends BaseFunction {
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);
+ let result = calculateCouppcd(settlementSerialNumber, maturitySerialNumber, frequencyValue);
// special handle for excel
- if (coupDateSerialNumber < 0) {
- coupDateSerialNumber = 0;
+ if (result < 0) {
+ result = 0;
}
- return NumberValueObject.create(coupDateSerialNumber);
+ return NumberValueObject.create(result);
}
}
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
index 60885b742b..b007bc33d5 100644
--- a/packages/engine-formula/src/functions/financial/cumipmt/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/cumipmt/__tests__/index.spec.ts
@@ -84,6 +84,11 @@ describe('Test cumipmt function', () => {
const endPeriod3 = NumberValueObject.create(2);
const result3 = testFunction.calculate(rate, nper, pv, startPeriod3, endPeriod3, type);
expect(result3.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const startPeriod4 = NumberValueObject.create(1.1);
+ const endPeriod4 = NumberValueObject.create(1.1);
+ const result4 = testFunction.calculate(rate, nper, pv, startPeriod4, endPeriod4, type);
+ expect(result4.getValue()).toStrictEqual(0);
});
it('Type value is not 0 or 1', () => {
diff --git a/packages/engine-formula/src/functions/financial/cumipmt/index.ts b/packages/engine-formula/src/functions/financial/cumipmt/index.ts
index 045d7db534..e4a8e1f4a0 100644
--- a/packages/engine-formula/src/functions/financial/cumipmt/index.ts
+++ b/packages/engine-formula/src/functions/financial/cumipmt/index.ts
@@ -27,7 +27,7 @@ export class Cumipmt extends BaseFunction {
override maxParams = 6;
- override calculate(rate: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, startPeriod: BaseValueObject, endPeriod: BaseValueObject, type: BaseValueObject) {
+ override calculate(rate: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, startPeriod: BaseValueObject, endPeriod: BaseValueObject, type: BaseValueObject): BaseValueObject {
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(rate, nper, pv, startPeriod, endPeriod, type);
if (isError) {
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
index 4b07d4b985..213c00c6a6 100644
--- a/packages/engine-formula/src/functions/financial/cumprinc/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/cumprinc/__tests__/index.spec.ts
@@ -84,6 +84,11 @@ describe('Test cumprinc function', () => {
const endPeriod3 = NumberValueObject.create(2);
const result3 = testFunction.calculate(rate, nper, pv, startPeriod3, endPeriod3, type);
expect(result3.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const startPeriod4 = NumberValueObject.create(1.1);
+ const endPeriod4 = NumberValueObject.create(1.1);
+ const result4 = testFunction.calculate(rate, nper, pv, startPeriod4, endPeriod4, type);
+ expect(result4.getValue()).toStrictEqual(0);
});
it('Type value is not 0 or 1', () => {
diff --git a/packages/engine-formula/src/functions/financial/cumprinc/index.ts b/packages/engine-formula/src/functions/financial/cumprinc/index.ts
index f2f7199a86..f01fb1f1d4 100644
--- a/packages/engine-formula/src/functions/financial/cumprinc/index.ts
+++ b/packages/engine-formula/src/functions/financial/cumprinc/index.ts
@@ -27,7 +27,7 @@ export class Cumprinc extends BaseFunction {
override maxParams = 6;
- override calculate(rate: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, startPeriod: BaseValueObject, endPeriod: BaseValueObject, type: BaseValueObject) {
+ override calculate(rate: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, startPeriod: BaseValueObject, endPeriod: BaseValueObject, type: BaseValueObject): BaseValueObject {
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(rate, nper, pv, startPeriod, endPeriod, type);
if (isError) {
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
index ae9520d9b7..76c7dd40ec 100644
--- a/packages/engine-formula/src/functions/financial/db/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/db/__tests__/index.spec.ts
@@ -18,7 +18,7 @@ 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 { NullValueObject, 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';
@@ -41,7 +41,7 @@ describe('Test db function', () => {
const salvage = NumberValueObject.create(1000000);
const life = NumberValueObject.create(6);
const period = NumberValueObject.create(1);
- const month = NumberValueObject.create(7);
+ const month = NullValueObject.create();
const result = testFunction.calculate(cost, salvage, life, period, month);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
});
@@ -82,6 +82,14 @@ describe('Test db function', () => {
const period3 = NumberValueObject.create(7);
const result3 = testFunction.calculate(cost, salvage, life, period3, month);
expect(result3.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const period4 = NumberValueObject.create(0.1);
+ const result4 = testFunction.calculate(cost, salvage, life, period4, month);
+ expect(result4.getValue()).toStrictEqual(1860833.3333333333);
+
+ const period5 = NumberValueObject.create(2);
+ const result5 = testFunction.calculate(cost, salvage, life, period5, month);
+ expect(result5.getValue()).toStrictEqual(2596394.166666667);
});
it('value is array', () => {
diff --git a/packages/engine-formula/src/functions/financial/db/index.ts b/packages/engine-formula/src/functions/financial/db/index.ts
index f017274201..ed07858caa 100644
--- a/packages/engine-formula/src/functions/financial/db/index.ts
+++ b/packages/engine-formula/src/functions/financial/db/index.ts
@@ -27,7 +27,7 @@ export class Db extends BaseFunction {
override maxParams = 5;
- override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject, period: BaseValueObject, month?: BaseValueObject) {
+ override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject, period: BaseValueObject, month?: BaseValueObject): BaseValueObject {
let _month = month ?? NumberValueObject.create(12);
if (_month.isNull()) {
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
index 69123b214d..179a5e82d1 100644
--- a/packages/engine-formula/src/functions/financial/ddb/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/ddb/__tests__/index.spec.ts
@@ -18,7 +18,7 @@ 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 { NullValueObject, 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';
@@ -33,7 +33,7 @@ describe('Test ddb function', () => {
const period = NumberValueObject.create(1);
const factor = NumberValueObject.create(2);
const result = testFunction.calculate(cost, salvage, life, period, factor);
- expect(result.getValue()).toStrictEqual(8000);
+ expect(result.getValue()).toStrictEqual(7999.999999999998);
});
it('Cost is normal string', () => {
@@ -41,7 +41,7 @@ describe('Test ddb function', () => {
const salvage = NumberValueObject.create(3000);
const life = NumberValueObject.create(6);
const period = NumberValueObject.create(1);
- const factor = NumberValueObject.create(2);
+ const factor = NullValueObject.create();
const result = testFunction.calculate(cost, salvage, life, period, factor);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
});
@@ -77,7 +77,7 @@ describe('Test ddb function', () => {
const period2 = NumberValueObject.create(6);
const result2 = testFunction.calculate(cost, salvage, life, period2, factor);
- expect(result2.getValue()).toStrictEqual(160.49382716049513);
+ expect(result2.getValue()).toStrictEqual(160.49382716049558);
const period3 = NumberValueObject.create(7);
const result3 = testFunction.calculate(cost, salvage, life, period3, factor);
@@ -102,7 +102,7 @@ describe('Test ddb function', () => {
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],
+ [7999.999999999998, 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
index 643ada5349..a8e1db37f0 100644
--- a/packages/engine-formula/src/functions/financial/ddb/index.ts
+++ b/packages/engine-formula/src/functions/financial/ddb/index.ts
@@ -21,13 +21,14 @@ 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';
+import { calculateDDB } from '../../../basics/financial';
export class Ddb extends BaseFunction {
override minParams = 4;
override maxParams = 5;
- override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject, period: BaseValueObject, factor?: BaseValueObject) {
+ override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject, period: BaseValueObject, factor?: BaseValueObject): BaseValueObject {
let _factor = factor ?? NumberValueObject.create(2);
if (_factor.isNull()) {
@@ -73,7 +74,7 @@ export class Ddb extends BaseFunction {
const costValue = +_costObject.getValue();
const salvageValue = +_salvageObject.getValue();
const lifeValue = +_lifeObject.getValue();
- const periodValue = Math.ceil(+_periodObject.getValue());
+ const periodValue = +_periodObject.getValue();
const factorValue = +_factorObject.getValue();
if (
@@ -81,13 +82,23 @@ export class Ddb extends BaseFunction {
salvageValue < 0 ||
lifeValue <= 0 ||
periodValue <= 0 ||
- Math.floor(periodValue) > Math.floor(lifeValue) ||
+ periodValue > lifeValue ||
factorValue <= 0
) {
return ErrorValueObject.create(ErrorType.NUM);
}
- return this._getResult(costValue, salvageValue, lifeValue, periodValue, factorValue, rowIndex, columnIndex);
+ const result = calculateDDB(costValue, salvageValue, lifeValue, periodValue, factorValue);
+
+ 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)');
+ }
+
+ return NumberValueObject.create(result);
});
if (maxRowLength === 1 && maxColumnLength === 1) {
@@ -96,34 +107,4 @@ export class Ddb extends BaseFunction {
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
index 595ef82e4c..ce272cbc32 100644
--- a/packages/engine-formula/src/functions/financial/disc/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/disc/__tests__/index.spec.ts
@@ -101,6 +101,15 @@ describe('Test disc function', () => {
const basis = NumberValueObject.create(1);
const result = testFunction.calculate(settlement, maturity, pr, redemption, basis);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2018-7-1');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, pr, redemption, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const basis2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, pr, redemption, basis2);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('Value is array', () => {
diff --git a/packages/engine-formula/src/functions/financial/disc/index.ts b/packages/engine-formula/src/functions/financial/disc/index.ts
index eca19aef60..f7ff47bb6b 100644
--- a/packages/engine-formula/src/functions/financial/disc/index.ts
+++ b/packages/engine-formula/src/functions/financial/disc/index.ts
@@ -26,7 +26,7 @@ export class Disc extends BaseFunction {
override maxParams = 5;
- override calculate(settlement: BaseValueObject, maturity: BaseValueObject, pr: BaseValueObject, redemption: BaseValueObject, basis?: BaseValueObject) {
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, pr: BaseValueObject, redemption: BaseValueObject, basis?: BaseValueObject): BaseValueObject {
const _basis = basis ?? NumberValueObject.create(0);
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, pr, redemption, _basis);
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
index aca801ec3a..27f2bf1661 100644
--- a/packages/engine-formula/src/functions/financial/dollarde/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/dollarde/__tests__/index.spec.ts
@@ -34,6 +34,17 @@ describe('Test dollarde function', () => {
expect(result.getValue()).toStrictEqual(1.125);
});
+ it('Fraction value test', () => {
+ const fractionalDollar = NumberValueObject.create(1.02);
+ let fraction = NumberValueObject.create(-1);
+ let result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ fraction = NumberValueObject.create(0.1);
+ result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.DIV_BY_ZERO);
+ });
+
it('Value is error', () => {
const fractionalDollar = ErrorValueObject.create(ErrorType.NAME);
const fraction = NumberValueObject.create(16);
diff --git a/packages/engine-formula/src/functions/financial/dollarde/index.ts b/packages/engine-formula/src/functions/financial/dollarde/index.ts
index 8efc356af5..4ace4cf508 100644
--- a/packages/engine-formula/src/functions/financial/dollarde/index.ts
+++ b/packages/engine-formula/src/functions/financial/dollarde/index.ts
@@ -25,7 +25,7 @@ export class Dollarde extends BaseFunction {
override maxParams = 2;
- override calculate(fractionalDollar: BaseValueObject, fraction: BaseValueObject) {
+ override calculate(fractionalDollar: BaseValueObject, fraction: BaseValueObject): BaseValueObject {
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(fractionalDollar, fraction);
if (isError) {
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
index ddbf1c202e..a7355299ae 100644
--- a/packages/engine-formula/src/functions/financial/dollarfr/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/dollarfr/__tests__/index.spec.ts
@@ -34,6 +34,17 @@ describe('Test dollarfr function', () => {
expect(result.getValue()).toStrictEqual(1.0032);
});
+ it('Fraction value test', () => {
+ const fractionalDollar = NumberValueObject.create(1.02);
+ let fraction = NumberValueObject.create(-1);
+ let result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ fraction = NumberValueObject.create(0.1);
+ result = testFunction.calculate(fractionalDollar, fraction);
+ expect(result.getValue()).toStrictEqual(ErrorType.DIV_BY_ZERO);
+ });
+
it('Value is error', () => {
const fractionalDollar = ErrorValueObject.create(ErrorType.NAME);
const fraction = NumberValueObject.create(16);
diff --git a/packages/engine-formula/src/functions/financial/dollarfr/index.ts b/packages/engine-formula/src/functions/financial/dollarfr/index.ts
index 6f5ca3ce17..3ed3928df0 100644
--- a/packages/engine-formula/src/functions/financial/dollarfr/index.ts
+++ b/packages/engine-formula/src/functions/financial/dollarfr/index.ts
@@ -25,7 +25,7 @@ export class Dollarfr extends BaseFunction {
override maxParams = 2;
- override calculate(decimalDollar: BaseValueObject, fraction: BaseValueObject) {
+ override calculate(decimalDollar: BaseValueObject, fraction: BaseValueObject): BaseValueObject {
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(decimalDollar, fraction);
if (isError) {
diff --git a/packages/engine-formula/src/functions/financial/duration/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/duration/__tests__/index.spec.ts
new file mode 100644
index 0000000000..fc79261d23
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/duration/__tests__/index.spec.ts
@@ -0,0 +1,198 @@
+/**
+ * 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 { Duration } 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 duration function', () => {
+ const testFunction = new Duration(FUNCTION_NAMES_FINANCIAL.DURATION);
+
+ describe('Duration', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(10.919145281591927);
+ });
+
+ it('Value is normal, settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2048-1-1');
+ const maturity = StringValueObject.create('2018-7-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is normal, settlement <= 0 || maturity <= 366', () => {
+ const settlement = NumberValueObject.create(0);
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Coupon < 0', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(-0.1);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Yld < 0', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(-0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, coupon, yld, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(10.877877529944621);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, coupon, yld, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(10.708643369360447);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(10.919145281591927);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(10.919145281591927);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(10.919145281591927);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(10.919145281591927);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis6);
+ expect(result6.getValue()).toStrictEqual(10.919145281591927);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, 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 coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, 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 coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2018-7-1');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, coupon, yld, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const coupon2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, coupon2, yld, frequency, basis);
+ expect(result3.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 coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/duration/index.ts b/packages/engine-formula/src/functions/financial/duration/index.ts
new file mode 100644
index 0000000000..95a97938c0
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/duration/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 { getDateSerialNumberByObject } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { calculateDuration } from '../../../basics/financial';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Duration extends BaseFunction {
+ override minParams = 5;
+
+ override maxParams = 6;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ coupon: BaseValueObject,
+ yld: BaseValueObject,
+ frequency: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, coupon, yld, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, couponObject, yldObject, 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 couponValue = +couponObject.getValue();
+ const yldValue = +yldObject.getValue();
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(couponValue) || Number.isNaN(yldValue) || Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ couponValue < 0 ||
+ yldValue < 0 ||
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ Math.floor(settlementSerialNumber) >= Math.floor(maturitySerialNumber)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // Special handle for excel (1900)
+ if (settlementSerialNumber <= 0 || maturitySerialNumber <= 366) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = calculateDuration(settlementSerialNumber, maturitySerialNumber, couponValue, yldValue, frequencyValue, basisValue);
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/effect/index.ts b/packages/engine-formula/src/functions/financial/effect/index.ts
index be621937ca..d49c5c7e9c 100644
--- a/packages/engine-formula/src/functions/financial/effect/index.ts
+++ b/packages/engine-formula/src/functions/financial/effect/index.ts
@@ -25,7 +25,7 @@ export class Effect extends BaseFunction {
override maxParams = 2;
- override calculate(nominalRate: BaseValueObject, npery: BaseValueObject) {
+ override calculate(nominalRate: BaseValueObject, npery: BaseValueObject): BaseValueObject {
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(nominalRate, npery);
if (isError) {
diff --git a/packages/engine-formula/src/functions/financial/function-map.ts b/packages/engine-formula/src/functions/financial/function-map.ts
index a152bb98e8..63312b2902 100644
--- a/packages/engine-formula/src/functions/financial/function-map.ts
+++ b/packages/engine-formula/src/functions/financial/function-map.ts
@@ -31,18 +31,44 @@ import { Ddb } from './ddb';
import { Disc } from './disc';
import { Dollarde } from './dollarde';
import { Dollarfr } from './dollarfr';
+import { Duration } from './duration';
import { Effect } from './effect';
import { Fv } from './fv';
import { Fvschedule } from './fvschedule';
import { Intrate } from './intrate';
import { Ipmt } from './ipmt';
+import { Irr } from './irr';
import { Ispmt } from './ispmt';
+import { Mduration } from './mduration';
+import { Mirr } from './mirr';
import { Nominal } from './nominal';
import { Nper } from './nper';
+import { Npv } from './npv';
+import { Oddfprice } from './oddfprice';
+import { Oddfyield } from './oddfyield';
+import { Oddlprice } from './oddlprice';
+import { Oddlyield } from './oddlyield';
+import { Pduration } from './pduration';
import { Pmt } from './pmt';
import { Ppmt } from './ppmt';
+import { Price } from './price';
+import { Pricedisc } from './pricedisc';
+import { Pricemat } from './pricemat';
import { Pv } from './pv';
import { Rate } from './rate';
+import { Received } from './received';
+import { Rri } from './rri';
+import { Sln } from './sln';
+import { Syd } from './syd';
+import { Tbilleq } from './tbilleq';
+import { Tbillprice } from './tbillprice';
+import { Tbillyield } from './tbillyield';
+import { Vdb } from './vdb';
+import { Xirr } from './xirr';
+import { Xnpv } from './xnpv';
+import { Yield } from './yield';
+import { Yielddisc } from './yielddisc';
+import { Yieldmat } from './yieldmat';
export const functionFinancial = [
[Accrint, FUNCTION_NAMES_FINANCIAL.ACCRINT],
@@ -61,16 +87,42 @@ export const functionFinancial = [
[Disc, FUNCTION_NAMES_FINANCIAL.DISC],
[Dollarde, FUNCTION_NAMES_FINANCIAL.DOLLARDE],
[Dollarfr, FUNCTION_NAMES_FINANCIAL.DOLLARFR],
+ [Duration, FUNCTION_NAMES_FINANCIAL.DURATION],
[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],
+ [Irr, FUNCTION_NAMES_FINANCIAL.IRR],
[Ispmt, FUNCTION_NAMES_FINANCIAL.ISPMT],
+ [Mduration, FUNCTION_NAMES_FINANCIAL.MDURATION],
+ [Mirr, FUNCTION_NAMES_FINANCIAL.MIRR],
[Nominal, FUNCTION_NAMES_FINANCIAL.NOMINAL],
[Nper, FUNCTION_NAMES_FINANCIAL.NPER],
+ [Npv, FUNCTION_NAMES_FINANCIAL.NPV],
+ [Oddfprice, FUNCTION_NAMES_FINANCIAL.ODDFPRICE],
+ [Oddfyield, FUNCTION_NAMES_FINANCIAL.ODDFYIELD],
+ [Oddlprice, FUNCTION_NAMES_FINANCIAL.ODDLPRICE],
+ [Oddlyield, FUNCTION_NAMES_FINANCIAL.ODDLYIELD],
+ [Pduration, FUNCTION_NAMES_FINANCIAL.PDURATION],
[Pmt, FUNCTION_NAMES_FINANCIAL.PMT],
[Ppmt, FUNCTION_NAMES_FINANCIAL.PPMT],
+ [Price, FUNCTION_NAMES_FINANCIAL.PRICE],
+ [Pricedisc, FUNCTION_NAMES_FINANCIAL.PRICEDISC],
+ [Pricemat, FUNCTION_NAMES_FINANCIAL.PRICEMAT],
[Pv, FUNCTION_NAMES_FINANCIAL.PV],
[Rate, FUNCTION_NAMES_FINANCIAL.RATE],
+ [Received, FUNCTION_NAMES_FINANCIAL.RECEIVED],
+ [Rri, FUNCTION_NAMES_FINANCIAL.RRI],
+ [Sln, FUNCTION_NAMES_FINANCIAL.SLN],
+ [Syd, FUNCTION_NAMES_FINANCIAL.SYD],
+ [Tbilleq, FUNCTION_NAMES_FINANCIAL.TBILLEQ],
+ [Tbillprice, FUNCTION_NAMES_FINANCIAL.TBILLPRICE],
+ [Tbillyield, FUNCTION_NAMES_FINANCIAL.TBILLYIELD],
+ [Vdb, FUNCTION_NAMES_FINANCIAL.VDB],
+ [Xirr, FUNCTION_NAMES_FINANCIAL.XIRR],
+ [Xnpv, FUNCTION_NAMES_FINANCIAL.XNPV],
+ [Yield, FUNCTION_NAMES_FINANCIAL.YIELD],
+ [Yielddisc, FUNCTION_NAMES_FINANCIAL.YIELDDISC],
+ [Yieldmat, FUNCTION_NAMES_FINANCIAL.YIELDMAT],
];
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
index 8b64957fe5..efd810da63 100644
--- a/packages/engine-formula/src/functions/financial/fv/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/fv/__tests__/index.spec.ts
@@ -41,6 +41,16 @@ describe('Test fv function', () => {
expect(result2.getValue()).toStrictEqual(2581.4033740601362);
});
+ it('Result is NaN', () => {
+ const rate = NumberValueObject.create(-1);
+ const nper = NumberValueObject.create(0);
+ 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.NUM);
+ });
+
it('Value is error', () => {
const rate = ErrorValueObject.create(ErrorType.NAME);
const nper = NumberValueObject.create(10);
diff --git a/packages/engine-formula/src/functions/financial/fv/index.ts b/packages/engine-formula/src/functions/financial/fv/index.ts
index ccfd5bed18..2adcba5a38 100644
--- a/packages/engine-formula/src/functions/financial/fv/index.ts
+++ b/packages/engine-formula/src/functions/financial/fv/index.ts
@@ -29,7 +29,7 @@ export class Fv extends BaseFunction {
override maxParams = 5;
- override calculate(rate: BaseValueObject, nper: BaseValueObject, pmt: BaseValueObject, pv?: BaseValueObject, type?: BaseValueObject) {
+ override calculate(rate: BaseValueObject, nper: BaseValueObject, pmt: BaseValueObject, pv?: BaseValueObject, type?: BaseValueObject): BaseValueObject {
const _pv = pv ?? NumberValueObject.create(0);
const _type = type ?? NumberValueObject.create(0);
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
index 7ce123cdc1..f79c44655b 100644
--- a/packages/engine-formula/src/functions/financial/fvschedule/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/fvschedule/__tests__/index.spec.ts
@@ -32,6 +32,10 @@ describe('Test fvschedule function', () => {
const schedule = ArrayValueObject.create('{0.09,0.11,0.1}');
const result = testFunction.calculate(principal, schedule);
expect(result.getValue()).toStrictEqual(1.3308900000000004);
+
+ const schedule2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(principal, schedule2);
+ expect(result2.getValue()).toStrictEqual(2);
});
it('Value is error', () => {
@@ -46,6 +50,11 @@ describe('Test fvschedule function', () => {
const schedule = ArrayValueObject.create('{0.09,0.11,0.1}');
const result = testFunction.calculate(principal, schedule);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const principal2 = NumberValueObject.create(1);
+ const schedule2 = BooleanValueObject.create(true);
+ const result2 = testFunction.calculate(principal2, schedule2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('Value is blank cell', () => {
@@ -60,6 +69,11 @@ describe('Test fvschedule function', () => {
const schedule = ArrayValueObject.create('{0.09,0.11,0.1}');
const result = testFunction.calculate(principal, schedule);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const principal2 = NumberValueObject.create(1);
+ const schedule2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(principal2, schedule2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('Value is array', () => {
@@ -77,6 +91,35 @@ describe('Test fvschedule function', () => {
const schedule = ArrayValueObject.create('{0.09,0.11,0.1}');
const result = testFunction.calculate(principal, schedule);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const principal2 = NumberValueObject.create(1);
+ const schedule2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(principal2, schedule2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const schedule3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', true, 'test', false, ErrorType.NAME],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(principal2, schedule3);
+ expect(result3.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
index 411e9d716f..9a8b229f13 100644
--- a/packages/engine-formula/src/functions/financial/fvschedule/index.ts
+++ b/packages/engine-formula/src/functions/financial/fvschedule/index.ts
@@ -25,7 +25,7 @@ export class Fvschedule extends BaseFunction {
override maxParams = 2;
- override calculate(principal: BaseValueObject, schedule: BaseValueObject) {
+ override calculate(principal: BaseValueObject, schedule: BaseValueObject): BaseValueObject {
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(principal);
if (isError) {
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
index 9650e0040d..27ed6e76a6 100644
--- a/packages/engine-formula/src/functions/financial/intrate/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/financial/intrate/__tests__/index.spec.ts
@@ -101,6 +101,15 @@ describe('Test intrate function', () => {
const basis = NumberValueObject.create(2);
const result = testFunction.calculate(settlement, maturity, investment, redemption, basis);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-2-15');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, investment, redemption, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const basis2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, investment, redemption, basis2);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
});
it('Value is array', () => {
diff --git a/packages/engine-formula/src/functions/financial/intrate/index.ts b/packages/engine-formula/src/functions/financial/intrate/index.ts
index b72c8920e5..a48a4af5a9 100644
--- a/packages/engine-formula/src/functions/financial/intrate/index.ts
+++ b/packages/engine-formula/src/functions/financial/intrate/index.ts
@@ -26,7 +26,13 @@ export class Intrate extends BaseFunction {
override maxParams = 5;
- override calculate(settlement: BaseValueObject, maturity: BaseValueObject, investment: BaseValueObject, redemption: BaseValueObject, basis?: BaseValueObject) {
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ investment: BaseValueObject,
+ redemption: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
const _basis = basis ?? NumberValueObject.create(0);
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(settlement, maturity, investment, redemption, _basis);
diff --git a/packages/engine-formula/src/functions/financial/ipmt/index.ts b/packages/engine-formula/src/functions/financial/ipmt/index.ts
index 74cfd0f2ab..c7dd79a27c 100644
--- a/packages/engine-formula/src/functions/financial/ipmt/index.ts
+++ b/packages/engine-formula/src/functions/financial/ipmt/index.ts
@@ -29,7 +29,7 @@ export class Ipmt extends BaseFunction {
override maxParams = 6;
- override calculate(rate: BaseValueObject, per: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject) {
+ override calculate(rate: BaseValueObject, per: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject): BaseValueObject {
const _fv = fv ?? NumberValueObject.create(0);
const _type = type ?? NumberValueObject.create(0);
diff --git a/packages/engine-formula/src/functions/financial/irr/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/irr/__tests__/index.spec.ts
new file mode 100644
index 0000000000..8f426a4d7c
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/irr/__tests__/index.spec.ts
@@ -0,0 +1,110 @@
+/**
+ * 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 { Irr } 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 irr function', () => {
+ const testFunction = new Irr(FUNCTION_NAMES_FINANCIAL.IRR);
+
+ describe('Irr', () => {
+ it('Value is normal', () => {
+ const values = ArrayValueObject.create('{-700000,120000,150000,180000,210000,260000}');
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(values, guess);
+ expect(result.getValue()).toStrictEqual(0.08663094803653168);
+ });
+
+ it('Value is normal, but no positive and negative number', () => {
+ const values = ArrayValueObject.create('{700000,120000,150000,180000,210000,260000}');
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(values, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is error', () => {
+ const values = ErrorValueObject.create(ErrorType.NAME);
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(values, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const values2 = ArrayValueObject.create('{-700000,120000,150000,180000,210000,260000}');
+ const guess2 = ErrorValueObject.create(ErrorType.NAME);
+ const result2 = testFunction.calculate(values2, guess2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const values = ArrayValueObject.create('{-700000,120000,150000,180000,210000,260000}');
+ const guess = BooleanValueObject.create(true);
+ const result = testFunction.calculate(values, guess);
+ expect(result.getValue()).toStrictEqual(0.08663094803650478);
+ });
+
+ it('Value is normal string', () => {
+ const values = ArrayValueObject.create('{-700000,120000,150000,180000,210000,260000}');
+ const guess = StringValueObject.create('test');
+ const result = testFunction.calculate(values, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const values = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME, null],
+ [-700000, 120000, 150000, 180000, 210000, 260000],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const guess = NumberValueObject.create(16);
+ const result = testFunction.calculate(values, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const values2 = NumberValueObject.create(16);
+ const guess2 = NullValueObject.create();
+ const result2 = testFunction.calculate(values2, guess2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const values3 = ArrayValueObject.create('{-700000,120000,150000,180000,210000,260000}');
+ const guess3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(values3, guess3);
+ expect(transformToValue(result3.getArrayValue())).toStrictEqual([
+ [0.08663094803654446, ErrorType.VALUE, 0.08663094803650478, 0.08663094803653167, ErrorType.NAME, 0.08663094803653167],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/irr/index.ts b/packages/engine-formula/src/functions/financial/irr/index.ts
new file mode 100644
index 0000000000..4760841fc2
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/irr/index.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 { 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 { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import { calculateNpv, getResultByGuessIterF } from '../../../basics/financial';
+
+interface IValuesType {
+ _values: number[];
+ valuesHasError: boolean;
+}
+
+interface ICheckValuesType {
+ positive: boolean;
+ negative: boolean;
+}
+
+export class Irr extends BaseFunction {
+ override minParams = 1;
+
+ override maxParams = 2;
+
+ override calculate(values: BaseValueObject, guess?: BaseValueObject): BaseValueObject {
+ let _guess = guess ?? NumberValueObject.create(0.1);
+
+ if (_guess.isNull()) {
+ _guess = NumberValueObject.create(0.1);
+ }
+
+ if (_guess.isArray()) {
+ return _guess.map((guessObject, rowIndex, columnIndex) => this._handleSingleObject(values, guessObject, rowIndex, columnIndex));
+ }
+
+ return this._handleSingleObject(values, _guess);
+ }
+
+ private _handleSingleObject(values: BaseValueObject, guess: BaseValueObject, rowIndex: number = 0, columnIndex: number = 0): BaseValueObject {
+ if (values.isError()) {
+ return values;
+ }
+
+ if (guess.isError()) {
+ return guess;
+ }
+
+ if (values.isNull()) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (!values.isArray()) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const { _values, valuesHasError } = this._getValues(values as ArrayValueObject);
+
+ if (valuesHasError) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ let _guess = guess;
+
+ if (_guess.isString()) {
+ _guess = _guess.convertToNumberObjectValue();
+
+ if (_guess.isError()) {
+ return _guess;
+ }
+ }
+
+ const guessValue = +_guess.getValue();
+
+ const { positive, negative } = this._checkValues(_values);
+
+ if (!positive || !negative) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = getResultByGuessIterF(guessValue, (rate: number) => calculateNpv(rate, _values));
+
+ if (typeof result !== 'number') {
+ return result as ErrorValueObject;
+ }
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '0%');
+ }
+
+ return NumberValueObject.create(result);
+ }
+
+ private _getValues(values: ArrayValueObject): IValuesType {
+ const _values: number[] = [];
+
+ let valuesHasError = false;
+
+ (values as ArrayValueObject).iterator((valueOject) => {
+ const _valueOject = valueOject as BaseValueObject;
+
+ if (_valueOject.isError()) {
+ valuesHasError = true;
+ return false;
+ }
+
+ if (_valueOject.isNull() || _valueOject.isBoolean()) {
+ return true;
+ }
+
+ const value = +_valueOject.getValue();
+
+ if (Number.isNaN(value)) {
+ return true;
+ }
+
+ _values.push(value);
+ });
+
+ return {
+ _values,
+ valuesHasError,
+ };
+ }
+
+ private _checkValues(values: number[]): ICheckValuesType {
+ let positive = false;
+ let negative = false;
+
+ for (let i = 0; i < values.length; i++) {
+ if (values[i] > 0) {
+ positive = true;
+ }
+
+ if (values[i] < 0) {
+ negative = true;
+ }
+ }
+
+ return {
+ positive,
+ negative,
+ };
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/ispmt/index.ts b/packages/engine-formula/src/functions/financial/ispmt/index.ts
index db4e7eedb5..2ced4459cc 100644
--- a/packages/engine-formula/src/functions/financial/ispmt/index.ts
+++ b/packages/engine-formula/src/functions/financial/ispmt/index.ts
@@ -28,7 +28,7 @@ export class Ispmt extends BaseFunction {
override maxParams = 4;
- override calculate(rate: BaseValueObject, per: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject) {
+ override calculate(rate: BaseValueObject, per: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject): BaseValueObject {
const maxRowLength = Math.max(
rate.isArray() ? (rate as ArrayValueObject).getRowCount() : 1,
per.isArray() ? (per as ArrayValueObject).getRowCount() : 1,
diff --git a/packages/engine-formula/src/functions/financial/mduration/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/mduration/__tests__/index.spec.ts
new file mode 100644
index 0000000000..763c62df42
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/mduration/__tests__/index.spec.ts
@@ -0,0 +1,187 @@
+/**
+ * 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 { Mduration } 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 mduration function', () => {
+ const testFunction = new Mduration(FUNCTION_NAMES_FINANCIAL.MDURATION);
+
+ describe('Mduration', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(10.448942853198018);
+ });
+
+ it('Value is normal, settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2048-1-1');
+ const maturity = StringValueObject.create('2018-7-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Coupon < 0', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(-0.1);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Yld < 0', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(-0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, coupon, yld, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(9.979704155912495);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, coupon, yld, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(10.473000850230266);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2018-7-1');
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(10.448942853198018);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(10.448942853198018);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(10.448942853198018);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(10.448942853198018);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis6);
+ expect(result6.getValue()).toStrictEqual(10.448942853198018);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2048-1-1');
+ const coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, 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 coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, 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 coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2018-7-1');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, coupon, yld, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const coupon2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, coupon2, yld, frequency, basis);
+ expect(result3.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 coupon = NumberValueObject.create(0.08);
+ const yld = NumberValueObject.create(0.09);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, coupon, yld, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/mduration/index.ts b/packages/engine-formula/src/functions/financial/mduration/index.ts
new file mode 100644
index 0000000000..09e545bf87
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/mduration/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 { getDateSerialNumberByObject } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { calculateDuration } from '../../../basics/financial';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Mduration extends BaseFunction {
+ override minParams = 5;
+
+ override maxParams = 6;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ coupon: BaseValueObject,
+ yld: BaseValueObject,
+ frequency: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, coupon, yld, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, couponObject, yldObject, 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 couponValue = +couponObject.getValue();
+ const yldValue = +yldObject.getValue();
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(couponValue) || Number.isNaN(yldValue) || Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ couponValue < 0 ||
+ yldValue < 0 ||
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ Math.floor(settlementSerialNumber) >= Math.floor(maturitySerialNumber)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ let result = calculateDuration(settlementSerialNumber, maturitySerialNumber, couponValue, yldValue, frequencyValue, basisValue);
+
+ result /= 1 + yldValue / frequencyValue;
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/mirr/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/mirr/__tests__/index.spec.ts
new file mode 100644
index 0000000000..2e88beb4c8
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/mirr/__tests__/index.spec.ts
@@ -0,0 +1,131 @@
+/**
+ * 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 { Mirr } 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 mirr function', () => {
+ const testFunction = new Mirr(FUNCTION_NAMES_FINANCIAL.MIRR);
+
+ describe('Mirr', () => {
+ it('Value is normal', () => {
+ const values = ArrayValueObject.create('{-700000,120000,150000,180000,210000,260000}');
+ const financeRate = NumberValueObject.create(0.1);
+ const reinvestRate = NumberValueObject.create(0.12);
+ const result = testFunction.calculate(values, financeRate, reinvestRate);
+ expect(result.getValue()).toStrictEqual(0.09866910733715017);
+ });
+
+ it('Value is normal, but no positive and negative number', () => {
+ const values = ArrayValueObject.create('{700000,120000,150000,180000,210000,260000}');
+ const financeRate = NumberValueObject.create(0.1);
+ const reinvestRate = NumberValueObject.create(0.12);
+ const result = testFunction.calculate(values, financeRate, reinvestRate);
+ expect(result.getValue()).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const values2 = NullValueObject.create();
+ const result2 = testFunction.calculate(values2, financeRate, reinvestRate);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const values3 = NumberValueObject.create(1);
+ const result3 = testFunction.calculate(values3, financeRate, reinvestRate);
+ expect(result3.getValue()).toStrictEqual(ErrorType.DIV_BY_ZERO);
+ });
+
+ it('ReinvestRate === -1', () => {
+ const values = ArrayValueObject.create('{-700000,120000,150000,180000,210000,260000}');
+ const financeRate = NumberValueObject.create(0.1);
+ const reinvestRate = NumberValueObject.create(-1);
+ const result = testFunction.calculate(values, financeRate, reinvestRate);
+ expect(result.getValue()).toStrictEqual(ErrorType.DIV_BY_ZERO);
+ });
+
+ it('Value is error', () => {
+ const values = ErrorValueObject.create(ErrorType.NAME);
+ const financeRate = NumberValueObject.create(0.1);
+ const reinvestRate = NumberValueObject.create(0.12);
+ const result = testFunction.calculate(values, financeRate, reinvestRate);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const values2 = ArrayValueObject.create('{700000,120000,150000,180000,210000,260000}');
+ const financeRate2 = ErrorValueObject.create(ErrorType.NAME);
+ const result2 = testFunction.calculate(values2, financeRate2, reinvestRate);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const reinvestRate2 = ErrorValueObject.create(ErrorType.NAME);
+ const result3 = testFunction.calculate(values2, financeRate, reinvestRate2);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const values = ArrayValueObject.create('{-700000,120000,150000,180000,210000,260000}');
+ const financeRate = BooleanValueObject.create(true);
+ const reinvestRate = NumberValueObject.create(0.12);
+ const result = testFunction.calculate(values, financeRate, reinvestRate);
+ expect(result.getValue()).toStrictEqual(0.09866910733715017);
+ });
+
+ it('Value is normal string', () => {
+ const values = ArrayValueObject.create('{-700000,120000,150000,180000,210000,260000}');
+ const financeRate = StringValueObject.create('test');
+ const reinvestRate = NumberValueObject.create(0.12);
+ const result = testFunction.calculate(values, financeRate, reinvestRate);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const values = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME, null],
+ [-700000, 120000, 150000, 180000, 210000, 260000],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const financeRate = NumberValueObject.create(0.1);
+ const reinvestRate = NumberValueObject.create(0.12);
+ const result = testFunction.calculate(values, financeRate, reinvestRate);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const values2 = ArrayValueObject.create('{-700000,120000,150000,180000,210000,260000}');
+ const financeRate2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [0.1, 0.12],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(values2, financeRate2, reinvestRate);
+ expect(transformToValue(result2.getArrayValue())).toStrictEqual([
+ [0.09866910733715017, 0.09866910733715017],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/mirr/index.ts b/packages/engine-formula/src/functions/financial/mirr/index.ts
new file mode 100644
index 0000000000..67d1d23f93
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/mirr/index.ts
@@ -0,0 +1,220 @@
+/**
+ * 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 '../../../engine/value-object/array-value-object';
+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 { expandArrayValueObject } from '../../../engine/utils/array-object';
+
+interface INumberValues {
+ numberValues: number[];
+ positive: boolean;
+ negative: boolean;
+}
+
+interface IValuesType extends INumberValues {
+ _values: BaseValueObject;
+}
+
+interface ICheckValuesType extends INumberValues {
+ valuesHasError: boolean;
+ errorObject: ErrorValueObject;
+}
+
+export class Mirr extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(values: BaseValueObject, financeRate: BaseValueObject, reinvestRate: BaseValueObject): BaseValueObject {
+ const { _values, numberValues, positive, negative } = this._getValues(values);
+
+ const maxRowLength = Math.max(
+ financeRate.isArray() ? (financeRate as ArrayValueObject).getRowCount() : 1,
+ reinvestRate.isArray() ? (reinvestRate as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ financeRate.isArray() ? (financeRate as ArrayValueObject).getColumnCount() : 1,
+ reinvestRate.isArray() ? (reinvestRate as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const financeRateArray = expandArrayValueObject(maxRowLength, maxColumnLength, financeRate, ErrorValueObject.create(ErrorType.NA));
+ const reinvestRateArray = expandArrayValueObject(maxRowLength, maxColumnLength, reinvestRate, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = financeRateArray.map((financeRateObject, rowIndex, columnIndex) => {
+ const reinvestRateObject = reinvestRateArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ if (values.isError()) {
+ return values;
+ }
+
+ if (reinvestRateObject.isError()) {
+ return reinvestRateObject;
+ }
+
+ if (_values.isError()) {
+ return _values;
+ }
+
+ if (!positive || !negative) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ const financeRateValue = +financeRateObject.getValue();
+ const reinvestRateValue = +reinvestRateObject.getValue();
+
+ if (Number.isNaN(financeRateValue) || Number.isNaN(reinvestRateValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (reinvestRateValue === -1) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ const result = this._getResult(numberValues, financeRateValue, reinvestRateValue);
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '0%');
+ }
+
+ return NumberValueObject.create(result);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+
+ private _getValues(values: BaseValueObject): IValuesType {
+ let _values = values;
+ let _numberValues: number[] = [];
+ let _positive = false;
+ let _negative = false;
+
+ if (!values.isError()) {
+ if (values.isNull()) {
+ _values = ErrorValueObject.create(ErrorType.VALUE);
+ } else if (!values.isArray()) {
+ _values = ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ } else {
+ const { numberValues, valuesHasError, errorObject, positive, negative } = this._checkValues(values as ArrayValueObject);
+
+ if (valuesHasError) {
+ _values = errorObject;
+ }
+
+ _numberValues = numberValues;
+ _positive = positive;
+ _negative = negative;
+ }
+ }
+
+ return {
+ _values,
+ numberValues: _numberValues,
+ positive: _positive,
+ negative: _negative,
+ };
+ }
+
+ private _checkValues(values: ArrayValueObject): ICheckValuesType {
+ const numberValues: number[] = [];
+
+ let valuesHasError = false;
+ let errorObject: ErrorValueObject = ErrorValueObject.create(ErrorType.VALUE);
+ let positive = false;
+ let negative = false;
+
+ (values as ArrayValueObject).iterator((valueOject) => {
+ const _valueOject = valueOject as BaseValueObject;
+
+ if (_valueOject.isError()) {
+ valuesHasError = true;
+ errorObject = _valueOject as ErrorValueObject;
+ return false;
+ }
+
+ if (_valueOject.isNull() || _valueOject.isBoolean()) {
+ return true;
+ }
+
+ const value = +_valueOject.getValue();
+
+ if (Number.isNaN(value)) {
+ return true;
+ }
+
+ if (value > 0) {
+ positive = true;
+ }
+
+ if (value < 0) {
+ negative = true;
+ }
+
+ numberValues.push(value);
+ });
+
+ return {
+ numberValues,
+ valuesHasError,
+ errorObject,
+ positive,
+ negative,
+ };
+ }
+
+ private _getResult(values: number[], financeRate: number, reinvestRate: number): number {
+ const n = values.length;
+ const negatives = [];
+ const positives = [];
+
+ for (let i = 0; i < n; i++) {
+ if (values[i] > 0) {
+ positives.push(values[i]);
+ } else if (values[i] < 0) {
+ negatives.push(values[i]);
+ }
+ }
+
+ const npvR = this._npv(reinvestRate, values, 'positive');
+ const npvF = this._npv(financeRate, values, 'negative');
+ const num = -npvR * ((1 + reinvestRate) ** n);
+ const den = npvF * (1 + financeRate);
+ const result = (num / den) ** (1 / (n - 1)) - 1;
+
+ return result;
+ }
+
+ private _npv(rate: number, values: number[], type: 'positive' | 'negative'): number {
+ let res = 0;
+
+ for (let i = 1; i <= values.length; i++) {
+ const value = values[i - 1];
+
+ if ((type === 'positive' && value > 0) || (type === 'negative' && value < 0)) {
+ res += value / ((1 + rate) ** i);
+ }
+ }
+
+ return res;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/nominal/index.ts b/packages/engine-formula/src/functions/financial/nominal/index.ts
index 6f1666eb6e..ac777dfc8e 100644
--- a/packages/engine-formula/src/functions/financial/nominal/index.ts
+++ b/packages/engine-formula/src/functions/financial/nominal/index.ts
@@ -25,7 +25,7 @@ export class Nominal extends BaseFunction {
override maxParams = 2;
- override calculate(effectRate: BaseValueObject, npery: BaseValueObject) {
+ override calculate(effectRate: BaseValueObject, npery: BaseValueObject): BaseValueObject {
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(effectRate, npery);
if (isError) {
diff --git a/packages/engine-formula/src/functions/financial/nper/index.ts b/packages/engine-formula/src/functions/financial/nper/index.ts
index 01fa522492..5c535838e4 100644
--- a/packages/engine-formula/src/functions/financial/nper/index.ts
+++ b/packages/engine-formula/src/functions/financial/nper/index.ts
@@ -28,7 +28,7 @@ export class Nper extends BaseFunction {
override maxParams = 5;
- override calculate(rate: BaseValueObject, pmt: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject) {
+ override calculate(rate: BaseValueObject, pmt: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject): BaseValueObject {
const _fv = fv ?? NumberValueObject.create(0);
const _type = type ?? NumberValueObject.create(0);
diff --git a/packages/engine-formula/src/functions/financial/npv/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/npv/__tests__/index.spec.ts
new file mode 100644
index 0000000000..eaef4ec323
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/npv/__tests__/index.spec.ts
@@ -0,0 +1,110 @@
+/**
+ * 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 { Npv } from '../index';
+import { BooleanValueObject, 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 npv function', () => {
+ const testFunction = new Npv(FUNCTION_NAMES_FINANCIAL.NPV);
+
+ describe('Npv', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.1);
+ const value1 = ArrayValueObject.create('{-10000,3000,4200,6800}');
+ const result = testFunction.calculate(rate, value1);
+ expect(result.getValue()).toStrictEqual(1188.4434123352207);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const value1 = ArrayValueObject.create('{-10000,3000,4200,6800}');
+ const result = testFunction.calculate(rate, value1);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const rate2 = NumberValueObject.create(0.1);
+ const value2 = ErrorValueObject.create(ErrorType.NAME);
+ const result2 = testFunction.calculate(rate2, value1, value2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const value3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME, null],
+ [-700000, 120000, 150000, 180000, 210000, 260000],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(rate2, value1, value3);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = NumberValueObject.create(0.1);
+ const value1 = ArrayValueObject.create('{-10000,3000,4200,6800}');
+ const value2 = BooleanValueObject.create(true);
+ const result = testFunction.calculate(rate, value1, value2);
+ expect(result.getValue()).toStrictEqual(1189.0643336582798);
+ });
+
+ it('Value is normal string', () => {
+ const rate = NumberValueObject.create(0.1);
+ const value1 = ArrayValueObject.create('{-10000,3000,4200,6800}');
+ const value2 = StringValueObject.create('test');
+ const result = testFunction.calculate(rate, value1, value2);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(rate2, value1);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is array', () => {
+ const rate = ArrayValueObject.create('{0.1,-0.1,-1}');
+ const value1 = ArrayValueObject.create('{-10000,3000,4200,6800}');
+ const result = testFunction.calculate(rate, value1);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [1188.4434123352207, 8718.183203779909, ErrorType.DIV_BY_ZERO],
+ ]);
+
+ const value2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, null],
+ [-700000, 120000, 150000, 210000, 260000],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(rate, value2);
+ expect(transformToValue(result2.getArrayValue())).toStrictEqual([
+ [-108744.97535213304, 373909.0553792423, ErrorType.DIV_BY_ZERO],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/npv/index.ts b/packages/engine-formula/src/functions/financial/npv/index.ts
new file mode 100644
index 0000000000..0985754665
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/npv/index.ts
@@ -0,0 +1,150 @@
+/**
+ * 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 '../../../engine/value-object/array-value-object';
+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 { calculateNpv } from '../../../basics/financial';
+
+interface IValuesType {
+ isError: boolean;
+ errorObject?: ErrorValueObject;
+ values?: number[];
+}
+
+export class Npv extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 255;
+
+ override calculate(rate: BaseValueObject, ...variants: BaseValueObject[]): BaseValueObject {
+ if (rate.isError()) {
+ return rate;
+ }
+
+ const { isError, errorObject, values } = this._getValues(variants);
+
+ if (rate.isArray()) {
+ return (rate as ArrayValueObject).map((rateObject, rowIndex, columnIndex) => this._handleSingleObject(rateObject, isError, errorObject, values, rowIndex, columnIndex));
+ }
+
+ return this._handleSingleObject(rate, isError, errorObject, values);
+ }
+
+ private _handleSingleObject(
+ rate: BaseValueObject,
+ isError: boolean,
+ errorObject: ErrorValueObject | undefined,
+ values: number[] | undefined,
+ rowIndex: number = 0,
+ columnIndex: number = 0
+ ): BaseValueObject {
+ let _rate = rate;
+
+ if (_rate.isString()) {
+ _rate = _rate.convertToNumberObjectValue();
+ }
+
+ if (_rate.isError()) {
+ return _rate;
+ }
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const rateValue = +rate.getValue();
+
+ const result = calculateNpv(rateValue, values as number[]);
+
+ if (Number.isNaN(result) || Math.abs(result) === Infinity) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ }
+
+ return NumberValueObject.create(result);
+ }
+
+ private _getValues(variants: BaseValueObject[]): IValuesType {
+ const values: number[] = [];
+
+ for (let i = 0; i < variants.length; i++) {
+ const variant = variants[i];
+
+ if (variant.isError()) {
+ return {
+ isError: true,
+ errorObject: variant as ErrorValueObject,
+ };
+ }
+
+ if (variant.isArray()) {
+ let isError = false;
+ let errorObject = ErrorValueObject.create(ErrorType.VALUE);
+
+ (variant as ArrayValueObject).iterator((variantOject) => {
+ const _variantOject = variantOject as BaseValueObject;
+
+ if (_variantOject.isError()) {
+ isError = true;
+ errorObject = _variantOject as ErrorValueObject;
+ return false;
+ }
+
+ if (_variantOject.isNull() || _variantOject.isBoolean()) {
+ return true;
+ }
+
+ const value = +_variantOject.getValue();
+
+ if (Number.isNaN(value)) {
+ return true;
+ }
+
+ values.push(value);
+ });
+
+ if (isError) {
+ return {
+ isError,
+ errorObject,
+ };
+ }
+ } else {
+ const value = +variant.getValue();
+
+ if (Number.isNaN(value)) {
+ return {
+ isError: true,
+ errorObject: ErrorValueObject.create(ErrorType.VALUE),
+ };
+ }
+
+ values.push(value);
+ }
+ }
+
+ return {
+ isError: false,
+ values,
+ };
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/oddfprice/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/oddfprice/__tests__/index.spec.ts
new file mode 100644
index 0000000000..87b6c05bdc
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/oddfprice/__tests__/index.spec.ts
@@ -0,0 +1,230 @@
+/**
+ * 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 { Oddfprice } 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 oddfprice function', () => {
+ const testFunction = new Oddfprice(FUNCTION_NAMES_FINANCIAL.ODDFPRICE);
+
+ describe('Oddfprice', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(113.59771747407883);
+ });
+
+ it('Value is normal, but date valid error, return #NUM!', () => {
+ const settlement = StringValueObject.create('2018-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const maturity2 = StringValueObject.create('2021-3-1');
+ const firstCoupon2 = StringValueObject.create('2009-3-2');
+ const result2 = testFunction.calculate(settlement, maturity2, issue, firstCoupon2, rate, yld, redemption, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Rate < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(-0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Yld < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(-0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(113.49458554550696);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(113.65002161109066);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(113.59920582823821);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(113.59879960832525);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(113.5961125952049);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(113.59920582823821);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis6);
+ expect(result6.getValue()).toStrictEqual(113.59920582823821);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-11-11');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, issue, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const issue2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, issue2, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const firstCoupon2 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(settlement2, maturity, issue, firstCoupon2, rate, yld, redemption, frequency, basis);
+ expect(result4.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = StringValueObject.create('test');
+ const result5 = testFunction.calculate(settlement2, maturity, issue, firstCoupon, rate2, yld, redemption, frequency, basis);
+ expect(result5.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('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/oddfprice/index.ts b/packages/engine-formula/src/functions/financial/oddfprice/index.ts
new file mode 100644
index 0000000000..19a10fd453
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/oddfprice/index.ts
@@ -0,0 +1,117 @@
+/**
+ * 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 } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { calculateOddFPrice, validCouppcdIsGte0ByTwoDate, validDaysBetweenIsWholeFrequencyByTwoDate } from '../../../basics/financial';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Oddfprice extends BaseFunction {
+ override minParams = 8;
+
+ override maxParams = 9;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ issue: BaseValueObject,
+ firstCoupon: BaseValueObject,
+ rate: BaseValueObject,
+ yld: BaseValueObject,
+ redemption: BaseValueObject,
+ frequency: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, issue, firstCoupon, rate, yld, redemption, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, issueObject, firstCouponObject, rateObject, yldObject, redemptionObject, 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 issueSerialNumber = getDateSerialNumberByObject(issueObject);
+
+ if (typeof issueSerialNumber !== 'number') {
+ return issueSerialNumber;
+ }
+
+ const firstCouponSerialNumber = getDateSerialNumberByObject(firstCouponObject);
+
+ if (typeof firstCouponSerialNumber !== 'number') {
+ return firstCouponSerialNumber;
+ }
+
+ const rateValue = +rateObject.getValue();
+ const yldValue = +yldObject.getValue();
+ const redemptionValue = +redemptionObject.getValue();
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(rateValue) || Number.isNaN(yldValue) || Number.isNaN(redemptionValue) || Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ rateValue < 0 ||
+ yldValue < 0 ||
+ redemptionValue <= 0 ||
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ !this._validDate(maturitySerialNumber, firstCouponSerialNumber, settlementSerialNumber, issueSerialNumber, frequencyValue)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = calculateOddFPrice(settlementSerialNumber, maturitySerialNumber, issueSerialNumber, firstCouponSerialNumber, rateValue, yldValue, redemptionValue, frequencyValue, basisValue);
+
+ return NumberValueObject.create(result);
+ }
+
+ private _validDate(maturitySerialNumber: number, firstCouponSerialNumber: number, settlementSerialNumber: number, issueSerialNumber: number, frequencyValue: number): boolean {
+ return this._getDateCorrectOrder(maturitySerialNumber, firstCouponSerialNumber, settlementSerialNumber, issueSerialNumber)
+ && validDaysBetweenIsWholeFrequencyByTwoDate(maturitySerialNumber, firstCouponSerialNumber, frequencyValue)
+ && validCouppcdIsGte0ByTwoDate(issueSerialNumber, maturitySerialNumber, frequencyValue);
+ }
+
+ private _getDateCorrectOrder(maturitySerialNumber: number, firstCouponSerialNumber: number, settlementSerialNumber: number, issueSerialNumber: number): boolean {
+ return Math.floor(maturitySerialNumber) > Math.floor(firstCouponSerialNumber)
+ && Math.floor(firstCouponSerialNumber) > Math.floor(settlementSerialNumber)
+ && Math.floor(settlementSerialNumber) > Math.floor(issueSerialNumber);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/oddfyield/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/oddfyield/__tests__/index.spec.ts
new file mode 100644
index 0000000000..391b4dac1b
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/oddfyield/__tests__/index.spec.ts
@@ -0,0 +1,230 @@
+/**
+ * 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 { Oddfyield } 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 oddfyield function', () => {
+ const testFunction = new Oddfyield(FUNCTION_NAMES_FINANCIAL.ODDFYIELD);
+
+ describe('Oddfyield', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(0.10076644980418786);
+ });
+
+ it('Value is normal, but date valid error, return #NUM!', () => {
+ const settlement = StringValueObject.create('2018-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const maturity2 = StringValueObject.create('2021-3-1');
+ const firstCoupon2 = StringValueObject.create('2009-3-2');
+ const result2 = testFunction.calculate(settlement, maturity2, issue, firstCoupon2, rate, pr, redemption, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Rate < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(-0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Pr < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(-84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(0.10116988609428873);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(0.1005633711558758);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(0.10076530248341407);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(0.10076426120146238);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(0.1007696795226579);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(0.10076530248341407);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis6);
+ expect(result6.getValue()).toStrictEqual(0.10076530248341407);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-11-11');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, issue, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const issue2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, issue2, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const firstCoupon2 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(settlement2, maturity, issue, firstCoupon2, rate, pr, redemption, frequency, basis);
+ expect(result4.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = StringValueObject.create('test');
+ const result5 = testFunction.calculate(settlement2, maturity, issue, firstCoupon, rate2, pr, redemption, frequency, basis);
+ expect(result5.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('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const firstCoupon = StringValueObject.create('2009-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/oddfyield/index.ts b/packages/engine-formula/src/functions/financial/oddfyield/index.ts
new file mode 100644
index 0000000000..873bbd3aa3
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/oddfyield/index.ts
@@ -0,0 +1,142 @@
+/**
+ * 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 { calculateOddFPrice, getResultByGuessIterF, validCouppcdIsGte0ByTwoDate, validDaysBetweenIsWholeFrequencyByTwoDate } from '../../../basics/financial';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Oddfyield extends BaseFunction {
+ override minParams = 8;
+
+ override maxParams = 9;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ issue: BaseValueObject,
+ firstCoupon: BaseValueObject,
+ rate: BaseValueObject,
+ pr: BaseValueObject,
+ redemption: BaseValueObject,
+ frequency: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, issue, firstCoupon, rate, pr, redemption, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, issueObject, firstCouponObject, rateObject, prObject, redemptionObject, 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 issueSerialNumber = getDateSerialNumberByObject(issueObject);
+
+ if (typeof issueSerialNumber !== 'number') {
+ return issueSerialNumber;
+ }
+
+ const firstCouponSerialNumber = getDateSerialNumberByObject(firstCouponObject);
+
+ if (typeof firstCouponSerialNumber !== 'number') {
+ return firstCouponSerialNumber;
+ }
+
+ const rateValue = +rateObject.getValue();
+ const prValue = +prObject.getValue();
+ const redemptionValue = +redemptionObject.getValue();
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(rateValue) || Number.isNaN(prValue) || Number.isNaN(redemptionValue) || Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ rateValue < 0 ||
+ prValue <= 0 ||
+ redemptionValue <= 0 ||
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ !this._validDate(maturitySerialNumber, firstCouponSerialNumber, settlementSerialNumber, issueSerialNumber, frequencyValue)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return this._getResult(settlementSerialNumber, maturitySerialNumber, issueSerialNumber, firstCouponSerialNumber, rateValue, prValue, redemptionValue, frequencyValue, basisValue);
+ }
+
+ private _validDate(maturitySerialNumber: number, firstCouponSerialNumber: number, settlementSerialNumber: number, issueSerialNumber: number, frequencyValue: number): boolean {
+ return this._getDateCorrectOrder(maturitySerialNumber, firstCouponSerialNumber, settlementSerialNumber, issueSerialNumber)
+ && validDaysBetweenIsWholeFrequencyByTwoDate(maturitySerialNumber, firstCouponSerialNumber, frequencyValue)
+ && validCouppcdIsGte0ByTwoDate(issueSerialNumber, maturitySerialNumber, frequencyValue);
+ }
+
+ private _getDateCorrectOrder(maturitySerialNumber: number, firstCouponSerialNumber: number, settlementSerialNumber: number, issueSerialNumber: number): boolean {
+ return Math.floor(maturitySerialNumber) > Math.floor(firstCouponSerialNumber)
+ && Math.floor(firstCouponSerialNumber) > Math.floor(settlementSerialNumber)
+ && Math.floor(settlementSerialNumber) > Math.floor(issueSerialNumber);
+ }
+
+ private _getResult(
+ settlementSerialNumber: number,
+ maturitySerialNumber: number,
+ issueSerialNumber: number,
+ firstCouponSerialNumber: number,
+ rate: number,
+ pr: number,
+ redemption: number,
+ frequency: number,
+ basis: number
+ ): BaseValueObject {
+ const { days } = getTwoDateDaysByBasis(settlementSerialNumber, maturitySerialNumber, basis);
+ const guess = (rate * days * 100 - (pr - 100)) / ((pr - 100) * 0.25 * (1 + 2 * days) + days * 100);
+
+ function _iterF(yld: number): number {
+ return pr - calculateOddFPrice(settlementSerialNumber, maturitySerialNumber, issueSerialNumber, firstCouponSerialNumber, rate, yld, redemption, frequency, basis);
+ }
+
+ const result = getResultByGuessIterF(guess, (yld: number) => _iterF(yld));
+
+ if (typeof result !== 'number') {
+ return result as ErrorValueObject;
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/oddlprice/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/oddlprice/__tests__/index.spec.ts
new file mode 100644
index 0000000000..be54e2bac4
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/oddlprice/__tests__/index.spec.ts
@@ -0,0 +1,211 @@
+/**
+ * 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 { Oddlprice } 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 oddlprice function', () => {
+ const testFunction = new Oddlprice(FUNCTION_NAMES_FINANCIAL.ODDLPRICE);
+
+ describe('Oddlprice', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(110.87452428419957);
+ });
+
+ it('Value is normal, but correct order is maturity > settlement > lastInterest, otherwise return #NUM!', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2009-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Rate < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(-0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Yld < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(-0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(110.87480393586972);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(110.87699178390282);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(110.88286909824446);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(110.8761636577708);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(110.87411927005179);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(110.88286909824446);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis6);
+ expect(result6.getValue()).toStrictEqual(110.88286909824446);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-11-11');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, lastInterest, rate, yld, redemption, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const lastInterest2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, lastInterest2, rate, yld, redemption, frequency, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(settlement2, maturity, lastInterest, rate2, yld, redemption, frequency, basis);
+ expect(result4.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('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/oddlprice/index.ts b/packages/engine-formula/src/functions/financial/oddlprice/index.ts
new file mode 100644
index 0000000000..a357fbd352
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/oddlprice/index.ts
@@ -0,0 +1,199 @@
+/**
+ * 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 { calculateCoupdays, validCouppcdIsGte0ByTwoDate } from '../../../basics/financial';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Oddlprice extends BaseFunction {
+ override minParams = 7;
+
+ override maxParams = 8;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ lastInterest: BaseValueObject,
+ rate: BaseValueObject,
+ yld: BaseValueObject,
+ redemption: BaseValueObject,
+ frequency: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, lastInterest, rate, yld, redemption, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, lastInterestObject, rateObject, yldObject, redemptionObject, 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 lastInterestSerialNumber = getDateSerialNumberByObject(lastInterestObject);
+
+ if (typeof lastInterestSerialNumber !== 'number') {
+ return lastInterestSerialNumber;
+ }
+
+ const rateValue = +rateObject.getValue();
+ const yldValue = +yldObject.getValue();
+ const redemptionValue = +redemptionObject.getValue();
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(rateValue) || Number.isNaN(yldValue) || Number.isNaN(redemptionValue) || Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ rateValue < 0 ||
+ yldValue < 0 ||
+ redemptionValue <= 0 ||
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ !this._validDate(maturitySerialNumber, settlementSerialNumber, lastInterestSerialNumber, frequencyValue)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // TODO: now result is same as ptc, but some results is different from excel
+ const result = this._getResult(settlementSerialNumber, maturitySerialNumber, lastInterestSerialNumber, rateValue, yldValue, redemptionValue, frequencyValue, basisValue);
+
+ return NumberValueObject.create(result);
+ }
+
+ private _validDate(maturitySerialNumber: number, settlementSerialNumber: number, lastInterestSerialNumber: number, frequencyValue: number): boolean {
+ return Math.floor(maturitySerialNumber) > Math.floor(settlementSerialNumber)
+ && Math.floor(settlementSerialNumber) > Math.floor(lastInterestSerialNumber)
+ && validCouppcdIsGte0ByTwoDate(lastInterestSerialNumber, maturitySerialNumber, frequencyValue);
+ }
+
+ private _getResult(
+ settlementSerialNumber: number,
+ maturitySerialNumber: number,
+ lastInterestSerialNumber: number,
+ rate: number,
+ yld: number,
+ redemption: number,
+ frequency: number,
+ basis: number
+ ): number {
+ const coupDateSerialNumber = this._getCoupDate(maturitySerialNumber, lastInterestSerialNumber, frequency);
+
+ const fAi = this._getFrac(lastInterestSerialNumber, settlementSerialNumber, coupDateSerialNumber, frequency, basis);
+ const fDCi = this._getFrac(lastInterestSerialNumber, maturitySerialNumber, coupDateSerialNumber, frequency, basis);
+ const fDSCi = this._getFrac(settlementSerialNumber, maturitySerialNumber, coupDateSerialNumber, frequency, basis);
+
+ const result = (redemption * frequency + 100 * rate * (fDCi - fAi * (1 + yld * fDSCi / frequency))) / (yld * fDSCi + frequency);
+
+ return result;
+ }
+
+ private _getCoupDate(maturitySerialNumber: number, lastInterestSerialNumber: number, frequency: number): number {
+ const maturityDate = excelSerialToDate(maturitySerialNumber);
+ const coupDate = excelSerialToDate(lastInterestSerialNumber);
+
+ coupDate.setUTCFullYear(maturityDate.getUTCFullYear());
+
+ if (coupDate > maturityDate) {
+ coupDate.setUTCFullYear(coupDate.getUTCFullYear() - 1);
+ }
+
+ // eslint-disable-next-line
+ while (coupDate < maturityDate) {
+ coupDate.setUTCMonth(coupDate.getUTCMonth() + 12 / frequency);
+ }
+
+ return excelDateSerial(coupDate);
+ }
+
+ private _getFrac(startDateSerialNumber: number, endDateSerialNumber: number, coupDateSerialNumber: number, frequency: number, basis: number): number {
+ const startDate = excelSerialToDate(startDateSerialNumber);
+ const endDate = excelSerialToDate(endDateSerialNumber);
+ const coupDate = excelSerialToDate(coupDateSerialNumber);
+
+ coupDate.setUTCFullYear(startDate.getUTCFullYear());
+
+ if (coupDate < startDate) {
+ coupDate.setUTCFullYear(coupDate.getUTCFullYear() + 1);
+ }
+
+ // eslint-disable-next-line
+ while (coupDate > startDate) {
+ coupDate.setUTCMonth(coupDate.getUTCMonth() - 12 / frequency);
+ }
+
+ let earlyCouponSerialNumber = excelDateSerial(coupDate);
+
+ coupDate.setUTCMonth(coupDate.getUTCMonth() + 12 / frequency);
+
+ let lateCouponSerialNumber = excelDateSerial(coupDate);
+
+ if (lateCouponSerialNumber >= endDateSerialNumber) {
+ const { days } = getTwoDateDaysByBasis(startDateSerialNumber, endDateSerialNumber, basis);
+ const coupdays = calculateCoupdays(earlyCouponSerialNumber, lateCouponSerialNumber, frequency, basis);
+
+ return days / coupdays;
+ }
+
+ const { days: daysF } = getTwoDateDaysByBasis(startDateSerialNumber, lateCouponSerialNumber, basis);
+ const coupdaysF = calculateCoupdays(earlyCouponSerialNumber, lateCouponSerialNumber, frequency, basis);
+ let result = daysF / coupdaysF;
+
+ const earlyCoupon = excelSerialToDate(lateCouponSerialNumber);
+ const lateCoupon = excelSerialToDate(lateCouponSerialNumber);
+ lateCoupon.setUTCMonth(lateCoupon.getUTCMonth() + 12 / frequency);
+
+ // eslint-disable-next-line
+ while (lateCoupon < endDate) {
+ earlyCoupon.setUTCMonth(earlyCoupon.getUTCMonth() + 12 / frequency);
+ lateCoupon.setUTCMonth(lateCoupon.getUTCMonth() + 12 / frequency);
+ result += 1;
+ }
+
+ earlyCouponSerialNumber = excelDateSerial(earlyCoupon);
+ lateCouponSerialNumber = excelDateSerial(lateCoupon);
+
+ const { days: daysL } = getTwoDateDaysByBasis(earlyCouponSerialNumber, endDateSerialNumber, basis);
+ const coupdaysL = calculateCoupdays(earlyCouponSerialNumber, lateCouponSerialNumber, frequency, basis);
+
+ result += daysL / coupdaysL;
+
+ return result;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/oddlyield/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/oddlyield/__tests__/index.spec.ts
new file mode 100644
index 0000000000..bc1069cf00
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/oddlyield/__tests__/index.spec.ts
@@ -0,0 +1,211 @@
+/**
+ * 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 { Oddlyield } 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 oddlyield function', () => {
+ const testFunction = new Oddlyield(FUNCTION_NAMES_FINANCIAL.ODDLYIELD);
+
+ describe('Oddlyield', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(0.10707208890680205);
+ });
+
+ it('Value is normal, but correct order is maturity > settlement > lastInterest, otherwise return #NUM!', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2018-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Rate < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(-0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Pr < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(-84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(0.10707509323707057);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(0.1070807374548397);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(0.10708735030923248);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(0.10705322702188155);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(0.10707674261155795);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(0.10708735030923248);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis6);
+ expect(result6.getValue()).toStrictEqual(0.10708735030923248);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-11-11');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, lastInterest, rate, pr, redemption, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const lastInterest2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, lastInterest2, rate, pr, redemption, frequency, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(settlement2, maturity, lastInterest, rate2, pr, redemption, frequency, basis);
+ expect(result4.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('2021-3-1');
+ const lastInterest = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(84.5);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, lastInterest, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/oddlyield/index.ts b/packages/engine-formula/src/functions/financial/oddlyield/index.ts
new file mode 100644
index 0000000000..830528c1cc
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/oddlyield/index.ts
@@ -0,0 +1,198 @@
+/**
+ * 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 { calculateCoupdays, validCouppcdIsGte0ByTwoDate } from '../../../basics/financial';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Oddlyield extends BaseFunction {
+ override minParams = 8;
+
+ override maxParams = 9;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ lastInterest: BaseValueObject,
+ rate: BaseValueObject,
+ pr: BaseValueObject,
+ redemption: BaseValueObject,
+ frequency: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, lastInterest, rate, pr, redemption, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, lastInterestObject, rateObject, prObject, redemptionObject, 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 lastInterestSerialNumber = getDateSerialNumberByObject(lastInterestObject);
+
+ if (typeof lastInterestSerialNumber !== 'number') {
+ return lastInterestSerialNumber;
+ }
+
+ const rateValue = +rateObject.getValue();
+ const prValue = +prObject.getValue();
+ const redemptionValue = +redemptionObject.getValue();
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(rateValue) || Number.isNaN(prValue) || Number.isNaN(redemptionValue) || Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ rateValue < 0 ||
+ prValue <= 0 ||
+ redemptionValue <= 0 ||
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ !this._validDate(maturitySerialNumber, settlementSerialNumber, lastInterestSerialNumber, frequencyValue)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = this._getResult(settlementSerialNumber, maturitySerialNumber, lastInterestSerialNumber, rateValue, prValue, redemptionValue, frequencyValue, basisValue);
+
+ return NumberValueObject.create(result);
+ }
+
+ private _validDate(maturitySerialNumber: number, settlementSerialNumber: number, lastInterestSerialNumber: number, frequencyValue: number): boolean {
+ return Math.floor(maturitySerialNumber) > Math.floor(settlementSerialNumber)
+ && Math.floor(settlementSerialNumber) > Math.floor(lastInterestSerialNumber)
+ && validCouppcdIsGte0ByTwoDate(lastInterestSerialNumber, maturitySerialNumber, frequencyValue);
+ }
+
+ private _getResult(
+ settlementSerialNumber: number,
+ maturitySerialNumber: number,
+ lastInterestSerialNumber: number,
+ rate: number,
+ pr: number,
+ redemption: number,
+ frequency: number,
+ basis: number
+ ): number {
+ const coupDateSerialNumber = this._getCoupDate(maturitySerialNumber, lastInterestSerialNumber, frequency);
+
+ const fAi = this._getFrac(lastInterestSerialNumber, settlementSerialNumber, coupDateSerialNumber, frequency, basis);
+ const fDCi = this._getFrac(lastInterestSerialNumber, maturitySerialNumber, coupDateSerialNumber, frequency, basis);
+ const fDSCi = this._getFrac(settlementSerialNumber, maturitySerialNumber, coupDateSerialNumber, frequency, basis);
+
+ const result = (frequency * (redemption - pr) + 100 * rate * (fDCi - fAi)) / (fDSCi * pr + 100 * rate * fAi * fDSCi / frequency);
+
+ return result;
+ }
+
+ private _getCoupDate(maturitySerialNumber: number, lastInterestSerialNumber: number, frequency: number): number {
+ const maturityDate = excelSerialToDate(maturitySerialNumber);
+ const coupDate = excelSerialToDate(lastInterestSerialNumber);
+
+ coupDate.setUTCFullYear(maturityDate.getUTCFullYear());
+
+ if (coupDate > maturityDate) {
+ coupDate.setUTCFullYear(coupDate.getUTCFullYear() - 1);
+ }
+
+ // eslint-disable-next-line
+ while (coupDate < maturityDate) {
+ coupDate.setUTCMonth(coupDate.getUTCMonth() + 12 / frequency);
+ }
+
+ return excelDateSerial(coupDate);
+ }
+
+ private _getFrac(startDateSerialNumber: number, endDateSerialNumber: number, coupDateSerialNumber: number, frequency: number, basis: number): number {
+ const startDate = excelSerialToDate(startDateSerialNumber);
+ const endDate = excelSerialToDate(endDateSerialNumber);
+ const coupDate = excelSerialToDate(coupDateSerialNumber);
+
+ coupDate.setUTCFullYear(startDate.getUTCFullYear());
+
+ if (coupDate < startDate) {
+ coupDate.setUTCFullYear(coupDate.getUTCFullYear() + 1);
+ }
+
+ // eslint-disable-next-line
+ while (coupDate > startDate) {
+ coupDate.setUTCMonth(coupDate.getUTCMonth() - 12 / frequency);
+ }
+
+ let earlyCouponSerialNumber = excelDateSerial(coupDate);
+
+ coupDate.setUTCMonth(coupDate.getUTCMonth() + 12 / frequency);
+
+ let lateCouponSerialNumber = excelDateSerial(coupDate);
+
+ if (lateCouponSerialNumber >= endDateSerialNumber) {
+ const { days } = getTwoDateDaysByBasis(startDateSerialNumber, endDateSerialNumber, basis);
+ const coupdays = calculateCoupdays(earlyCouponSerialNumber, lateCouponSerialNumber, frequency, basis);
+
+ return days / coupdays;
+ }
+
+ const { days: daysF } = getTwoDateDaysByBasis(startDateSerialNumber, lateCouponSerialNumber, basis);
+ const coupdaysF = calculateCoupdays(earlyCouponSerialNumber, lateCouponSerialNumber, frequency, basis);
+ let result = daysF / coupdaysF;
+
+ const earlyCoupon = excelSerialToDate(lateCouponSerialNumber);
+ const lateCoupon = excelSerialToDate(lateCouponSerialNumber);
+ lateCoupon.setUTCMonth(lateCoupon.getUTCMonth() + 12 / frequency);
+
+ // eslint-disable-next-line
+ while (lateCoupon < endDate) {
+ earlyCoupon.setUTCMonth(earlyCoupon.getUTCMonth() + 12 / frequency);
+ lateCoupon.setUTCMonth(lateCoupon.getUTCMonth() + 12 / frequency);
+ result += 1;
+ }
+
+ earlyCouponSerialNumber = excelDateSerial(earlyCoupon);
+ lateCouponSerialNumber = excelDateSerial(lateCoupon);
+
+ const { days: daysL } = getTwoDateDaysByBasis(earlyCouponSerialNumber, endDateSerialNumber, basis);
+ const coupdaysL = calculateCoupdays(earlyCouponSerialNumber, lateCouponSerialNumber, frequency, basis);
+
+ result += daysL / coupdaysL;
+
+ return result;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/pduration/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/pduration/__tests__/index.spec.ts
new file mode 100644
index 0000000000..448437fc54
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/pduration/__tests__/index.spec.ts
@@ -0,0 +1,94 @@
+/**
+ * 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 { Pduration } 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 pduration function', () => {
+ const testFunction = new Pduration(FUNCTION_NAMES_FINANCIAL.PDURATION);
+
+ describe('Pduration', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.025 / 12);
+ const pv = NumberValueObject.create(1000);
+ const fv = NumberValueObject.create(1200);
+ const result = testFunction.calculate(rate, pv, fv);
+ expect(result.getValue()).toStrictEqual(87.6054764193714);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const pv = NumberValueObject.create(1000);
+ const fv = NumberValueObject.create(1200);
+ const result = testFunction.calculate(rate, pv, fv);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = BooleanValueObject.create(true);
+ const pv = NumberValueObject.create(1000);
+ const fv = NumberValueObject.create(1200);
+ const result = testFunction.calculate(rate, pv, fv);
+ expect(result.getValue()).toStrictEqual(0.2630344058337942);
+ });
+
+ it('Value is blank cell', () => {
+ const rate = NullValueObject.create();
+ const pv = NumberValueObject.create(1000);
+ const fv = NumberValueObject.create(1200);
+ const result = testFunction.calculate(rate, pv, fv);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is normal string', () => {
+ const rate = StringValueObject.create('test');
+ const pv = NumberValueObject.create(1000);
+ const fv = NumberValueObject.create(1200);
+ const result = testFunction.calculate(rate, pv, fv);
+ 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 pv = NumberValueObject.create(1000);
+ const fv = NumberValueObject.create(1200);
+ const result = testFunction.calculate(rate, pv, fv);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, 3.1289681352195324, ErrorType.NUM],
+ [0.2630344058337942, ErrorType.NUM, ErrorType.NAME],
+ [ErrorType.NUM, 0.2273331625481107, 0.0395052645166332],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/pduration/index.ts b/packages/engine-formula/src/functions/financial/pduration/index.ts
new file mode 100644
index 0000000000..cd54a7e2fa
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/pduration/index.ts
@@ -0,0 +1,83 @@
+/**
+ * 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 Pduration extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(rate: BaseValueObject, pv: BaseValueObject, fv: BaseValueObject): BaseValueObject {
+ const maxRowLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getRowCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getRowCount() : 1,
+ fv.isArray() ? (fv as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ rate.isArray() ? (rate as ArrayValueObject).getColumnCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getColumnCount() : 1,
+ fv.isArray() ? (fv as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const rateArray = expandArrayValueObject(maxRowLength, maxColumnLength, rate, 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 resultArray = rateArray.map((rateObject, rowIndex, columnIndex) => {
+ const pvObject = pvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const fvObject = fvArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(rateObject, pvObject, fvObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_rateObject, _pvObject, _fvObject] = variants as BaseValueObject[];
+
+ const rateValue = +_rateObject.getValue();
+ const pvValue = +_pvObject.getValue();
+ const fvValue = +_fvObject.getValue();
+
+ if (rateValue <= -1) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = (Math.log(fvValue) - Math.log(pvValue)) / 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/index.ts b/packages/engine-formula/src/functions/financial/pmt/index.ts
index f15e987afe..ae119a00dd 100644
--- a/packages/engine-formula/src/functions/financial/pmt/index.ts
+++ b/packages/engine-formula/src/functions/financial/pmt/index.ts
@@ -29,7 +29,7 @@ export class Pmt extends BaseFunction {
override maxParams = 5;
- override calculate(rate: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject) {
+ override calculate(rate: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject): BaseValueObject {
const _fv = fv ?? NumberValueObject.create(0);
const _type = type ?? NumberValueObject.create(0);
diff --git a/packages/engine-formula/src/functions/financial/ppmt/index.ts b/packages/engine-formula/src/functions/financial/ppmt/index.ts
index fc89b032ac..445fdde9c9 100644
--- a/packages/engine-formula/src/functions/financial/ppmt/index.ts
+++ b/packages/engine-formula/src/functions/financial/ppmt/index.ts
@@ -29,7 +29,7 @@ export class Ppmt extends BaseFunction {
override maxParams = 6;
- override calculate(rate: BaseValueObject, per: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject) {
+ override calculate(rate: BaseValueObject, per: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject): BaseValueObject {
const _fv = fv ?? NumberValueObject.create(0);
const _type = type ?? NumberValueObject.create(0);
diff --git a/packages/engine-formula/src/functions/financial/price/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/price/__tests__/index.spec.ts
new file mode 100644
index 0000000000..6f317b4b8c
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/price/__tests__/index.spec.ts
@@ -0,0 +1,197 @@
+/**
+ * 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 { Price } 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 price function', () => {
+ const testFunction = new Price(FUNCTION_NAMES_FINANCIAL.PRICE);
+
+ describe('Price', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(113.58003983610452);
+ });
+
+ it('Settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2028-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Rate < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(-0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Yld < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(-0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(113.40580881052651);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(113.66233450391869);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(113.5813321520683);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(113.57920636475004);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(113.58127386649703);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(113.5813321520683);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis6);
+ expect(result6.getValue()).toStrictEqual(113.5813321520683);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-11-11');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, rate, yld, redemption, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, rate2, yld, redemption, frequency, basis);
+ expect(result3.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('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, yld, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/price/index.ts b/packages/engine-formula/src/functions/financial/price/index.ts
new file mode 100644
index 0000000000..eef5af2be4
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/price/index.ts
@@ -0,0 +1,92 @@
+/**
+ * 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 } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { calculatePrice, validCouppcdIsGte0ByTwoDate } from '../../../basics/financial';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Price extends BaseFunction {
+ override minParams = 6;
+
+ override maxParams = 7;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ rate: BaseValueObject,
+ yld: BaseValueObject,
+ redemption: BaseValueObject,
+ frequency: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, rate, yld, redemption, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, rateObject, yldObject, redemptionObject, 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 rateValue = +rateObject.getValue();
+ const yldValue = +yldObject.getValue();
+ const redemptionValue = +redemptionObject.getValue();
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(rateValue) || Number.isNaN(yldValue) || Number.isNaN(redemptionValue) || Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ rateValue < 0 ||
+ yldValue < 0 ||
+ redemptionValue <= 0 ||
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ settlementSerialNumber >= maturitySerialNumber ||
+ !validCouppcdIsGte0ByTwoDate(settlementSerialNumber, maturitySerialNumber, frequencyValue)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = calculatePrice(settlementSerialNumber, maturitySerialNumber, rateValue, yldValue, redemptionValue, frequencyValue, basisValue);
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/pricedisc/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/pricedisc/__tests__/index.spec.ts
new file mode 100644
index 0000000000..d124670c0f
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/pricedisc/__tests__/index.spec.ts
@@ -0,0 +1,159 @@
+/**
+ * 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 { Pricedisc } 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 pricedisc function', () => {
+ const testFunction = new Pricedisc(FUNCTION_NAMES_FINANCIAL.PRICEDISC);
+
+ describe('Pricedisc', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const discount = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, discount, redemption, basis);
+ expect(result.getValue()).toStrictEqual(23.125244427062967);
+ });
+
+ it('Settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2028-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const discount = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, discount, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Discount <= 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const discount = NumberValueObject.create(-0.0625);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, discount, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Redemption <= 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const discount = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(-100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, discount, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const discount = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, discount, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, discount, redemption, basis2);
+ expect(result2.getValue()).toStrictEqual(23.09027777777777);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, discount, redemption, basis3);
+ expect(result3.getValue()).toStrictEqual(21.99652777777777);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, discount, redemption, basis4);
+ expect(result4.getValue()).toStrictEqual(23.06506849315069);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, discount, redemption, basis5);
+ expect(result5.getValue()).toStrictEqual(23.09027777777777);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, discount, redemption, basis6);
+ expect(result6.getValue()).toStrictEqual(23.09027777777777);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2021-3-1');
+ const discount = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, discount, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const discount = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const basis = BooleanValueObject.create(true);
+ const result = testFunction.calculate(settlement, maturity, discount, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2021-3-1');
+ const discount = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, discount, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-11-11');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, discount, redemption, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const discount2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, discount2, redemption, basis);
+ expect(result3.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('2021-3-1');
+ const discount = NumberValueObject.create(0.0625);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, discount, redemption, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/pricedisc/index.ts b/packages/engine-formula/src/functions/financial/pricedisc/index.ts
new file mode 100644
index 0000000000..33bc8aa8c6
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/pricedisc/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 { getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Pricedisc extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 5;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ discount: BaseValueObject,
+ redemption: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, discount, redemption, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, discountObject, 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 discountValue = +discountObject.getValue();
+ const redemptionValue = +redemptionObject.getValue();
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(discountValue) || Number.isNaN(redemptionValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ discountValue <= 0 ||
+ redemptionValue <= 0 ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ settlementSerialNumber >= maturitySerialNumber
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // B = number of days in year, depending on year basis.
+ // DSM = number of days from settlement to maturity.
+ const { days: DSM, yearDays: B } = getTwoDateDaysByBasis(settlementSerialNumber, maturitySerialNumber, basisValue);
+
+ const result = redemptionValue - discountValue * redemptionValue * DSM / B;
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/pricemat/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/pricemat/__tests__/index.spec.ts
new file mode 100644
index 0000000000..157dbee1f8
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/pricemat/__tests__/index.spec.ts
@@ -0,0 +1,172 @@
+/**
+ * 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 { Pricemat } 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 pricemat function', () => {
+ const testFunction = new Pricemat(FUNCTION_NAMES_FINANCIAL.PRICEMAT);
+
+ describe('Pricemat', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, yld, basis);
+ expect(result.getValue()).toStrictEqual(110.86278008170586);
+ });
+
+ it('Value is normal, but correct order is maturity > settlement > issue, otherwise return #NUM!', () => {
+ const settlement = StringValueObject.create('2018-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2028-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, yld, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Rate < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(-0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, yld, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Yld < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(-0.0625);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, yld, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, yld, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, issue, rate, yld, basis2);
+ expect(result2.getValue()).toStrictEqual(110.88286909824446);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, issue, rate, yld, basis3);
+ expect(result3.getValue()).toStrictEqual(110.96026004584026);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, issue, rate, yld, basis4);
+ expect(result4.getValue()).toStrictEqual(110.87891053931479);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, issue, rate, yld, basis5);
+ expect(result5.getValue()).toStrictEqual(110.88286909824446);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, issue, rate, yld, basis6);
+ expect(result6.getValue()).toStrictEqual(110.88286909824446);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, yld, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const basis = BooleanValueObject.create(true);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, yld, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, yld, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-11-11');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, issue, rate, yld, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const issue2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, issue2, rate, yld, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(settlement2, maturity, issue, rate2, yld, basis);
+ expect(result4.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('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const yld = NumberValueObject.create(0.0625);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, yld, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/pricemat/index.ts b/packages/engine-formula/src/functions/financial/pricemat/index.ts
new file mode 100644
index 0000000000..2a19a26a4c
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/pricemat/index.ts
@@ -0,0 +1,107 @@
+/**
+ * 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, getNormalYearDaysByBasis, getTwoDateDaysByBasis } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Pricemat extends BaseFunction {
+ override minParams = 5;
+
+ override maxParams = 6;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ issue: BaseValueObject,
+ rate: BaseValueObject,
+ yld: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, issue, rate, yld, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, issueObject, rateObject, yldObject, 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 issueSerialNumber = getDateSerialNumberByObject(issueObject);
+
+ if (typeof issueSerialNumber !== 'number') {
+ return issueSerialNumber;
+ }
+
+ const rateValue = +rateObject.getValue();
+ const yldValue = +yldObject.getValue();
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(rateValue) || Number.isNaN(yldValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ const isCorrectOrder = this._getDateCorrectOrder(maturitySerialNumber, settlementSerialNumber, issueSerialNumber);
+
+ if (
+ rateValue < 0 ||
+ yldValue < 0 ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ !isCorrectOrder
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // B = number of days in year, depending on year basis.
+ // DSM = number of days from settlement to maturity.
+ // DIM = number of days from issue to maturity.
+ // A = number of days from issue to settlement.
+ const B = getNormalYearDaysByBasis(settlementSerialNumber, basisValue);
+ const { days: DSM } = getTwoDateDaysByBasis(settlementSerialNumber, maturitySerialNumber, basisValue);
+ const { days: DIM } = getTwoDateDaysByBasis(issueSerialNumber, maturitySerialNumber, basisValue);
+ const { days: A } = getTwoDateDaysByBasis(issueSerialNumber, settlementSerialNumber, basisValue);
+
+ const result = (100 + DIM / B * rateValue * 100) / (1 + DSM / B * yldValue) - (A / B * rateValue * 100);
+
+ return NumberValueObject.create(result);
+ }
+
+ private _getDateCorrectOrder(maturitySerialNumber: number, settlementSerialNumber: number, issueSerialNumber: number): boolean {
+ return Math.floor(maturitySerialNumber) > Math.floor(settlementSerialNumber)
+ && Math.floor(settlementSerialNumber) > Math.floor(issueSerialNumber);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/pv/index.ts b/packages/engine-formula/src/functions/financial/pv/index.ts
index ca702d89f7..68ba42bf4e 100644
--- a/packages/engine-formula/src/functions/financial/pv/index.ts
+++ b/packages/engine-formula/src/functions/financial/pv/index.ts
@@ -28,7 +28,7 @@ export class Pv extends BaseFunction {
override maxParams = 5;
- override calculate(rate: BaseValueObject, nper: BaseValueObject, pmt: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject) {
+ override calculate(rate: BaseValueObject, nper: BaseValueObject, pmt: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject): BaseValueObject {
const _fv = fv ?? NumberValueObject.create(0);
const _type = type ?? NumberValueObject.create(0);
diff --git a/packages/engine-formula/src/functions/financial/rate/index.ts b/packages/engine-formula/src/functions/financial/rate/index.ts
index 48e8526002..e8e10ab255 100644
--- a/packages/engine-formula/src/functions/financial/rate/index.ts
+++ b/packages/engine-formula/src/functions/financial/rate/index.ts
@@ -28,7 +28,7 @@ export class Rate extends BaseFunction {
override maxParams = 6;
- override calculate(nper: BaseValueObject, pmt: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject, guess?: BaseValueObject) {
+ override calculate(nper: BaseValueObject, pmt: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject, guess?: BaseValueObject): BaseValueObject {
const _fv = fv ?? NumberValueObject.create(0);
const _type = type ?? NumberValueObject.create(0);
const _guess = guess ?? NumberValueObject.create(0.1);
diff --git a/packages/engine-formula/src/functions/financial/received/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/received/__tests__/index.spec.ts
new file mode 100644
index 0000000000..37ffe8326c
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/received/__tests__/index.spec.ts
@@ -0,0 +1,163 @@
+/**
+ * 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 { Received } 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 received function', () => {
+ const testFunction = new Received(FUNCTION_NAMES_FINANCIAL.RECEIVED);
+
+ describe('Received', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-2-15');
+ const maturity = StringValueObject.create('2008-3-15');
+ const investment = NumberValueObject.create(10000000);
+ const discount = NumberValueObject.create(0.0575);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, discount, basis);
+ expect(result.getValue()).toStrictEqual(10046534.991941841);
+
+ const settlement2 = StringValueObject.create('1990-2-15');
+ const result2 = testFunction.calculate(settlement2, maturity, investment, discount, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2028-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const investment = NumberValueObject.create(10000000);
+ const discount = NumberValueObject.create(0.0575);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, discount, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('investment <= 0', () => {
+ const settlement = StringValueObject.create('2008-2-15');
+ const maturity = StringValueObject.create('2008-3-15');
+ const investment = NumberValueObject.create(-10000000);
+ const discount = NumberValueObject.create(0.0575);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, discount, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Discount <= 0', () => {
+ const settlement = StringValueObject.create('2008-2-15');
+ const maturity = StringValueObject.create('2008-3-15');
+ const investment = NumberValueObject.create(10000000);
+ const discount = NumberValueObject.create(-0.0575);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, discount, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2008-2-15');
+ const maturity = StringValueObject.create('2008-3-15');
+ const investment = NumberValueObject.create(10000000);
+ const discount = NumberValueObject.create(0.0575);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, investment, discount, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, investment, discount, basis2);
+ expect(result2.getValue()).toStrictEqual(10048147.372828135);
+
+ const basis3 = NumberValueObject.create(1);
+ const result3 = testFunction.calculate(settlement, maturity, investment, discount, basis3);
+ expect(result3.getValue()).toStrictEqual(10045768.631675735);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, investment, discount, basis4);
+ expect(result4.getValue()).toStrictEqual(10045894.60067569);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, investment, discount, basis5);
+ expect(result5.getValue()).toStrictEqual(10048147.372828135);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, investment, discount, basis6);
+ expect(result6.getValue()).toStrictEqual(10048147.372828135);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2008-3-15');
+ const investment = NumberValueObject.create(10000000);
+ const discount = NumberValueObject.create(0.0575);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, discount, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-2-15');
+ const maturity = StringValueObject.create('2008-3-15');
+ const investment = NumberValueObject.create(10000000);
+ const discount = NumberValueObject.create(0.0575);
+ const basis = BooleanValueObject.create(true);
+ const result = testFunction.calculate(settlement, maturity, investment, discount, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2008-3-15');
+ const investment = NumberValueObject.create(10000000);
+ const discount = NumberValueObject.create(0.0575);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, discount, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-2-15');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, investment, discount, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const discount2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, investment, discount2, basis);
+ expect(result3.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-3-15');
+ const investment = NumberValueObject.create(10000000);
+ const discount = NumberValueObject.create(0.0575);
+ const basis = NumberValueObject.create(2);
+ const result = testFunction.calculate(settlement, maturity, investment, discount, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/received/index.ts b/packages/engine-formula/src/functions/financial/received/index.ts
new file mode 100644
index 0000000000..87b15c2154
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/received/index.ts
@@ -0,0 +1,92 @@
+/**
+ * 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 { checkVariantsErrorIsNullorArrayOrBoolean } 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 Received extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 5;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ investment: BaseValueObject,
+ discount: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, investment, discount, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, investmentObject, discountObject, 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 discountValue = +discountObject.getValue();
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(investmentValue) || Number.isNaN(discountValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ investmentValue <= 0 ||
+ discountValue <= 0 ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ settlementSerialNumber >= maturitySerialNumber
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // B = number of days in year, depending on year basis.
+ // DSM = number of days from settlement to maturity.
+ const { days: DSM, yearDays: B } = getTwoDateDaysByBasis(settlementSerialNumber, maturitySerialNumber, basisValue);
+
+ const result = investmentValue / (1 - (discountValue * DSM / B));
+
+ if (result < 0) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/rri/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/rri/__tests__/index.spec.ts
new file mode 100644
index 0000000000..36cf330276
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/rri/__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 { Rri } 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 rri function', () => {
+ const testFunction = new Rri(FUNCTION_NAMES_FINANCIAL.RRI);
+
+ describe('Rri', () => {
+ it('Value is normal', () => {
+ const nper = NumberValueObject.create(96);
+ const pv = NumberValueObject.create(10000);
+ const fv = NumberValueObject.create(11000);
+ const result = testFunction.calculate(nper, pv, fv);
+ expect(result.getValue()).toStrictEqual(0.0009933073762913303);
+ });
+
+ it('Nper <= 0', () => {
+ const nper = NumberValueObject.create(-96);
+ const pv = NumberValueObject.create(10000);
+ const fv = NumberValueObject.create(11000);
+ const result = testFunction.calculate(nper, pv, fv);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Pv === 0 && fv === 0', () => {
+ const nper = NumberValueObject.create(96);
+ const pv = NumberValueObject.create(0);
+ const fv = NumberValueObject.create(0);
+ const result = testFunction.calculate(nper, pv, fv);
+ expect(result.getValue()).toStrictEqual(0);
+ });
+
+ it('Only pv === 0', () => {
+ const nper = NumberValueObject.create(96);
+ const pv = NumberValueObject.create(0);
+ const fv = NumberValueObject.create(11000);
+ const result = testFunction.calculate(nper, pv, fv);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Fv / pv < 0', () => {
+ const nper = NumberValueObject.create(96);
+ const pv = NumberValueObject.create(-10000);
+ const fv = NumberValueObject.create(11000);
+ const result = testFunction.calculate(nper, pv, fv);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is error', () => {
+ const nper = ErrorValueObject.create(ErrorType.NAME);
+ const pv = NumberValueObject.create(10000);
+ const fv = NumberValueObject.create(11000);
+ const result = testFunction.calculate(nper, pv, fv);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const nper = BooleanValueObject.create(true);
+ const pv = NumberValueObject.create(10000);
+ const fv = NumberValueObject.create(11000);
+ const result = testFunction.calculate(nper, pv, fv);
+ expect(result.getValue()).toStrictEqual(0.10000000000000009);
+ });
+
+ it('Value is blank cell', () => {
+ const nper = NullValueObject.create();
+ const pv = NumberValueObject.create(10000);
+ const fv = NumberValueObject.create(11000);
+ const result = testFunction.calculate(nper, pv, fv);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is normal string', () => {
+ const nper = StringValueObject.create('test');
+ const pv = NumberValueObject.create(10000);
+ const fv = NumberValueObject.create(11000);
+ const result = testFunction.calculate(nper, pv, fv);
+ 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 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 result = testFunction.calculate(nper, pv, fv);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, -1, ErrorType.NUM],
+ [-1, ErrorType.NUM, ErrorType.NAME],
+ [ErrorType.NUM, 0, 0],
+ [ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/rri/index.ts b/packages/engine-formula/src/functions/financial/rri/index.ts
new file mode 100644
index 0000000000..d6937d429e
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/rri/index.ts
@@ -0,0 +1,87 @@
+/**
+ * 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 Rri extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 6;
+
+ override calculate(nper: BaseValueObject, pv: BaseValueObject, fv: BaseValueObject): BaseValueObject {
+ const maxRowLength = Math.max(
+ nper.isArray() ? (nper as ArrayValueObject).getRowCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getRowCount() : 1,
+ fv.isArray() ? (fv as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ nper.isArray() ? (nper as ArrayValueObject).getColumnCount() : 1,
+ pv.isArray() ? (pv as ArrayValueObject).getColumnCount() : 1,
+ fv.isArray() ? (fv as ArrayValueObject).getColumnCount() : 1
+ );
+
+ 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 resultArray = nperArray.map((nperObject, rowIndex, columnIndex) => {
+ const pvObject = pvArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const fvObject = fvArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(nperObject, pvObject, fvObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_nperObject, _pvObject, _fvObject] = variants as BaseValueObject[];
+
+ const nperValue = +_nperObject.getValue();
+ const pvValue = +_pvObject.getValue();
+ const fvValue = +_fvObject.getValue();
+
+ if (nperValue <= 0) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (pvValue === 0 && fvValue === 0) {
+ return NumberValueObject.create(0);
+ }
+
+ const result = (fvValue / pvValue) ** (1 / nperValue) - 1;
+
+ if (Number.isNaN(result) || !Number.isFinite(result) || fvValue / pvValue < 0) {
+ 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/sln/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/sln/__tests__/index.spec.ts
new file mode 100644
index 0000000000..4f2ba93bdd
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/sln/__tests__/index.spec.ts
@@ -0,0 +1,123 @@
+/**
+ * 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 { Sln } 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 { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test sln function', () => {
+ const testFunction = new Sln(FUNCTION_NAMES_FINANCIAL.SLN);
+
+ describe('Sln', () => {
+ it('Value is normal', () => {
+ const cost = NumberValueObject.create(300000);
+ const salvage = NumberValueObject.create(75000);
+ const life = NumberValueObject.create(10);
+ const result = testFunction.calculate(cost, salvage, life);
+ expect(result.getValue()).toStrictEqual(22500);
+ });
+
+ it('Value is normal string', () => {
+ const cost = StringValueObject.create('test');
+ const salvage = NumberValueObject.create(75000);
+ const life = NumberValueObject.create(10);
+ const result = testFunction.calculate(cost, salvage, life);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is boolean', () => {
+ const cost = NumberValueObject.create(300000);
+ const salvage = NumberValueObject.create(75000);
+ const life = BooleanValueObject.create(true);
+ const result = testFunction.calculate(cost, salvage, life);
+ expect(result.getValue()).toStrictEqual(225000);
+ });
+
+ it('Value is null', () => {
+ const cost = NumberValueObject.create(300000);
+ const salvage = NumberValueObject.create(75000);
+ const life = NullValueObject.create();
+ const result = testFunction.calculate(cost, salvage, life);
+ expect(result.getValue()).toStrictEqual(ErrorType.DIV_BY_ZERO);
+ });
+
+ it('Value is error', () => {
+ const cost = NumberValueObject.create(300000);
+ const salvage = ErrorValueObject.create(ErrorType.NAME);
+ const life = NumberValueObject.create(10);
+ const result = testFunction.calculate(cost, salvage, life);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const salvage2 = NumberValueObject.create(75000);
+ const life2 = ErrorValueObject.create(ErrorType.NAME);
+ const result2 = testFunction.calculate(cost, salvage2, life2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('value is array', () => {
+ const cost = 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 salvage = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, -200, false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 4,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const life = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ [10],
+ [false],
+ [null],
+ ]),
+ rowCount: 4,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(cost, salvage, life);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, 200.06, 0, ErrorType.NA],
+ [0, 20, 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/sln/index.ts b/packages/engine-formula/src/functions/financial/sln/index.ts
new file mode 100644
index 0000000000..46a34b1fd7
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/sln/index.ts
@@ -0,0 +1,85 @@
+/**
+ * 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 { expandArrayValueObject } from '../../../engine/utils/array-object';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+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 Sln extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject): BaseValueObject {
+ 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
+ );
+
+ 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
+ );
+
+ 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 resultArray = costArray.map((costObject, rowIndex, columnIndex) => {
+ const salvageObject = salvageArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const lifeObject = lifeArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ if (salvageObject.isError()) {
+ return salvageObject;
+ }
+
+ if (lifeObject.isError()) {
+ return lifeObject;
+ }
+
+ const costValue = +costObject.getValue();
+ const salvageValue = +salvageObject.getValue();
+ const lifeValue = +lifeObject.getValue();
+
+ if (Number.isNaN(costValue) || Number.isNaN(salvageValue) || Number.isNaN(lifeValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (lifeValue === 0) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ const result = (costValue - salvageValue) / lifeValue;
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ }
+
+ 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/syd/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/syd/__tests__/index.spec.ts
new file mode 100644
index 0000000000..c725141ae8
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/syd/__tests__/index.spec.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 { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';
+import { Syd } 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 { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test syd function', () => {
+ const testFunction = new Syd(FUNCTION_NAMES_FINANCIAL.SYD);
+
+ describe('Syd', () => {
+ it('Value is normal', () => {
+ const cost = NumberValueObject.create(300000);
+ const salvage = NumberValueObject.create(75000);
+ const life = NumberValueObject.create(10);
+ const per = NumberValueObject.create(10);
+ const result = testFunction.calculate(cost, salvage, life, per);
+ expect(result.getValue()).toStrictEqual(4090.909090909091);
+ });
+
+ it('Value is normal string', () => {
+ const cost = StringValueObject.create('test');
+ const salvage = NumberValueObject.create(75000);
+ const life = NumberValueObject.create(10);
+ const per = NumberValueObject.create(10);
+ const result = testFunction.calculate(cost, salvage, life, per);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is boolean', () => {
+ const cost = NumberValueObject.create(300000);
+ const salvage = NumberValueObject.create(75000);
+ const life = BooleanValueObject.create(true);
+ const per = NumberValueObject.create(1);
+ const result = testFunction.calculate(cost, salvage, life, per);
+ expect(result.getValue()).toStrictEqual(225000);
+ });
+
+ it('Value is null', () => {
+ const cost = NumberValueObject.create(300000);
+ const salvage = NumberValueObject.create(75000);
+ const life = NullValueObject.create();
+ const per = NumberValueObject.create(10);
+ const result = testFunction.calculate(cost, salvage, life, per);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is error', () => {
+ const cost = NumberValueObject.create(300000);
+ const salvage = ErrorValueObject.create(ErrorType.NAME);
+ const life = NumberValueObject.create(10);
+ const per = NumberValueObject.create(10);
+ const result = testFunction.calculate(cost, salvage, life, per);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const salvage2 = NumberValueObject.create(75000);
+ const life2 = ErrorValueObject.create(ErrorType.NAME);
+ const result2 = testFunction.calculate(cost, salvage2, life2, per);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const per2 = ErrorValueObject.create(ErrorType.NAME);
+ const result3 = testFunction.calculate(cost, salvage2, life, per2);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Salvage < 0', () => {
+ const cost = NumberValueObject.create(300000);
+ const salvage = NumberValueObject.create(-1);
+ const life = NumberValueObject.create(10);
+ const per = NumberValueObject.create(10);
+ const result = testFunction.calculate(cost, salvage, life, per);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Per > life', () => {
+ const cost = NumberValueObject.create(300000);
+ const salvage = NumberValueObject.create(75000);
+ const life = NumberValueObject.create(10);
+ const per = NumberValueObject.create(11);
+ const result = testFunction.calculate(cost, salvage, life, per);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('value is array', () => {
+ const cost = 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 salvage = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, -200, false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 4,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const life = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ [10],
+ [false],
+ [null],
+ ]),
+ rowCount: 4,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const per = NumberValueObject.create(1);
+ const result = testFunction.calculate(cost, salvage, life, per);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.VALUE, ErrorType.NUM, 0, ErrorType.NA],
+ [0, 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/syd/index.ts b/packages/engine-formula/src/functions/financial/syd/index.ts
new file mode 100644
index 0000000000..e53e4a4d55
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/syd/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 { ErrorType } from '../../../basics/error-type';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+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 Syd extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 4;
+
+ override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject, per: BaseValueObject): BaseValueObject {
+ 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,
+ per.isArray() ? (per 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,
+ per.isArray() ? (per 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 perArray = expandArrayValueObject(maxRowLength, maxColumnLength, per, 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 perObject = perArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ if (salvageObject.isError()) {
+ return salvageObject;
+ }
+
+ if (lifeObject.isError()) {
+ return lifeObject;
+ }
+
+ if (perObject.isError()) {
+ return perObject;
+ }
+
+ const costValue = +costObject.getValue();
+ const salvageValue = +salvageObject.getValue();
+ const lifeValue = +lifeObject.getValue();
+ const perValue = +perObject.getValue();
+
+ if (Number.isNaN(costValue) || Number.isNaN(salvageValue) || Number.isNaN(lifeValue) || Number.isNaN(perValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ salvageValue < 0 ||
+ lifeValue <= 0 ||
+ perValue > lifeValue
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = (costValue - salvageValue) * (lifeValue - perValue + 1) * 2 / (lifeValue * (lifeValue + 1));
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ }
+
+ 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/tbilleq/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/tbilleq/__tests__/index.spec.ts
new file mode 100644
index 0000000000..0f4c8d7891
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/tbilleq/__tests__/index.spec.ts
@@ -0,0 +1,125 @@
+/**
+ * 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 { Tbilleq } 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 tbilleq function', () => {
+ const testFunction = new Tbilleq(FUNCTION_NAMES_FINANCIAL.TBILLEQ);
+
+ describe('Tbilleq', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(0.09415149356594302);
+
+ const maturity2 = StringValueObject.create('2008-11-1');
+ const result2 = testFunction.calculate(settlement, maturity2, discount);
+ expect(result2.getValue()).toStrictEqual(0.09730435851979326);
+ });
+
+ it('Settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2018-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Maturity is more than one year after settlement', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2018-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Discount <= 0 || discount to result < 0 or NaN', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = NumberValueObject.create(-0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const discount2 = NumberValueObject.create(11);
+ const result2 = testFunction.calculate(settlement, maturity, discount2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const maturity2 = StringValueObject.create('2008-12-1');
+ const result3 = testFunction.calculate(settlement, maturity2, discount2);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = BooleanValueObject.create(true);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-3-31');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, discount);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const discount2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, discount2);
+ expect(result3.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-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/tbilleq/index.ts b/packages/engine-formula/src/functions/financial/tbilleq/index.ts
new file mode 100644
index 0000000000..bedcdbad21
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/tbilleq/index.ts
@@ -0,0 +1,95 @@
+/**
+ * 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 { excelSerialToDate, getDateSerialNumberByObject, getDaysInYear } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Tbilleq extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, discount: BaseValueObject): BaseValueObject {
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, discount);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, discountObject] = variants as BaseValueObject[];
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const maturitySerialNumber = getDateSerialNumberByObject(maturityObject);
+
+ if (typeof maturitySerialNumber !== 'number') {
+ return maturitySerialNumber;
+ }
+
+ const discountValue = +discountObject.getValue();
+
+ if (Number.isNaN(discountValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ discountValue <= 0 ||
+ settlementSerialNumber >= maturitySerialNumber
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // where DSM is the number of days between settlement and maturity computed according to the 360 days per year basis.
+ const DSM = Math.floor(maturitySerialNumber) - Math.floor(settlementSerialNumber);
+
+ const date = excelSerialToDate(settlementSerialNumber);
+ const year = date.getUTCFullYear();
+ const yearDays = getDaysInYear(year);
+
+ // if maturity is more than one year after settlement, TBILLEQ returns the #NUM! error value.
+ if (DSM > yearDays) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // TBILLEQ is calculated as TBILLEQ = (365 x rate)/(360-(rate x DSM))
+ let result = (365 * discountValue) / (360 - (discountValue * DSM));
+
+ if (DSM > 182) {
+ const tbillPrice = 100 * (1 - discountValue * DSM / 360);
+ const fraction = DSM / 365;
+
+ result = (-fraction + Math.sqrt(fraction * fraction - (fraction * 2 - 1) * (1 - 100 / tbillPrice))) / (fraction - 0.5);
+
+ if (Number.isNaN(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+ }
+
+ if (result < 0) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/tbillprice/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/tbillprice/__tests__/index.spec.ts
new file mode 100644
index 0000000000..74ed46001c
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/tbillprice/__tests__/index.spec.ts
@@ -0,0 +1,117 @@
+/**
+ * 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 { Tbillprice } 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 tbillprice function', () => {
+ const testFunction = new Tbillprice(FUNCTION_NAMES_FINANCIAL.TBILLPRICE);
+
+ describe('Tbillprice', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(98.42588888888889);
+ });
+
+ it('Settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2018-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Maturity is more than one year after settlement', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2018-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Discount <= 0 || discount to result < 0 or NaN', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = NumberValueObject.create(-0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const discount2 = NumberValueObject.create(11);
+ const result2 = testFunction.calculate(settlement, maturity, discount2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = BooleanValueObject.create(true);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2008-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-3-31');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, discount);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const discount2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, discount2);
+ expect(result3.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-6-1');
+ const discount = NumberValueObject.create(0.0914);
+ const result = testFunction.calculate(settlement, maturity, discount);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/tbillprice/index.ts b/packages/engine-formula/src/functions/financial/tbillprice/index.ts
new file mode 100644
index 0000000000..1488bcc304
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/tbillprice/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 { excelSerialToDate, getDateSerialNumberByObject, getDaysInYear } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Tbillprice extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, discount: BaseValueObject): BaseValueObject {
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, discount);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, discountObject] = variants as BaseValueObject[];
+
+ const settlementSerialNumber = getDateSerialNumberByObject(settlementObject);
+
+ if (typeof settlementSerialNumber !== 'number') {
+ return settlementSerialNumber;
+ }
+
+ const maturitySerialNumber = getDateSerialNumberByObject(maturityObject);
+
+ if (typeof maturitySerialNumber !== 'number') {
+ return maturitySerialNumber;
+ }
+
+ const discountValue = +discountObject.getValue();
+
+ if (Number.isNaN(discountValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ discountValue <= 0 ||
+ settlementSerialNumber >= maturitySerialNumber
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // where DSM is the number of days between settlement and maturity computed according to the 360 days per year basis.
+ const DSM = Math.floor(maturitySerialNumber) - Math.floor(settlementSerialNumber);
+
+ const date = excelSerialToDate(settlementSerialNumber);
+ const year = date.getUTCFullYear();
+ const yearDays = getDaysInYear(year);
+
+ // if maturity is more than one year after settlement, TBILLPRICE returns the #NUM! error value.
+ if (DSM > yearDays) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // TBILLPRICE is calculated as TBILLPRICE = 100 x (1 - discount x DSM / 360)
+ const result = 100 * (1 - discountValue * DSM / 360);
+
+ if (result < 0) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/tbillyield/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/tbillyield/__tests__/index.spec.ts
new file mode 100644
index 0000000000..e097228da9
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/tbillyield/__tests__/index.spec.ts
@@ -0,0 +1,113 @@
+/**
+ * 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 { Tbillyield } 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 tbillyield function', () => {
+ const testFunction = new Tbillyield(FUNCTION_NAMES_FINANCIAL.TBILLYIELD);
+
+ describe('Tbillyield', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const pr = NumberValueObject.create(98.45);
+ const result = testFunction.calculate(settlement, maturity, pr);
+ expect(result.getValue()).toStrictEqual(0.09141696292534264);
+ });
+
+ it('Settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2018-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const pr = NumberValueObject.create(98.45);
+ const result = testFunction.calculate(settlement, maturity, pr);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Maturity is more than one year after settlement', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2018-6-1');
+ const pr = NumberValueObject.create(98.45);
+ const result = testFunction.calculate(settlement, maturity, pr);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('pr <= 0', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const pr = NumberValueObject.create(-98.45);
+ const result = testFunction.calculate(settlement, maturity, pr);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2008-6-1');
+ const pr = NumberValueObject.create(98.45);
+ const result = testFunction.calculate(settlement, maturity, pr);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-3-31');
+ const maturity = StringValueObject.create('2008-6-1');
+ const pr = BooleanValueObject.create(true);
+ const result = testFunction.calculate(settlement, maturity, pr);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2008-6-1');
+ const pr = NumberValueObject.create(98.45);
+ const result = testFunction.calculate(settlement, maturity, pr);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-3-31');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, pr);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const pr2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, pr2);
+ expect(result3.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-6-1');
+ const pr = NumberValueObject.create(98.45);
+ const result = testFunction.calculate(settlement, maturity, pr);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/tbillyield/index.ts b/packages/engine-formula/src/functions/financial/tbillyield/index.ts
new file mode 100644
index 0000000000..0e5492a0e9
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/tbillyield/index.ts
@@ -0,0 +1,80 @@
+/**
+ * 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 { excelSerialToDate, getDateSerialNumberByObject, getDaysInYear } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Tbillyield extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(settlement: BaseValueObject, maturity: BaseValueObject, pr: BaseValueObject): BaseValueObject {
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, pr);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, prObject] = 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();
+
+ if (Number.isNaN(prValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ prValue <= 0 ||
+ settlementSerialNumber >= maturitySerialNumber
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // where DSM is the number of days between settlement and maturity computed according to the 360 days per year basis.
+ const DSM = Math.floor(maturitySerialNumber) - Math.floor(settlementSerialNumber);
+
+ const date = excelSerialToDate(settlementSerialNumber);
+ const year = date.getUTCFullYear();
+ const yearDays = getDaysInYear(year);
+
+ // if maturity is more than one year after settlement, TBILLYIELD returns the #NUM! error value.
+ if (DSM > yearDays) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // TBILLYIELD is calculated as TBILLYIELD = (100 - pr) / pr x 360 / DSM
+ const result = (100 - prValue) / prValue * 360 / DSM;
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/vdb/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/vdb/__tests__/index.spec.ts
new file mode 100644
index 0000000000..827fe41297
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/vdb/__tests__/index.spec.ts
@@ -0,0 +1,155 @@
+/**
+ * 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 { Vdb } from '../index';
+import { NullValueObject, 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 vdb function', () => {
+ const testFunction = new Vdb(FUNCTION_NAMES_FINANCIAL.VDB);
+
+ describe('Vdb', () => {
+ it('Value is normal', () => {
+ const cost = NumberValueObject.create(24000);
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(10);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const factor = NumberValueObject.create(2);
+ const noSwitch = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, salvage, life, startPeriod, endPeriod, factor, noSwitch);
+ expect(result.getValue()).toStrictEqual(3840);
+ });
+
+ it('Cost is normal string', () => {
+ const cost = StringValueObject.create('test');
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(10);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const factor = NumberValueObject.create(2);
+ const noSwitch = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, salvage, life, startPeriod, endPeriod, factor, noSwitch);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Cost < 0 || salvage < 0 || cost < salvage', () => {
+ const cost = NumberValueObject.create(-24000);
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(10);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const factor = NumberValueObject.create(2);
+ const noSwitch = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, salvage, life, startPeriod, endPeriod, factor, noSwitch);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const salvage2 = NumberValueObject.create(-3000);
+ const result2 = testFunction.calculate(cost, salvage2, life, startPeriod, endPeriod, factor, noSwitch);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const cost3 = NumberValueObject.create(2400);
+ const salvage3 = NumberValueObject.create(3000);
+ const result3 = testFunction.calculate(cost3, salvage3, life, startPeriod, endPeriod, factor, noSwitch);
+ expect(result3.getValue()).toStrictEqual(0);
+
+ const startPeriod4 = NumberValueObject.create(0.1);
+ const result4 = testFunction.calculate(cost3, salvage3, life, startPeriod4, endPeriod, factor, noSwitch);
+ expect(result4.getValue()).toStrictEqual(-600);
+ });
+
+ it('Life === 0 && startPeriod === 0 && endPeriod === 0', () => {
+ const cost = NumberValueObject.create(24000);
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(0);
+ const startPeriod = NumberValueObject.create(0);
+ const endPeriod = NumberValueObject.create(0);
+ const factor = NumberValueObject.create(2);
+ const noSwitch = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, salvage, life, startPeriod, endPeriod, factor, noSwitch);
+ expect(result.getValue()).toStrictEqual(ErrorType.DIV_BY_ZERO);
+ });
+
+ it('StartPeriod > endPeriod > life || StartPeriod > life / 2', () => {
+ const cost = NumberValueObject.create(24000);
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(10);
+ const startPeriod = NumberValueObject.create(22);
+ const endPeriod = NumberValueObject.create(12);
+ const factor = NumberValueObject.create(2);
+ const noSwitch = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, salvage, life, startPeriod, endPeriod, factor, noSwitch);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const startPeriod2 = NumberValueObject.create(6.1);
+ const endPeriod2 = NumberValueObject.create(6.2);
+ const result2 = testFunction.calculate(cost, salvage, life, startPeriod2, endPeriod2, factor, noSwitch);
+ expect(result2.getValue()).toStrictEqual(123.31253760000065);
+ });
+
+ it('NoSwitch test', () => {
+ const cost = NumberValueObject.create(24000);
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(10);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const factor = NumberValueObject.create(2);
+ const noSwitch = NumberValueObject.create(1);
+ const result = testFunction.calculate(cost, salvage, life, startPeriod, endPeriod, factor, noSwitch);
+ expect(result.getValue()).toStrictEqual(3839.9999999999964);
+ });
+
+ it('Value is null', () => {
+ const cost = NumberValueObject.create(24000);
+ const salvage = NumberValueObject.create(3000);
+ const life = NumberValueObject.create(10);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const factor = NullValueObject.create();
+ const noSwitch = NullValueObject.create();
+ const result = testFunction.calculate(cost, salvage, life, startPeriod, endPeriod, factor, noSwitch);
+ expect(result.getValue()).toStrictEqual(3840);
+ });
+
+ 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(10);
+ const startPeriod = NumberValueObject.create(1);
+ const endPeriod = NumberValueObject.create(2);
+ const factor = NumberValueObject.create(2);
+ const noSwitch = NumberValueObject.create(0);
+ const result = testFunction.calculate(cost, salvage, life, startPeriod, endPeriod, factor, noSwitch);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [3840, ErrorType.VALUE, 0, 0, ErrorType.NAME, 0],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/vdb/index.ts b/packages/engine-formula/src/functions/financial/vdb/index.ts
new file mode 100644
index 0000000000..3816a3cc87
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/vdb/index.ts
@@ -0,0 +1,232 @@
+/**
+ * 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 { BooleanValueObject, 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';
+import { calculateDDB } from '../../../basics/financial';
+
+export class Vdb extends BaseFunction {
+ override minParams = 5;
+
+ override maxParams = 7;
+
+ override calculate(
+ cost: BaseValueObject,
+ salvage: BaseValueObject,
+ life: BaseValueObject,
+ startPeriod: BaseValueObject,
+ endPeriod: BaseValueObject,
+ factor?: BaseValueObject,
+ noSwitch?: BaseValueObject
+ ): BaseValueObject {
+ let _factor = factor ?? NumberValueObject.create(2);
+
+ if (_factor.isNull()) {
+ _factor = NumberValueObject.create(2);
+ }
+
+ let _noSwitch = noSwitch ?? BooleanValueObject.create(false);
+
+ if (_noSwitch.isNull()) {
+ _noSwitch = BooleanValueObject.create(false);
+ }
+
+ 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,
+ startPeriod.isArray() ? (startPeriod as ArrayValueObject).getRowCount() : 1,
+ endPeriod.isArray() ? (endPeriod as ArrayValueObject).getRowCount() : 1,
+ _factor.isArray() ? (_factor as ArrayValueObject).getRowCount() : 1,
+ _noSwitch.isArray() ? (_noSwitch 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,
+ startPeriod.isArray() ? (startPeriod as ArrayValueObject).getColumnCount() : 1,
+ endPeriod.isArray() ? (endPeriod as ArrayValueObject).getColumnCount() : 1,
+ _factor.isArray() ? (_factor as ArrayValueObject).getColumnCount() : 1,
+ _noSwitch.isArray() ? (_noSwitch 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 startPeriodArray = expandArrayValueObject(maxRowLength, maxColumnLength, startPeriod, ErrorValueObject.create(ErrorType.NA));
+ const endPeriodArray = expandArrayValueObject(maxRowLength, maxColumnLength, endPeriod, ErrorValueObject.create(ErrorType.NA));
+ const factorArray = expandArrayValueObject(maxRowLength, maxColumnLength, _factor, ErrorValueObject.create(ErrorType.NA));
+ const noSwitchArray = expandArrayValueObject(maxRowLength, maxColumnLength, _noSwitch, ErrorValueObject.create(ErrorType.NA));
+
+ return this._getResultArray(
+ costArray,
+ salvageArray,
+ lifeArray,
+ startPeriodArray,
+ endPeriodArray,
+ factorArray,
+ noSwitchArray,
+ maxRowLength,
+ maxColumnLength
+ );
+ }
+
+ private _getResultArray(
+ costArray: ArrayValueObject,
+ salvageArray: ArrayValueObject,
+ lifeArray: ArrayValueObject,
+ startPeriodArray: ArrayValueObject,
+ endPeriodArray: ArrayValueObject,
+ factorArray: ArrayValueObject,
+ noSwitchArray: ArrayValueObject,
+ maxRowLength: number,
+ maxColumnLength: number
+ ): BaseValueObject {
+ const resultArray = costArray.map((costObject, rowIndex, columnIndex) => {
+ const salvageObject = salvageArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const lifeObject = lifeArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const startPeriodObject = startPeriodArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const endPeriodObject = endPeriodArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const factorObject = factorArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const noSwitchObject = noSwitchArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(costObject, salvageObject, lifeObject, startPeriodObject, endPeriodObject, factorObject, noSwitchObject);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [_costObject, _salvageObject, _lifeObject, _startPeriodObject, _endPeriodObject, _factorObject, _noSwitchObject] = variants as BaseValueObject[];
+
+ const costValue = +_costObject.getValue();
+ const salvageValue = +_salvageObject.getValue();
+ const lifeValue = +_lifeObject.getValue();
+ const startPeriodValue = +_startPeriodObject.getValue();
+ const endPeriodValue = +_endPeriodObject.getValue();
+ const factorValue = +_factorObject.getValue();
+ const noSwitchValue = +_noSwitchObject.getValue();
+
+ if (
+ costValue < 0 ||
+ salvageValue < 0 ||
+ lifeValue < 0 ||
+ startPeriodValue < 0 ||
+ endPeriodValue < 0 ||
+ endPeriodValue > lifeValue ||
+ startPeriodValue > endPeriodValue ||
+ factorValue < 0
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (lifeValue === 0 && startPeriodValue === 0 && endPeriodValue === 0) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ const result = this._getResult(costValue, salvageValue, lifeValue, startPeriodValue, endPeriodValue, factorValue, noSwitchValue);
+
+ if (rowIndex === 0 && columnIndex === 0) {
+ return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');
+ }
+
+ return NumberValueObject.create(result);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+
+ private _getResult(cost: number, salvage: number, life: number, startPeriod: number, endPeriod: number, factor: number, noSwitch: number): number {
+ const start = Math.floor(startPeriod);
+ const end = Math.ceil(endPeriod);
+
+ let result = 0;
+
+ if (cost < salvage) {
+ if (startPeriod >= 1 || noSwitch) {
+ return result;
+ }
+
+ const tempMinus = Math.abs(cost - salvage);
+ result = tempMinus * (endPeriod - startPeriod) > tempMinus ? tempMinus : tempMinus * (endPeriod - startPeriod);
+
+ return -result;
+ }
+
+ if (noSwitch) {
+ for (let i = start + 1; i <= end; i++) {
+ let ddb = calculateDDB(cost, salvage, life, i, factor);
+
+ if (i === start + 1) {
+ ddb *= (Math.min(endPeriod, start + 1) - startPeriod);
+ } else if (i === end) {
+ ddb *= (endPeriod + 1 - end);
+ }
+
+ result += ddb;
+ }
+ } else {
+ const _cost = cost - this._getVdb(cost, salvage, life, life, startPeriod, factor);
+ result = this._getVdb(_cost, salvage, life, life - startPeriod, endPeriod - startPeriod, factor);
+ }
+
+ return result;
+ }
+
+ private _getVdb(cost: number, salvage: number, life: number, startPeriod: number, endPeriod: number, factor: number): number {
+ const end = Math.ceil(endPeriod);
+
+ let result = 0;
+ let rest = cost - salvage;
+ let sln = 0;
+ let temp = 0;
+ let flag = false;
+
+ for (let i = 1; i <= end; i++) {
+ if (!flag) {
+ const ddb = calculateDDB(cost, salvage, life, i, factor);
+ sln = rest / (startPeriod - (i - 1));
+
+ if (sln > ddb) {
+ temp = sln;
+ flag = true;
+ } else {
+ temp = ddb;
+ rest -= ddb;
+ }
+ } else {
+ temp = sln;
+ }
+
+ if (i === end) {
+ temp *= (endPeriod + 1 - end);
+ }
+
+ result += temp;
+ }
+
+ return result;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/xirr/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/xirr/__tests__/index.spec.ts
new file mode 100644
index 0000000000..2e1c66a44e
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/xirr/__tests__/index.spec.ts
@@ -0,0 +1,225 @@
+/**
+ * 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 { Xirr } 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 xirr function', () => {
+ const testFunction = new Xirr(FUNCTION_NAMES_FINANCIAL.XIRR);
+
+ describe('Xirr', () => {
+ it('Value is normal', () => {
+ const values = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(values, dates, guess);
+ expect(result.getValue()).toStrictEqual(0.3733625335188314);
+ });
+
+ it('Value is normal, but no positive and negative number', () => {
+ const values = ArrayValueObject.create('{10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(values, dates, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is normal, but values.length !== dates.length', () => {
+ const values = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859}');
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(values, dates, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is error', () => {
+ const values = ErrorValueObject.create(ErrorType.NAME);
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(values, dates, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const values2 = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates2 = ErrorValueObject.create(ErrorType.NAME);
+ const result2 = testFunction.calculate(values2, dates2, guess);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const values = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const guess = BooleanValueObject.create(true);
+ const result = testFunction.calculate(values, dates, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const values2 = BooleanValueObject.create(true);
+ const guess2 = NumberValueObject.create(0.1);
+ const result2 = testFunction.calculate(values2, dates, guess2);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const values3 = NumberValueObject.create(1);
+ const result3 = testFunction.calculate(values3, dates, guess2);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NA);
+
+ const dates2 = BooleanValueObject.create(true);
+ const result4 = testFunction.calculate(values, dates2, guess2);
+ expect(result4.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const dates3 = NumberValueObject.create(1);
+ const result5 = testFunction.calculate(values, dates3, guess2);
+ expect(result5.getValue()).toStrictEqual(ErrorType.NA);
+
+ const dates4 = NumberValueObject.create(-1);
+ const result6 = testFunction.calculate(values, dates4, guess2);
+ expect(result6.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is normal string', () => {
+ const values = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const guess = StringValueObject.create('test');
+ const result = testFunction.calculate(values, dates, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is null', () => {
+ const values = NullValueObject.create();
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(values, dates, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.NA);
+
+ const values2 = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const guess2 = NullValueObject.create();
+ const result2 = testFunction.calculate(values2, dates, guess2);
+ expect(result2.getValue()).toStrictEqual(0.3733625335188314);
+ });
+
+ it('Value is array', () => {
+ const values = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const guess = NumberValueObject.create(0.1);
+ const result = testFunction.calculate(values, dates, guess);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const values2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', true, 'test', false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(values2, dates, guess);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const values3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', ErrorType.NAME, true, 'test', false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(values3, dates, guess);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const values4 = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(values4, dates2, guess);
+ expect(result4.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const dates3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', true, 'test', false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result5 = testFunction.calculate(values4, dates3, guess);
+ expect(result5.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const dates4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', ErrorType.NAME, true, 'test', false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result6 = testFunction.calculate(values4, dates4, guess);
+ expect(result6.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const dates5 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [-2, ErrorType.NAME, true, 'test', false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result7 = testFunction.calculate(values4, dates5, guess);
+ expect(result7.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const values5 = ArrayValueObject.create('{-10000}');
+ const dates6 = ArrayValueObject.create('{39448}');
+ const result8 = testFunction.calculate(values5, dates6, guess);
+ expect(result8.getValue()).toStrictEqual(ErrorType.NA);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/xirr/index.ts b/packages/engine-formula/src/functions/financial/xirr/index.ts
new file mode 100644
index 0000000000..03061820c7
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/xirr/index.ts
@@ -0,0 +1,307 @@
+/**
+ * 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 { isRealNum } from '@univerjs/core';
+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 { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import { getResultByGuessIterF } from '../../../basics/financial';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+
+interface ICheckErrorType {
+ isError: boolean;
+ errorObejct?: ErrorValueObject;
+}
+
+interface ICheckErrorValues extends ICheckErrorType {
+ _values?: number[];
+}
+
+interface ICheckErrorDates extends ICheckErrorType {
+ _dates?: number[];
+}
+
+interface ICheckNumber {
+ positive: boolean;
+ negative: boolean;
+}
+
+export class Xirr extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 3;
+
+ override calculate(values: BaseValueObject, dates: BaseValueObject, guess?: BaseValueObject): BaseValueObject {
+ if (values.isNull() || dates.isNull()) {
+ return ErrorValueObject.create(ErrorType.NA);
+ }
+
+ const { isError, errorObejct, _values, _dates } = this._checkErrors(values, dates);
+
+ if (isError) {
+ return errorObejct as ErrorValueObject;
+ }
+
+ let _guess = guess ?? NumberValueObject.create(0.1);
+
+ if (_guess.isNull()) {
+ _guess = NumberValueObject.create(0.1);
+ }
+
+ const { isError: _isError_guess, errorObject: _errorObject_guess, variants } = checkVariantsErrorIsArrayOrBoolean(_guess);
+
+ if (_isError_guess) {
+ return _errorObject_guess as ErrorValueObject;
+ }
+
+ const [guessObject] = variants as BaseValueObject[];
+
+ const guessValue = +guessObject.getValue();
+
+ if (Number.isNaN(guessValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ const { positive, negative } = this._checkValues(_values as number[]);
+
+ if (!positive || !negative || _values?.length !== _dates?.length || guessValue < 0) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = getResultByGuessIterF(guessValue, (rate: number) => this._iterF(_values as number[], _dates as number[], rate));
+
+ if (typeof result !== 'number') {
+ return result as ErrorValueObject;
+ }
+
+ return NumberValueObject.create(result);
+ }
+
+ private _checkErrors(values: BaseValueObject, dates: BaseValueObject): ICheckErrorValues & ICheckErrorDates {
+ if (values.isError()) {
+ return {
+ isError: true,
+ errorObejct: values as ErrorValueObject,
+ };
+ }
+
+ if (dates.isError()) {
+ return {
+ isError: true,
+ errorObejct: dates as ErrorValueObject,
+ };
+ }
+
+ const { isError: isError_values, errorObejct: errorObejct_values, _values } = this._checkErrorValues(values);
+
+ if (isError_values) {
+ return {
+ isError: isError_values,
+ errorObejct: errorObejct_values,
+ };
+ }
+
+ const { isError: isError_dates, errorObejct: errorObejct_dates, _dates } = this._checkErrorDates(dates);
+
+ if (isError_dates) {
+ return {
+ isError: isError_dates,
+ errorObejct: errorObejct_dates,
+ };
+ }
+
+ return {
+ isError: false,
+ _values,
+ _dates,
+ };
+ }
+
+ private _checkErrorValues(values: BaseValueObject): ICheckErrorValues {
+ const _values: number[] = [];
+
+ if (values.isArray()) {
+ let isError = false;
+ let errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+
+ (values as ArrayValueObject).iterator((valuesObject) => {
+ const _valuesObject = valuesObject as BaseValueObject;
+
+ if (_valuesObject.isError()) {
+ isError = true;
+ errorObejct = _valuesObject as ErrorValueObject;
+ return false;
+ }
+
+ if (_valuesObject.isBoolean()) {
+ isError = true;
+ errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ const value = +_valuesObject.getValue();
+
+ if (Number.isNaN(value)) {
+ isError = true;
+ errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ _values.push(value);
+ });
+
+ if (isError) {
+ return {
+ isError,
+ errorObejct,
+ };
+ }
+
+ if (_values.length <= 1) {
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.NA),
+ };
+ }
+
+ return {
+ isError,
+ _values,
+ };
+ } else {
+ const valuesValue = values.getValue();
+
+ if (values.isBoolean() || (values.isString() && !isRealNum(valuesValue))) {
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.VALUE),
+ };
+ }
+
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.NA),
+ };
+ }
+ }
+
+ private _checkErrorDates(dates: BaseValueObject): ICheckErrorDates {
+ const _dates: number[] = [];
+
+ if (dates.isArray()) {
+ let isError = false;
+ let errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+
+ (dates as ArrayValueObject).iterator((datesObject) => {
+ if (datesObject?.isError()) {
+ isError = true;
+ errorObejct = datesObject as ErrorValueObject;
+ return false;
+ }
+
+ if (datesObject?.isBoolean()) {
+ isError = true;
+ errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ const datesValue = +(datesObject as BaseValueObject).getValue();
+
+ if (Number.isNaN(datesValue)) {
+ isError = true;
+ errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ if (datesValue < 0) {
+ isError = true;
+ errorObejct = ErrorValueObject.create(ErrorType.NUM);
+ return false;
+ }
+
+ _dates.push(Math.floor(datesValue));
+ });
+
+ if (isError) {
+ return {
+ isError,
+ errorObejct,
+ };
+ }
+
+ if (_dates.length <= 1) {
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.NA),
+ };
+ }
+
+ return {
+ isError,
+ _dates,
+ };
+ } else {
+ const datesValue = dates.getValue();
+
+ if (dates.isBoolean() || (dates.isString() && !isRealNum(datesValue))) {
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.VALUE),
+ };
+ }
+
+ if (+datesValue < 0) {
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.NUM),
+ };
+ }
+
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.NA),
+ };
+ }
+ }
+
+ private _checkValues(values: number[]): ICheckNumber {
+ let positive = false;
+ let negative = false;
+
+ for (let i = 0; i < values.length; i++) {
+ if (values[i] > 0) {
+ positive = true;
+ }
+
+ if (values[i] < 0) {
+ negative = true;
+ }
+ }
+
+ return {
+ positive,
+ negative,
+ };
+ }
+
+ private _iterF(values: number[], dates: number[], rate: number): number {
+ return values.reduce((total, value, index) => {
+ return total + value / ((1 + rate) ** ((dates[index] - dates[0]) / 365));
+ }, 0);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/xnpv/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/xnpv/__tests__/index.spec.ts
new file mode 100644
index 0000000000..5e11c88d8f
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/xnpv/__tests__/index.spec.ts
@@ -0,0 +1,238 @@
+/**
+ * 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 { Xnpv } 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 xnpv function', () => {
+ const testFunction = new Xnpv(FUNCTION_NAMES_FINANCIAL.XNPV);
+
+ describe('Xnpv', () => {
+ it('Value is normal', () => {
+ const rate = NumberValueObject.create(0.1);
+ const values = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const result = testFunction.calculate(rate, values, dates);
+ expect(result.getValue()).toStrictEqual(1994.5100406532624);
+ });
+
+ it('Value is normal, but no positive and negative number', () => {
+ const rate = NumberValueObject.create(0.1);
+ const values = ArrayValueObject.create('{10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const result = testFunction.calculate(rate, values, dates);
+ expect(result.getValue()).toStrictEqual(21994.510040653262);
+ });
+
+ it('Value is normal, but values.length !== dates.length', () => {
+ const rate = NumberValueObject.create(0.1);
+ const values = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859}');
+ const result = testFunction.calculate(rate, values, dates);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is error', () => {
+ const rate = ErrorValueObject.create(ErrorType.NAME);
+ const values = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const result = testFunction.calculate(rate, values, dates);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const rate2 = NumberValueObject.create(0.1);
+ const values2 = ErrorValueObject.create(ErrorType.NAME);
+ const result2 = testFunction.calculate(rate2, values2, dates);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const dates2 = ErrorValueObject.create(ErrorType.NAME);
+ const result3 = testFunction.calculate(rate2, values, dates2);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const rate = BooleanValueObject.create(true);
+ const values = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const result = testFunction.calculate(rate, values, dates);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = NumberValueObject.create(0.1);
+ const values2 = BooleanValueObject.create(true);
+ const result2 = testFunction.calculate(rate2, values2, dates);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const values3 = NumberValueObject.create(1);
+ const result3 = testFunction.calculate(rate2, values3, dates);
+ expect(result3.getValue()).toStrictEqual(ErrorType.NA);
+
+ const dates2 = BooleanValueObject.create(true);
+ const result4 = testFunction.calculate(rate2, values, dates2);
+ expect(result4.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const dates3 = NumberValueObject.create(1);
+ const result5 = testFunction.calculate(rate2, values, dates3);
+ expect(result5.getValue()).toStrictEqual(ErrorType.NA);
+
+ const dates4 = NumberValueObject.create(-1);
+ const result6 = testFunction.calculate(rate2, values, dates4);
+ expect(result6.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Value is normal string', () => {
+ const rate = StringValueObject.create('test');
+ const values = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const result = testFunction.calculate(rate, values, dates);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is null', () => {
+ const rate = NullValueObject.create();
+ const values = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const result = testFunction.calculate(rate, values, dates);
+ expect(result.getValue()).toStrictEqual(ErrorType.NA);
+ });
+
+ it('Value is array', () => {
+ const rate = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const values = ArrayValueObject.create('{-10000,2750,4250,3250,2750}');
+ const dates = ArrayValueObject.create('{39448,39508,39751,39859,39904}');
+ const result = testFunction.calculate(rate, values, dates);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = NumberValueObject.create(0.1);
+ const values2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(rate2, values2, dates);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const values3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', true, 'test', false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(rate2, values3, dates);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const values4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', ErrorType.NAME, true, 'test', false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(rate2, values4, dates);
+ expect(result4.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const dates2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', 'test', true, false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result5 = testFunction.calculate(rate2, values, dates2);
+ expect(result5.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const dates3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', true, 'test', false, ErrorType.NAME, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result6 = testFunction.calculate(rate2, values, dates3);
+ expect(result6.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const dates4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['1.02', ErrorType.NAME, true, 'test', false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result7 = testFunction.calculate(rate2, values, dates4);
+ expect(result7.getValue()).toStrictEqual(ErrorType.NAME);
+
+ const dates5 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [-2, ErrorType.NAME, true, 'test', false, null],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result8 = testFunction.calculate(rate2, values, dates5);
+ expect(result8.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const values5 = ArrayValueObject.create('{-10000}');
+ const dates6 = ArrayValueObject.create('{39448}');
+ const result9 = testFunction.calculate(rate2, values5, dates6);
+ expect(result9.getValue()).toStrictEqual(ErrorType.NA);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/xnpv/index.ts b/packages/engine-formula/src/functions/financial/xnpv/index.ts
new file mode 100644
index 0000000000..3b3847f37f
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/xnpv/index.ts
@@ -0,0 +1,281 @@
+/**
+ * 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 { isRealNum } from '@univerjs/core';
+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 { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+import { checkVariantsErrorIsArrayOrBoolean } from '../../../engine/utils/check-variant-error';
+
+interface ICheckErrorType {
+ isError: boolean;
+ errorObejct?: ErrorValueObject;
+}
+
+interface ICheckErrorValues extends ICheckErrorType {
+ _values?: number[];
+}
+
+interface ICheckErrorDates extends ICheckErrorType {
+ _dates?: number[];
+}
+
+interface ICheckNumber {
+ positive: boolean;
+ negative: boolean;
+}
+
+export class Xnpv extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(rate: BaseValueObject, values: BaseValueObject, dates: BaseValueObject): BaseValueObject {
+ if (rate.isNull() || values.isNull() || dates.isNull()) {
+ return ErrorValueObject.create(ErrorType.NA);
+ }
+
+ const { isError: _isError_rate, errorObject: _errorObject_rate, variants } = checkVariantsErrorIsArrayOrBoolean(rate);
+
+ if (_isError_rate) {
+ return _errorObject_rate as ErrorValueObject;
+ }
+
+ const [rateObject] = variants as BaseValueObject[];
+
+ const rateValue = +rateObject.getValue();
+
+ if (Number.isNaN(rateValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ let { isError, errorObejct, _values, _dates } = this._checkErrors(values, dates);
+
+ if (isError) {
+ return errorObejct as ErrorValueObject;
+ }
+
+ _values = _values as number[];
+ _dates = _dates as number[];
+
+ if (rateValue < 0 || _values.length !== _dates.length) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ let result = 0;
+ const d1 = _dates[0];
+
+ for (let i = 0; i < _dates.length; i++) {
+ const di = _dates[i];
+ const Pi = _values[i];
+
+ result += Pi / ((1 + rateValue) ** ((di - d1) / 365));
+ }
+
+ return NumberValueObject.create(result);
+ }
+
+ private _checkErrors(values: BaseValueObject, dates: BaseValueObject): ICheckErrorValues & ICheckErrorDates {
+ if (values.isError()) {
+ return {
+ isError: true,
+ errorObejct: values as ErrorValueObject,
+ };
+ }
+
+ if (dates.isError()) {
+ return {
+ isError: true,
+ errorObejct: dates as ErrorValueObject,
+ };
+ }
+
+ const { isError: isError_values, errorObejct: errorObejct_values, _values } = this._checkErrorValues(values);
+
+ if (isError_values) {
+ return {
+ isError: isError_values,
+ errorObejct: errorObejct_values,
+ };
+ }
+
+ const { isError: isError_dates, errorObejct: errorObejct_dates, _dates } = this._checkErrorDates(dates);
+
+ if (isError_dates) {
+ return {
+ isError: isError_dates,
+ errorObejct: errorObejct_dates,
+ };
+ }
+
+ return {
+ isError: false,
+ _values,
+ _dates,
+ };
+ }
+
+ private _checkErrorValues(values: BaseValueObject): ICheckErrorValues {
+ const _values: number[] = [];
+
+ if (values.isArray()) {
+ let isError = false;
+ let errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+
+ (values as ArrayValueObject).iterator((valuesObject) => {
+ const _valuesObject = valuesObject as BaseValueObject;
+
+ if (_valuesObject.isError()) {
+ isError = true;
+ errorObejct = _valuesObject as ErrorValueObject;
+ return false;
+ }
+
+ if (_valuesObject.isNull() || _valuesObject.isBoolean()) {
+ isError = true;
+ errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ const value = +_valuesObject.getValue();
+
+ if (Number.isNaN(value)) {
+ isError = true;
+ errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ _values.push(value);
+ });
+
+ if (isError) {
+ return {
+ isError,
+ errorObejct,
+ };
+ }
+
+ if (_values.length <= 1) {
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.NA),
+ };
+ }
+
+ return {
+ isError,
+ _values,
+ };
+ } else {
+ const valuesValue = values.getValue();
+
+ if (values.isNull() || values.isBoolean() || (values.isString() && !isRealNum(valuesValue))) {
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.VALUE),
+ };
+ }
+
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.NA),
+ };
+ }
+ }
+
+ private _checkErrorDates(dates: BaseValueObject): ICheckErrorDates {
+ const _dates: number[] = [];
+
+ if (dates.isArray()) {
+ let isError = false;
+ let errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+
+ (dates as ArrayValueObject).iterator((datesObject) => {
+ const _datesObject = datesObject as BaseValueObject;
+
+ if (_datesObject.isError()) {
+ isError = true;
+ errorObejct = _datesObject as ErrorValueObject;
+ return false;
+ }
+
+ if (_datesObject.isNull() || _datesObject.isBoolean()) {
+ isError = true;
+ errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ const datesValue = +_datesObject.getValue();
+
+ if (Number.isNaN(datesValue)) {
+ isError = true;
+ errorObejct = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ if (datesValue < 0) {
+ isError = true;
+ errorObejct = ErrorValueObject.create(ErrorType.NUM);
+ return false;
+ }
+
+ _dates.push(Math.floor(datesValue));
+ });
+
+ if (isError) {
+ return {
+ isError,
+ errorObejct,
+ };
+ }
+
+ if (_dates.length <= 1) {
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.NA),
+ };
+ }
+
+ return {
+ isError,
+ _dates,
+ };
+ } else {
+ const datesValue = dates.getValue();
+
+ if (dates.isNull() || dates.isBoolean() || (dates.isString() && !isRealNum(datesValue))) {
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.VALUE),
+ };
+ }
+
+ if (+datesValue < 0) {
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.NUM),
+ };
+ }
+
+ return {
+ isError: true,
+ errorObejct: ErrorValueObject.create(ErrorType.NA),
+ };
+ }
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/yield/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/yield/__tests__/index.spec.ts
new file mode 100644
index 0000000000..48fa677133
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/yield/__tests__/index.spec.ts
@@ -0,0 +1,206 @@
+/**
+ * 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 { Yield } 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 yield function', () => {
+ const testFunction = new Yield(FUNCTION_NAMES_FINANCIAL.YIELD);
+
+ describe('Yield', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(0.08048420029608885);
+
+ const maturity2 = StringValueObject.create('2009-3-1');
+ const result2 = testFunction.calculate(settlement, maturity2, rate, pr, redemption, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(0.12952250829599993);
+ });
+
+ it('Settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2028-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Rate < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(-0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Pr <= 0 || redemption <= 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(0);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const pr2 = NumberValueObject.create(98.45);
+ const redemption2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, rate, pr2, redemption2, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Frequency value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(3);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const frequency2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency2, basis);
+ expect(result2.getValue()).toStrictEqual(0.08044675194939552);
+
+ const frequency3 = NumberValueObject.create(4);
+ const result3 = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency3, basis);
+ expect(result3.getValue()).toStrictEqual(0.08049213260932456);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis2);
+ expect(result2.getValue()).toStrictEqual(0.08048411336357866);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis3);
+ expect(result3.getValue()).toStrictEqual(0.08048425764748052);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis4);
+ expect(result4.getValue()).toStrictEqual(0.0804841172323108);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis5);
+ expect(result5.getValue()).toStrictEqual(0.08048411336357866);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis6);
+ expect(result6.getValue()).toStrictEqual(0.08048411336357866);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(100);
+ const frequency = BooleanValueObject.create(true);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-11-11');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, rate, pr, redemption, frequency, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, rate2, pr, redemption, frequency, basis);
+ expect(result3.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('2021-3-1');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(100);
+ const frequency = NumberValueObject.create(2);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, rate, pr, redemption, frequency, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/yield/index.ts b/packages/engine-formula/src/functions/financial/yield/index.ts
new file mode 100644
index 0000000000..db016ccac3
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/yield/index.ts
@@ -0,0 +1,131 @@
+/**
+ * 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 { calculateCoupdaybs, calculateCoupdays, calculateCoupnum, calculatePrice, validCouppcdIsGte0ByTwoDate } from '../../../basics/financial';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Yield extends BaseFunction {
+ override minParams = 6;
+
+ override maxParams = 7;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ rate: BaseValueObject,
+ pr: BaseValueObject,
+ redemption: BaseValueObject,
+ frequency: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, rate, pr, redemption, frequency, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, rateObject, prObject, redemptionObject, 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 rateValue = +rateObject.getValue();
+ const prValue = +prObject.getValue();
+ const redemptionValue = +redemptionObject.getValue();
+ const frequencyValue = Math.floor(+frequencyObject.getValue());
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(rateValue) || Number.isNaN(prValue) || Number.isNaN(redemptionValue) || Number.isNaN(frequencyValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (
+ rateValue < 0 ||
+ prValue <= 0 ||
+ redemptionValue <= 0 ||
+ ![1, 2, 4].includes(frequencyValue) ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ settlementSerialNumber >= maturitySerialNumber ||
+ !validCouppcdIsGte0ByTwoDate(settlementSerialNumber, maturitySerialNumber, frequencyValue)
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = this._getResult(settlementSerialNumber, maturitySerialNumber, rateValue, prValue, redemptionValue, frequencyValue, basisValue);
+
+ return NumberValueObject.create(result);
+ }
+
+ private _getResult(
+ settlementSerialNumber: number,
+ maturitySerialNumber: number,
+ rate: number,
+ pr: number,
+ redemption: number,
+ frequency: number,
+ basis: number
+ ): number {
+ const N = calculateCoupnum(settlementSerialNumber, maturitySerialNumber, frequency);
+
+ if (N > 1) {
+ const g_Eps = 1e-7;
+
+ let yld = rate || 0.01;
+ let price = calculatePrice(settlementSerialNumber, maturitySerialNumber, rate, yld, redemption, frequency, basis);
+ let eps = price - pr;
+
+ for (let i = 0; i < 100 && Math.abs(eps) > g_Eps; i++) {
+ price = calculatePrice(settlementSerialNumber, maturitySerialNumber, rate, 1.01 * yld, redemption, frequency, basis);
+ yld += -eps / (price - pr - eps) * yld * 0.01;
+
+ const priceN = calculatePrice(settlementSerialNumber, maturitySerialNumber, rate, yld, redemption, frequency, basis);
+ eps = priceN - pr;
+ }
+
+ return yld;
+ }
+
+ const A = calculateCoupdaybs(settlementSerialNumber, maturitySerialNumber, frequency, basis);
+ const E = calculateCoupdays(settlementSerialNumber, maturitySerialNumber, frequency, basis);
+ const { days: DSR } = getTwoDateDaysByBasis(settlementSerialNumber, maturitySerialNumber, basis);
+
+ const temp = pr / 100 + (A / E * rate / frequency);
+ const result = ((redemption / 100 + rate / frequency) - temp) / temp * frequency * E / DSR;
+
+ return result;
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/yielddisc/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/yielddisc/__tests__/index.spec.ts
new file mode 100644
index 0000000000..97a4d190b6
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/yielddisc/__tests__/index.spec.ts
@@ -0,0 +1,159 @@
+/**
+ * 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 { Yielddisc } 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 yielddisc function', () => {
+ const testFunction = new Yielddisc(FUNCTION_NAMES_FINANCIAL.YIELDDISC);
+
+ describe('Yielddisc', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(100);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, pr, redemption, basis);
+ expect(result.getValue()).toStrictEqual(0.0012800067124173955);
+ });
+
+ it('Settlement >= maturity', () => {
+ const settlement = StringValueObject.create('2028-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const pr = NumberValueObject.create(98.45);
+ 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('Pr <= 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const pr = NumberValueObject.create(0);
+ 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('Redemption <= 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(0);
+ 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('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const pr = NumberValueObject.create(98.45);
+ 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.0012794247632892156);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, pr, redemption, basis3);
+ expect(result3.getValue()).toStrictEqual(0.0012614849101649731);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, pr, redemption, basis4);
+ expect(result4.getValue()).toStrictEqual(0.0012790055339172645);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, pr, redemption, basis5);
+ expect(result5.getValue()).toStrictEqual(0.0012794247632892156);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, pr, redemption, basis6);
+ expect(result6.getValue()).toStrictEqual(0.0012794247632892156);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2021-3-1');
+ const pr = NumberValueObject.create(98.45);
+ 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('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const pr = NumberValueObject.create(98.45);
+ const redemption = NumberValueObject.create(100);
+ const basis = BooleanValueObject.create(true);
+ 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('2021-3-1');
+ const pr = NumberValueObject.create(98.45);
+ 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);
+
+ const settlement2 = StringValueObject.create('2008-11-11');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, pr, redemption, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const pr2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, pr2, redemption, basis);
+ expect(result3.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('2021-3-1');
+ const pr = NumberValueObject.create(98.45);
+ 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/yielddisc/index.ts b/packages/engine-formula/src/functions/financial/yielddisc/index.ts
new file mode 100644
index 0000000000..121fbb0e4e
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/yielddisc/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 { getDateSerialNumberByObject, getTwoDateDaysByBasis } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Yielddisc extends BaseFunction {
+ override minParams = 4;
+
+ override maxParams = 5;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ pr: BaseValueObject,
+ redemption: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(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 ||
+ settlementSerialNumber >= maturitySerialNumber
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // B = number of days in year, depending on year basis.
+ // DSM = number of days from settlement to maturity.
+ const { days: DSM, yearDays: B } = getTwoDateDaysByBasis(settlementSerialNumber, maturitySerialNumber, basisValue);
+
+ const result = ((redemptionValue / prValue) - 1) / (DSM / B);
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/financial/yieldmat/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/yieldmat/__tests__/index.spec.ts
new file mode 100644
index 0000000000..bad5afb013
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/yieldmat/__tests__/index.spec.ts
@@ -0,0 +1,172 @@
+/**
+ * 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 { Yieldmat } 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 yieldmat function', () => {
+ const testFunction = new Yieldmat(FUNCTION_NAMES_FINANCIAL.YIELDMAT);
+
+ describe('Yieldmat', () => {
+ it('Value is normal', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, pr, basis);
+ expect(result.getValue()).toStrictEqual(0.08054463998901565);
+ });
+
+ it('Value is normal, but correct order is maturity > settlement > issue, otherwise return #NUM!', () => {
+ const settlement = StringValueObject.create('2018-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2028-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, pr, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Rate < 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(-0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, pr, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Pr <= 0', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(0);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, pr, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+ });
+
+ it('Basis value test', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const basis = NumberValueObject.create(5);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, pr, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NUM);
+
+ const basis2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(settlement, maturity, issue, rate, pr, basis2);
+ expect(result2.getValue()).toStrictEqual(0.08055145927494163);
+
+ const basis3 = NumberValueObject.create(2);
+ const result3 = testFunction.calculate(settlement, maturity, issue, rate, pr, basis3);
+ expect(result3.getValue()).toStrictEqual(0.08051589089528836);
+
+ const basis4 = NumberValueObject.create(3);
+ const result4 = testFunction.calculate(settlement, maturity, issue, rate, pr, basis4);
+ expect(result4.getValue()).toStrictEqual(0.08053986600547684);
+
+ const basis5 = NumberValueObject.create(4);
+ const result5 = testFunction.calculate(settlement, maturity, issue, rate, pr, basis5);
+ expect(result5.getValue()).toStrictEqual(0.08055145927494163);
+
+ const basis6 = NullValueObject.create();
+ const result6 = testFunction.calculate(settlement, maturity, issue, rate, pr, basis6);
+ expect(result6.getValue()).toStrictEqual(0.08055145927494163);
+ });
+
+ it('Value is error', () => {
+ const settlement = ErrorValueObject.create(ErrorType.NAME);
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, pr, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Value is boolean', () => {
+ const settlement = StringValueObject.create('2008-11-11');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const basis = BooleanValueObject.create(true);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, pr, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is normal string', () => {
+ const settlement = StringValueObject.create('test');
+ const maturity = StringValueObject.create('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, pr, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const settlement2 = StringValueObject.create('2008-11-11');
+ const maturity2 = StringValueObject.create('test');
+ const result2 = testFunction.calculate(settlement2, maturity2, issue, rate, pr, basis);
+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const issue2 = StringValueObject.create('test');
+ const result3 = testFunction.calculate(settlement2, maturity, issue2, rate, pr, basis);
+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);
+
+ const rate2 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(settlement2, maturity, issue, rate2, pr, basis);
+ expect(result4.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('2021-3-1');
+ const issue = StringValueObject.create('2008-10-15');
+ const rate = NumberValueObject.create(0.0785);
+ const pr = NumberValueObject.create(98.45);
+ const basis = NumberValueObject.create(1);
+ const result = testFunction.calculate(settlement, maturity, issue, rate, pr, basis);
+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/financial/yieldmat/index.ts b/packages/engine-formula/src/functions/financial/yieldmat/index.ts
new file mode 100644
index 0000000000..e1cc3cec56
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/yieldmat/index.ts
@@ -0,0 +1,107 @@
+/**
+ * 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, getNormalYearDaysByBasis, getTwoDateDaysByBasis } from '../../../basics/date';
+import { ErrorType } from '../../../basics/error-type';
+import { checkVariantsErrorIsNullorArrayOrBoolean } 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 Yieldmat extends BaseFunction {
+ override minParams = 5;
+
+ override maxParams = 6;
+
+ override calculate(
+ settlement: BaseValueObject,
+ maturity: BaseValueObject,
+ issue: BaseValueObject,
+ rate: BaseValueObject,
+ pr: BaseValueObject,
+ basis?: BaseValueObject
+ ): BaseValueObject {
+ let _basis = basis ?? NumberValueObject.create(0);
+
+ if (_basis.isNull()) {
+ _basis = NumberValueObject.create(0);
+ }
+
+ const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, issue, rate, pr, _basis);
+
+ if (isError) {
+ return errorObject as ErrorValueObject;
+ }
+
+ const [settlementObject, maturityObject, issueObject, rateObject, prObject, 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 issueSerialNumber = getDateSerialNumberByObject(issueObject);
+
+ if (typeof issueSerialNumber !== 'number') {
+ return issueSerialNumber;
+ }
+
+ const rateValue = +rateObject.getValue();
+ const prValue = +prObject.getValue();
+ const basisValue = Math.floor(+basisObject.getValue());
+
+ if (Number.isNaN(rateValue) || Number.isNaN(prValue) || Number.isNaN(basisValue)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ const isCorrectOrder = this._getDateCorrectOrder(maturitySerialNumber, settlementSerialNumber, issueSerialNumber);
+
+ if (
+ rateValue < 0 ||
+ prValue <= 0 ||
+ basisValue < 0 ||
+ basisValue > 4 ||
+ !isCorrectOrder
+ ) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ // B = number of days in year, depending on year basis.
+ // DSM = number of days from settlement to maturity.
+ // DIM = number of days from issue to maturity.
+ // A = number of days from issue to settlement.
+ const B = getNormalYearDaysByBasis(settlementSerialNumber, basisValue);
+ const { days: DSM } = getTwoDateDaysByBasis(settlementSerialNumber, maturitySerialNumber, basisValue);
+ const { days: DIM } = getTwoDateDaysByBasis(issueSerialNumber, maturitySerialNumber, basisValue);
+ const { days: A } = getTwoDateDaysByBasis(issueSerialNumber, settlementSerialNumber, basisValue);
+
+ const result = ((1 + DIM / B * rateValue) / (prValue / 100 + A / B * rateValue) - 1) / (DSM / B);
+
+ return NumberValueObject.create(result);
+ }
+
+ private _getDateCorrectOrder(maturitySerialNumber: number, settlementSerialNumber: number, issueSerialNumber: number): boolean {
+ return Math.floor(maturitySerialNumber) > Math.floor(settlementSerialNumber)
+ && Math.floor(settlementSerialNumber) > Math.floor(issueSerialNumber);
+ }
+}
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 d1256e2121..c21e186e22 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
@@ -306,8 +306,12 @@ 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." },
+ coupon: { name: 'coupon', detail: "The security's annual coupon rate." },
+ yld: { name: 'yld', detail: "The security's annual yield." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
EFFECT: {
@@ -400,8 +404,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: 'values', detail: 'An array or a reference to cells that contain numbers for which you want to calculate the internal rate of return.\n1.Values must contain at least one positive value and one negative value to calculate the internal rate of return.\n2.IRR uses the order of values to interpret the order of cash flows. Be sure to enter your payment and income values in the sequence you want.\n3.If an array or reference argument contains text, logical values, or empty cells, those values are ignored.' },
+ guess: { name: 'guess', detail: 'A number that you guess is close to the result of IRR.' },
},
},
ISPMT: {
@@ -430,8 +434,12 @@ 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." },
+ coupon: { name: 'coupon', detail: "The security's annual coupon rate." },
+ yld: { name: 'yld', detail: "The security's annual yield." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
MIRR: {
@@ -444,8 +452,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: 'values', detail: 'An array or a reference to cells that contain numbers. These numbers represent a series of payments (negative values) and income (positive values) occurring at regular periods.\n1.Values must contain at least one positive value and one negative value to calculate the modified internal rate of return. Otherwise, MIRR returns the #DIV/0! error value.\n2.If an array or reference argument contains text, logical values, or empty cells, those values are ignored; however, cells with the value zero are included.' },
+ financeRate: { name: 'finance_rate', detail: 'The interest rate you pay on the money used in the cash flows.' },
+ reinvestRate: { name: 'reinvest_rate', detail: 'The interest rate you receive on the cash flows as you reinvest them.' },
},
},
NOMINAL: {
@@ -489,8 +498,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'The rate of discount over the length of one period.' },
+ value1: { name: 'value1', detail: '1 to 254 arguments representing the payments and income.' },
+ value2: { name: 'value2', detail: '1 to 254 arguments representing the payments and income.' },
},
},
ODDFPRICE: {
@@ -503,8 +513,15 @@ 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." },
+ issue: { name: 'issue', detail: "The security's issue date." },
+ firstCoupon: { name: 'first_coupon', detail: "The security's first coupon date." },
+ rate: { name: 'rate', detail: "The security's interest rate." },
+ yld: { name: 'yld', detail: "The security's annual yield." },
+ redemption: { name: 'redemption', detail: "The security's redemption value per $100 face value." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year. For annual payments, frequency = 1; for semiannual, frequency = 2; for quarterly, frequency = 4.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
ODDFYIELD: {
@@ -517,8 +534,15 @@ 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." },
+ issue: { name: 'issue', detail: "The security's issue date." },
+ firstCoupon: { name: 'first_coupon', detail: "The security's first coupon date." },
+ rate: { name: 'rate', detail: "The security's interest rate." },
+ pr: { name: 'pr', detail: "The security's price." },
+ redemption: { name: 'redemption', detail: "The security's redemption value per $100 face value." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year. For annual payments, frequency = 1; for semiannual, frequency = 2; for quarterly, frequency = 4.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
ODDLPRICE: {
@@ -531,8 +555,14 @@ 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." },
+ lastInterest: { name: 'last_interest', detail: "The security's last coupon date." },
+ rate: { name: 'rate', detail: "The security's interest rate." },
+ yld: { name: 'yld', detail: "The security's annual yield." },
+ redemption: { name: 'redemption', detail: "The security's redemption value per $100 face value." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year. For annual payments, frequency = 1; for semiannual, frequency = 2; for quarterly, frequency = 4.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
ODDLYIELD: {
@@ -545,8 +575,14 @@ 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." },
+ lastInterest: { name: 'last_interest', detail: "The security's last coupon date." },
+ rate: { name: 'rate', detail: "The security's interest rate." },
+ pr: { name: 'pr', detail: "The security's price." },
+ redemption: { name: 'redemption', detail: "The security's redemption value per $100 face value." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year. For annual payments, frequency = 1; for semiannual, frequency = 2; for quarterly, frequency = 4.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
PDURATION: {
@@ -559,8 +595,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'Rate is the interest rate per period.' },
+ pv: { name: 'pv', detail: 'Pv is the present value of the investment.' },
+ fv: { name: 'fv', detail: 'Fv is the desired future value of the investment.' },
},
},
PMT: {
@@ -608,8 +645,13 @@ 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." },
+ rate: { name: 'rate', detail: "The security's interest rate." },
+ yld: { name: 'yld', detail: "The security's annual yield." },
+ redemption: { name: 'redemption', detail: "The security's redemption value per $100 face value." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year. For annual payments, frequency = 1; for semiannual, frequency = 2; for quarterly, frequency = 4.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
PRICEDISC: {
@@ -622,8 +664,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." },
+ discount: { name: 'discount', detail: "The security's discount rate." },
+ 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.' },
},
},
PRICEMAT: {
@@ -636,8 +681,12 @@ 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." },
+ issue: { name: 'issue', detail: "The security's issue date." },
+ rate: { name: 'rate', detail: "The security's interest rate." },
+ yld: { name: 'yld', detail: "The security's annual yield." },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
PV: {
@@ -685,8 +734,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.' },
+ discount: { name: 'discount', detail: "The security's discount rate." },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
RRI: {
@@ -699,8 +751,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nper: { name: 'nper', detail: 'Nper is the number of periods for the investment.' },
+ pv: { name: 'pv', detail: 'Pv is the present value of the investment.' },
+ fv: { name: 'fv', detail: 'Fv is the future value of the investment.' },
},
},
SLN: {
@@ -713,8 +766,9 @@ 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 depreciated (sometimes called the useful life of the asset).' },
},
},
SYD: {
@@ -727,8 +781,10 @@ 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 depreciated (sometimes called the useful life of the asset).' },
+ per: { name: 'per', detail: 'The period and must use the same units as life.' },
},
},
TBILLEQ: {
@@ -741,8 +797,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'settlement', detail: "The Treasury bill's settlement date." },
+ maturity: { name: 'maturity', detail: "The Treasury bill's maturity date." },
+ discount: { name: 'discount', detail: "The Treasury bill's discount rate." },
},
},
TBILLPRICE: {
@@ -755,8 +812,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'settlement', detail: "The Treasury bill's settlement date." },
+ maturity: { name: 'maturity', detail: "The Treasury bill's maturity date." },
+ discount: { name: 'discount', detail: "The Treasury bill's discount rate." },
},
},
TBILLYIELD: {
@@ -769,8 +827,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: 'settlement', detail: "The Treasury bill's settlement date." },
+ maturity: { name: 'maturity', detail: "The Treasury bill's maturity date." },
+ pr: { name: 'pr', detail: "The Treasury bill's price per $100 face value." },
},
},
VDB: {
@@ -783,8 +842,13 @@ 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).' },
+ startPeriod: { name: 'start_period', detail: 'The starting period for which you want to calculate the depreciation.' },
+ endPeriod: { name: 'end_period', detail: 'The ending 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).' },
+ noSwitch: { name: 'no_switch', detail: 'A logical value specifying whether to switch to straight-line depreciation when depreciation is greater than the declining balance calculation.' },
},
},
XIRR: {
@@ -797,8 +861,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: 'values', detail: 'A series of cash flows that corresponds to a schedule of payments in dates. The first payment is optional and corresponds to a cost or payment that occurs at the beginning of the investment. If the first value is a cost or payment, it must be a negative value. All succeeding payments are discounted based on a 365-day year. The series of values must contain at least one positive and one negative value.' },
+ dates: { name: 'dates', detail: 'A schedule of payment dates that corresponds to the cash flow payments. Dates may occur in any order.' },
+ guess: { name: 'guess', detail: 'A number that you guess is close to the result of XIRR.' },
},
},
XNPV: {
@@ -811,8 +876,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'rate', detail: 'The discount rate to apply to the cash flows.' },
+ values: { name: 'values', detail: 'A series of cash flows that corresponds to a schedule of payments in dates. The first payment is optional and corresponds to a cost or payment that occurs at the beginning of the investment. If the first value is a cost or payment, it must be a negative value. All succeeding payments are discounted based on a 365-day year. The series of values must contain at least one positive and one negative value.' },
+ dates: { name: 'dates', detail: 'A schedule of payment dates that corresponds to the cash flow payments. Dates may occur in any order.' },
},
},
YIELD: {
@@ -825,8 +891,13 @@ 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." },
+ rate: { name: 'rate', detail: "The security's interest rate." },
+ 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." },
+ frequency: { name: 'frequency', detail: 'The number of coupon payments per year. For annual payments, frequency = 1; for semiannual, frequency = 2; for quarterly, frequency = 4.' },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
YIELDDISC: {
@@ -839,8 +910,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.' },
},
},
YIELDMAT: {
@@ -853,8 +927,12 @@ 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." },
+ issue: { name: 'issue', detail: "The security's issue date." },
+ rate: { name: 'rate', detail: "The security's interest rate." },
+ pr: { name: 'pr', detail: "The security's price per $100 face value." },
+ basis: { name: 'basis', detail: 'The type of day count basis to use.' },
},
},
};
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 32b7bc01bf..ca36c47b64 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
@@ -306,8 +306,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ coupon: { name: '年利率', detail: '証券の年利を指定します。' },
+ yld: { name: '利回り', detail: '証券の年間配当を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
EFFECT: {
@@ -400,8 +404,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: 'キャッシュフロー', detail: '内部収益率を計算する数値を含む配列またはセルへの参照。\n1.内部利益率を計算するには、正の値と負の値が範囲に少なくとも 1 つずつ含まれている必要があります。\n2.IRR 関数では、値の順序がキャッシュ フローの順序であると見なされます。 支払額と収益額を入力する際は、その順序に注意してください。\n3.範囲に文字列、論理値、または空白セルが含まれる場合、これらは無視されます。' },
+ guess: { name: '推測値', detail: 'IRR 関数の計算結果に近いと思われる数値を指定します。' },
},
},
ISPMT: {
@@ -430,8 +434,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ coupon: { name: '年利率', detail: '証券の年利を指定します。' },
+ yld: { name: '利回り', detail: '証券の年間配当を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
MIRR: {
@@ -444,8 +452,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: 'キャッシュフロー', detail: '数値を含む配列またはセル参照を指定します。 これらの数値は、定期的に発生する一連の支払い (負の値) とその収益 (正の値) を表しています。\n1.修正内部収益率を計算するには、正の値と負の値が範囲に少なくとも 1 つずつ含まれている必要があります。 そうでない場合は、エラー値 #DIV/0! が返されます。\n2.引数として指定した配列またはセル範囲に文字列、論理値、空白セルが含まれている場合、これらは無視されます。ただし、数値として 0 (ゼロ) を含むセルは計算の対象となります。' },
+ financeRate: { name: '融資利率', detail: '支払額 (負のキャッシュ フロー) に対する利率を指定します。' },
+ reinvestRate: { name: '再投資収益率', detail: '収益額 (正のキャッシュ フロー) に対する利率を指定します。' },
},
},
NOMINAL: {
@@ -489,8 +498,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '割引率', detail: '投資期間を通じて一定の利率を指定します。' },
+ value1: { name: 'キャッシュフロー1', detail: '支払いと収入を表す 1 から 254 の引数。' },
+ value2: { name: 'キャッシュフロー2', detail: '支払いと収入を表す 1 から 254 の引数。' },
},
},
ODDFPRICE: {
@@ -503,8 +513,15 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ issue: { name: '発行日', detail: '証券の発行日を指定します。' },
+ firstCoupon: { name: '初回利払日', detail: '証券の最初の利払日を指定します。' },
+ rate: { name: '利率', detail: '証券の利率を指定します。' },
+ yld: { name: '利回り', detail: '証券の年間配当を指定します。' },
+ redemption: { name: '償還価額', detail: '額面 $100 に対する証券の償還額を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。 年 1 回の場合は頻度 = 1、年 2 回の場合は頻度 = 2、四半期ごとの場合は頻度 = 4 を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
ODDFYIELD: {
@@ -517,8 +534,15 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ issue: { name: '発行日', detail: '証券の発行日を指定します。' },
+ firstCoupon: { name: '初回利払日', detail: '証券の最初の利払日を指定します。' },
+ rate: { name: '利率', detail: '証券の利率を指定します。' },
+ pr: { name: '価格', detail: '証券の価格を指定します。' },
+ redemption: { name: '償還価額', detail: '額面 $100 に対する証券の償還額を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。 年 1 回の場合は頻度 = 1、年 2 回の場合は頻度 = 2、四半期ごとの場合は頻度 = 4 を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
ODDLPRICE: {
@@ -531,8 +555,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ lastInterest: { name: '最終利払日', detail: '証券の最後の利払日を指定します。' },
+ rate: { name: '利率', detail: '証券の利率を指定します。' },
+ yld: { name: '利回り', detail: '証券の年間配当を指定します。' },
+ redemption: { name: '償還価額', detail: '額面 $100 に対する証券の償還額を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。 年 1 回の場合は頻度 = 1、年 2 回の場合は頻度 = 2、四半期ごとの場合は頻度 = 4 を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
ODDLYIELD: {
@@ -545,8 +575,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ lastInterest: { name: '最終利払日', detail: '証券の最後の利払日を指定します。' },
+ rate: { name: '利率', detail: '証券の利率を指定します。' },
+ pr: { name: '価格', detail: '証券の価格を指定します。' },
+ redemption: { name: '償還価額', detail: '額面 $100 に対する証券の償還額を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。 年 1 回の場合は頻度 = 1、年 2 回の場合は頻度 = 2、四半期ごとの場合は頻度 = 4 を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
PDURATION: {
@@ -559,8 +595,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '利率は投資の利率を指定します。' },
+ pv: { name: '現在価値', detail: '投資の現在価値を指定します。' },
+ fv: { name: '将来価値', detail: '投資の目標とする将来価値を指定します。' },
},
},
PMT: {
@@ -608,8 +645,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ rate: { name: '利率', detail: '証券の利率を指定します。' },
+ yld: { name: '利回り', detail: '証券の年間配当を指定します。' },
+ redemption: { name: '償還価額', detail: '額面 $100 に対する証券の償還額を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。 年 1 回の場合は頻度 = 1、年 2 回の場合は頻度 = 2、四半期ごとの場合は頻度 = 4 を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
PRICEDISC: {
@@ -622,8 +664,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ discount: { name: '割引率', detail: '証券の割引率を指定します。' },
+ redemption: { name: '償還価額', detail: '額面 $100 に対する証券の償還額を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
PRICEMAT: {
@@ -636,8 +681,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ issue: { name: '発行日', detail: '証券の発行日を指定します。' },
+ rate: { name: '利率', detail: '証券の利率を指定します。' },
+ yld: { name: '利回り', detail: '証券の年間配当を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
PV: {
@@ -685,8 +734,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ investment: { name: '投資額', detail: '証券への投資額を指定します。' },
+ discount: { name: '割引率', detail: '証券の割引率を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
RRI: {
@@ -699,8 +751,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nper: { name: '期間', detail: '投資期間の期間数を指定します。' },
+ pv: { name: '現在価値', detail: '投資の現在価値を指定します。' },
+ fv: { name: '将来価値', detail: 'Fvは投資の将来価値です。' },
},
},
SLN: {
@@ -713,8 +766,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '取得価額', detail: '資産を購入した時点での価格を指定します。' },
+ salvage: { name: '残存価額', detail: '耐用年数が終了した時点での資産の価格 (資産の救済価額) を指定します。' },
+ life: { name: '耐用年数', detail: '資産を使用できる年数、つまり償却の対象となる資産の寿命年数を指定します。' },
},
},
SYD: {
@@ -727,8 +781,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '取得価額', detail: '資産を購入した時点での価格を指定します。' },
+ salvage: { name: '残存価額', detail: '耐用年数が終了した時点での資産の価格 (資産の救済価額) を指定します。' },
+ life: { name: '耐用年数', detail: '資産を使用できる年数、つまり償却の対象となる資産の寿命年数を指定します。' },
+ per: { name: '期間', detail: '期間 と は、有効期間と同じ単位を使用する必要があります。' },
},
},
TBILLEQ: {
@@ -741,8 +797,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '財務省証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '財務省証券の満期日を指定します。' },
+ discount: { name: '割引率', detail: '財務省証券の割引率を指定します。' },
},
},
TBILLPRICE: {
@@ -755,8 +812,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '財務省証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '財務省証券の満期日を指定します。' },
+ discount: { name: '割引率', detail: '財務省証券の割引率を指定します。' },
},
},
TBILLYIELD: {
@@ -769,8 +827,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '財務省証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '財務省証券の満期日を指定します。' },
+ pr: { name: '価値', detail: '額面 $100 に対する財務省証券の価値を指定します。' },
},
},
VDB: {
@@ -783,8 +842,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '取得価額', detail: '資産を購入した時点での価格を指定します。' },
+ salvage: { name: '残存価額', detail: '耐用年数が終了した時点での資産の価格 (資産の救済価額) を指定します。' },
+ life: { name: '耐用年数', detail: '資産を使用できる年数 (資産の寿命年数) を指定します。' },
+ startPeriod: { name: '開始期', detail: '減価償却費の計算の対象となる最初の期を指定します。' },
+ endPeriod: { name: '終了期', detail: '減価償却費の計算の対象となる最後の期を指定します。' },
+ factor: { name: '率', detail: '減価償却率を指定します。率を省略すると、2 を指定したと見なされ、倍額定率法で計算が行われます。' },
+ noSwitch: { name: '切り替えなし', detail: '減価償却費が定率法による計算の結果より大きくなったときに、自動的に定額法に切り替えるかどうかを、論理値で指定します。' },
},
},
XIRR: {
@@ -797,8 +861,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: 'キャッシュフロー', detail: '収支明細表の日付に対応する一覧のキャッシュ フローを指定します。 最初の支払いは投資の最初に発生する原価や支払いに対応し、省略できます。 最初のキャッシュ フローが原価や支払いの場合、負の値を指定する必要があります。 それ以降の支払いは、1 年の日数を 365 日として割り引かれます。 値には、正の値と負の値が少なくとも 1 つずつ含まれている必要があります。' },
+ dates: { name: '日付テーブル', detail: 'キャッシュ フローに対応する一連の支払日を指定します。 指定順序は自由です。' },
+ guess: { name: '推測値', detail: 'XIRR 関数の計算結果に近いと思われる数値を指定します。' },
},
},
XNPV: {
@@ -811,8 +876,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '割引率', detail: '対象となるキャッシュ フローに適用する割引率を指定します。' },
+ values: { name: 'キャッシュフロー', detail: '収支明細表の日付に対応する一覧のキャッシュ フローを指定します。 最初の支払いは投資の最初に発生する原価や支払いに対応し、省略できます。 最初のキャッシュ フローが原価や支払いの場合、負の値を指定する必要があります。 それ以降の支払いは、1 年の日数を 365 日として割り引かれます。 値には、正の値と負の値が少なくとも 1 つずつ含まれている必要があります。' },
+ dates: { name: '日付テーブル', detail: 'キャッシュ フローに対応する一連の支払日を指定します。 指定順序は自由です。' },
},
},
YIELD: {
@@ -825,8 +891,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ rate: { name: '利率', detail: '証券の利率を指定します。' },
+ pr: { name: '価格', detail: '額面 $100 に対する証券の価値を指定します。' },
+ redemption: { name: '償還価額', detail: '額面 $100 に対する証券の償還額を指定します。' },
+ frequency: { name: '頻度', detail: '年間の利息支払回数を指定します。 年 1 回の場合は頻度 = 1、年 2 回の場合は頻度 = 2、四半期ごとの場合は頻度 = 4 を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
YIELDDISC: {
@@ -839,8 +910,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: '計算に使用する基準日数を示す数値を指定します。' },
},
},
YIELDMAT: {
@@ -853,8 +927,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '受渡日', detail: '証券の受渡日を指定します。' },
+ maturity: { name: '満期日', detail: '証券の満期日を指定します。' },
+ issue: { name: '発行日', detail: '証券の発行日を指定します。' },
+ rate: { name: '利率', detail: '証券の利率を指定します。' },
+ pr: { name: '価格', detail: '額面 $100 に対する証券の価値を指定します。' },
+ basis: { name: '基準', detail: '計算に使用する基準日数を示す数値を指定します。' },
},
},
};
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 e891f0f212..d817bc2aa2 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
@@ -306,8 +306,12 @@ 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.' },
+ coupon: { name: 'lãi suất coupon hàng năm.', detail: 'Lãi suất coupon hàng năm của một chứng khoán.' },
+ yld: { name: 'tỷ suất lợi nhuận hàng năm.', detail: 'Tỷ suất lợi nhuận hàng năm của một chứng khoán có thể bán được.' },
+ 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.' },
},
},
EFFECT: {
@@ -400,8 +404,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: 'dòng tiền', detail: 'Tham chiếu đến một mảng hoặc ô chứa các số dùng để tính tỷ suất hoàn vốn nội bộ.\n1.Các giá trị phải chứa ít nhất một giá trị dương và một giá trị âm để tính tỷ suất hoàn vốn nội bộ được trả về.\n2.IRR sử dụng chuỗi giá trị để minh họa chuỗi dòng tiền. Đảm bảo nhập các giá trị chi phí và lợi ích theo thứ tự bạn yêu cầu.\n3.Nếu mảng hoặc tham chiếu chứa văn bản, giá trị logic hoặc ô trống thì các giá trị này sẽ bị bỏ qua.' },
+ guess: { name: 'giá trị ước tính', detail: 'Ước tính tính toán IRR của hàm.' },
},
},
ISPMT: {
@@ -420,6 +424,24 @@ export default {
pv: { name: 'giá trị hiện tại', detail: 'Giá trị hiện tại.' },
},
},
+ MDURATION: {
+ description: 'Trả về thời hạn đã sửa đổi của Macauley cho một chứng khoán có mệnh giá giả định là 100 đô la',
+ abstract: 'Trả về thời hạn đã sửa đổi của Macauley cho một chứng khoán có mệnh giá giả định là 100 đô la',
+ links: [
+ {
+ title: 'Hướng dẫn',
+ url: 'https://support.microsoft.com/vi-vn/office/mduration-%E5%87%BD%E6%95%B0-7c5ae5c5-e22a-4c6e-bfc5-43c7b41f1974',
+ },
+ ],
+ functionParameter: {
+ 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.' },
+ coupon: { name: 'lãi suất coupon hàng năm.', detail: 'Lãi suất coupon hàng năm của một chứng khoán.' },
+ yld: { name: 'tỷ suất lợi nhuận hàng năm.', detail: 'Tỷ suất lợi nhuận hàng năm của một chứng khoán có thể bán được.' },
+ 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.' },
+ },
+ },
MIRR: {
description: 'Trả về tỷ lệ hoàn vốn nội bộ điều chỉnh cho các dòng tiền định kỳ, có tính đến chi phí đầu tư và lãi suất của khoản đầu tư',
abstract: 'Trả về tỷ lệ hoàn vốn nội bộ điều chỉnh cho các dòng tiền định kỳ, có tính đến chi phí đầu tư và lãi suất của khoản đầu tư',
@@ -430,8 +452,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: 'dòng tiền', detail: 'Một mảng hoặc tham chiếu đến một ô chứa số. Các giá trị này đại diện cho một loạt chi phí định kỳ (giá trị âm) và lợi ích (giá trị dương).\n1.Các giá trị phải chứa ít nhất một giá trị dương và một giá trị âm để tính tỷ suất hoàn vốn nội bộ được sửa đổi. Ngược lại, MIRR trả về #DIV/0! .\n2.Tuy nhiên, nếu mảng hoặc tham số tham chiếu chứa văn bản, giá trị logic hoặc ô trống thì các giá trị đó sẽ bị bỏ qua; tuy nhiên, các ô chứa giá trị 0 sẽ được tính.' },
+ financeRate: { name: 'Lãi suất tài trợ', detail: 'Lãi suất trả cho các khoản tiền được sử dụng trong dòng tiền.' },
+ reinvestRate: { name: 'tỷ suất sinh lợi tái đầu tư', detail: 'Tỷ suất lợi nhuận của dòng tiền tái đầu tư.' },
},
},
NOMINAL: {
@@ -475,8 +498,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'tỷ lệ chiết khấu', detail: 'Tỷ lệ chiết khấu trong một thời gian nhất định.' },
+ value1: { name: 'dòng tiền 1', detail: 'Đây là các tham số từ 1 đến 254 thể hiện chi phí và thu nhập.' },
+ value2: { name: 'dòng tiền 2', detail: 'Đây là các tham số từ 1 đến 254 thể hiện chi phí và thu nhập.' },
},
},
ODDFPRICE: {
@@ -489,8 +513,15 @@ 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.' },
+ issue: { name: 'ngày phát hành', detail: 'Ngày phát hành chứng khoán.' },
+ firstCoupon: { name: 'ngày phiếu lãi đầu tiên', detail: 'Ngày phát hành phiếu giảm giá đầu tiên của chứng khoán.' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất chứng khoán.' },
+ yld: { name: 'lợi suất hàng năm', detail: 'Lợi suất hàng năm của chứng khoán.' },
+ redemption: { name: 'giá trị chuộc lại', detail: 'Giá trị hoàn lại của chứng khoán trên mỗi mệnh giá 100 đô la.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu giảm giá mỗi năm. Đối với các khoản thanh toán hàng năm, tần suất = 1; đối với các khoản thanh toán nửa năm, tần suất = 2; đối với các khoản thanh toán hàng quý, tần suất = 4.' },
+ basis: { name: 'cơ sở', detail: 'Loại cơ sở tính ngày cần sử dụng.' },
},
},
ODDFYIELD: {
@@ -503,8 +534,15 @@ 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.' },
+ issue: { name: 'ngày phát hành', detail: 'Ngày phát hành chứng khoán.' },
+ firstCoupon: { name: 'ngày phiếu lãi đầu tiên', detail: 'Ngày phát hành phiếu giảm giá đầu tiên của chứng khoán.' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất chứng khoán.' },
+ pr: { name: 'giá của', detail: 'Giá của chứng khoán.' },
+ redemption: { name: 'giá trị chuộc lại', detail: 'Giá trị hoàn lại của chứng khoán trên mỗi mệnh giá 100 đô la.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu giảm giá mỗi năm. Đối với các khoản thanh toán hàng năm, tần suất = 1; đối với các khoản thanh toán nửa năm, tần suất = 2; đối với các khoản thanh toán hàng quý, tần suất = 4.' },
+ basis: { name: 'cơ sở', detail: 'Loại cơ sở tính ngày cần sử dụng.' },
},
},
ODDLPRICE: {
@@ -517,8 +555,14 @@ 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.' },
+ lastInterest: { name: 'ngày thanh toán lãi cuối', detail: 'Ngày thanh toán lãi cuối cùng của chứng khoán.' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất chứng khoán.' },
+ yld: { name: 'lợi suất hàng năm', detail: 'Lợi suất hàng năm của chứng khoán.' },
+ redemption: { name: 'giá trị chuộc lại', detail: 'Giá trị hoàn lại của chứng khoán trên mỗi mệnh giá 100 đô la.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu giảm giá mỗi năm. Đối với các khoản thanh toán hàng năm, tần suất = 1; đối với các khoản thanh toán nửa năm, tần suất = 2; đối với các khoản thanh toán hàng quý, tần suất = 4.' },
+ basis: { name: 'cơ sở', detail: 'Loại cơ sở tính ngày cần sử dụng.' },
},
},
ODDLYIELD: {
@@ -531,8 +575,29 @@ 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.' },
+ lastInterest: { name: 'ngày thanh toán lãi cuối', detail: 'Ngày thanh toán lãi cuối cùng của chứng khoán.' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất chứng khoán.' },
+ pr: { name: 'giá của', detail: 'Giá của chứng khoán.' },
+ redemption: { name: 'giá trị chuộc lại', detail: 'Giá trị hoàn lại của chứng khoán trên mỗi mệnh giá 100 đô la.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu giảm giá mỗi năm. Đối với các khoản thanh toán hàng năm, tần suất = 1; đối với các khoản thanh toán nửa năm, tần suất = 2; đối với các khoản thanh toán hàng quý, tần suất = 4.' },
+ basis: { name: 'cơ sở', detail: 'Loại cơ sở tính ngày cần sử dụng.' },
+ },
+ },
+ PDURATION: {
+ description: 'Trả về số kỳ hạn cần thiết để một khoản đầu tư đạt đến giá trị đã xác định.',
+ abstract: 'Trả về số kỳ hạn cần thiết để một khoản đầu tư đạt đến giá trị đã xác định.',
+ links: [
+ {
+ title: 'Hướng dẫn',
+ url: 'https://support.microsoft.com/vi-vn/office/pduration-%E5%87%BD%E6%95%B0-44f33460-5be5-4c90-b857-22308892adaf',
+ },
+ ],
+ functionParameter: {
+ rate: { name: 'lãi suất', detail: 'lãi suất của mỗi kỳ hạn.' },
+ pv: { name: 'giá trị hiện tại', detail: 'giá trị hiện tại của khoản đầu tư.' },
+ fv: { name: 'giá trị tương lai', detail: 'giá trị tương lai được kỳ vọng của khoản đầu tư.' },
},
},
PMT: {
@@ -580,8 +645,13 @@ 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.' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất chứng khoán.' },
+ yld: { name: 'lợi suất hàng năm', detail: 'Lợi suất hàng năm của chứng khoán.' },
+ redemption: { name: 'giá trị chuộc lại', detail: 'Giá trị hoàn lại của chứng khoán trên mỗi mệnh giá 100 đô la.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu giảm giá mỗi năm. Đối với các khoản thanh toán hàng năm, tần suất = 1; đối với các khoản thanh toán nửa năm, tần suất = 2; đối với các khoản thanh toán hàng quý, tần suất = 4.' },
+ basis: { name: 'cơ sở', detail: 'Loại cơ sở tính ngày cần sử dụng.' },
},
},
PRICEDISC: {
@@ -594,8 +664,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.' },
+ discount: { name: 'lãi suất chiết', detail: 'Lãi suất chiết khấu đối với chứng khoán.' },
+ redemption: { name: 'giá trị chuộc lại', detail: 'Giá trị hoàn lại của chứng khoán trên mỗi mệnh giá 100 đô la.' },
+ basis: { name: 'cơ sở', detail: 'Loại cơ sở tính ngày cần sử dụng.' },
},
},
PRICEMAT: {
@@ -608,8 +681,12 @@ 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.' },
+ issue: { name: 'ngày phát hành', detail: 'Ngày phát hành chứng khoán.' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất chứng khoán.' },
+ yld: { name: 'lợi suất hàng năm', detail: 'Lợi suất hàng năm của chứng khoán.' },
+ basis: { name: 'cơ sở', detail: 'Loại cơ sở tính ngày cần sử dụng.' },
},
},
PV: {
@@ -657,8 +734,26 @@ 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 tư', detail: 'Số tiền đầu tư vào chứng khoán có thể bán được.' },
+ discount: { name: 'lãi suất chiết', detail: 'Lãi suất chiết khấu đối với chứng khoán.' },
+ basis: { name: 'cơ sở', detail: 'Loại cơ sở tính ngày cần sử dụng.' },
+ },
+ },
+ RRI: {
+ description: 'Trả về một lãi suất tương đương cho sự tăng trưởng của một khoản đầu tư.',
+ abstract: 'Trả về một lãi suất tương đương cho sự tăng trưởng của một khoản đầu tư.',
+ links: [
+ {
+ title: 'Hướng dẫn',
+ url: 'https://support.microsoft.com/vi-vn/office/rri-%E5%87%BD%E6%95%B0-6f5822d8-7ef1-4233-944c-79e8172930f4',
+ },
+ ],
+ functionParameter: {
+ nper: { name: 'số kỳ hạn của khoản đầu tư.', detail: 'Nper là số kỳ hạn của khoản đầu tư.' },
+ pv: { name: 'giá trị hiện tại', detail: 'Pv là giá trị hiện tại của khoản đầu tư.' },
+ fv: { name: 'giá trị tương lai', detail: 'Fv là giá trị tương lai của khoản đầu tư.' },
},
},
SLN: {
@@ -671,8 +766,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: 'giá trị ban đầu của tài sản', detail: 'Giá trị ban đầu của tài sản.' },
+ salvage: { name: 'giá trị còn lại của tài sản', 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: 'thời gian sử dụng tài sản', 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).' },
},
},
SYD: {
@@ -685,8 +781,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: 'giá trị ban đầu của tài sản', detail: 'Giá trị ban đầu của tài sản.' },
+ salvage: { name: 'giá trị còn lại của tài sản', 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: 'thời gian sử dụng tài sản', 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).' },
+ per: { name: 'thời kỳ', detail: 'Chu kỳ và phải sử dụng cùng đơn vị với cuộc sống.' },
},
},
TBILLEQ: {
@@ -699,8 +797,9 @@ 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 trái phiếu kho bạc.' },
+ maturity: { name: 'ngày đáo hạn', detail: 'Ngày đáo hạn của trái phiếu kho bạc.' },
+ discount: { name: 'lãi suất chiết', detail: 'Lãi suất chiết khấu của trái phiếu kho bạc.' },
},
},
TBILLPRICE: {
@@ -713,8 +812,9 @@ 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 trái phiếu kho bạc.' },
+ maturity: { name: 'ngày đáo hạn', detail: 'Ngày đáo hạn của trái phiếu kho bạc.' },
+ discount: { name: 'lãi suất chiết', detail: 'Lãi suất chiết khấu của trái phiếu kho bạc.' },
},
},
TBILLYIELD: {
@@ -727,8 +827,9 @@ 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 trái phiếu kho bạc.' },
+ maturity: { name: 'ngày đáo hạn', detail: 'Ngày đáo hạn của trái phiếu kho bạc.' },
+ pr: { name: 'giá', detail: 'Giá trái phiếu kho bạc tính theo mệnh giá 100 đô la.' },
},
},
VDB: {
@@ -741,8 +842,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.' },
+ 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).' },
+ startPeriod: { name: 'kỳ đầu tiên', detail: 'Kỳ đầu tiên mà bạn muốn tính khấu hao.' },
+ endPeriod: { name: 'kỳ kết thúc', detail: 'Kỳ kết thúc 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).' },
+ noSwitch: { name: 'không chuyển đổi', detail: 'Giá trị logic chỉ định liệu có nên chuyển sang khấu hao theo đường thẳng hay không khi mức khấu hao lớn hơn phép tính số dư giảm dần.' },
},
},
XIRR: {
@@ -755,8 +861,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: 'dòng tiền', detail: 'Một chuỗi các dòng tiền tương ứng với thời điểm thanh toán theo ngày. Khoản trả trước là tùy chọn và liên quan đến chi phí hoặc khoản thanh toán khi bắt đầu đầu tư. Nếu giá trị đầu tiên là chi phí hoặc khoản thanh toán thì giá trị đó phải âm. Tất cả các khoản thanh toán tiếp theo được chiết khấu trên cơ sở 365 ngày/năm. Chuỗi giá trị phải chứa ít nhất một giá trị dương và một giá trị âm.' },
+ dates: { name: 'bảng ngày tháng', detail: 'Lịch trình ngày thanh toán tương ứng với các khoản thanh toán dòng tiền. Ngày tháng có thể xuất hiện theo bất kỳ thứ tự nào.' },
+ guess: { name: 'giá trị ước tính', detail: 'Ước tính kết quả của phép tính hàm XIRR.' },
},
},
XNPV: {
@@ -769,8 +876,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: 'tỷ lệ chiết khấu', detail: 'Tỷ lệ chiết khấu áp dụng cho dòng tiền.' },
+ values: { name: 'dòng tiền', detail: 'Một chuỗi các dòng tiền tương ứng với thời điểm thanh toán theo ngày. Khoản trả trước là tùy chọn và liên quan đến chi phí hoặc khoản thanh toán khi bắt đầu đầu tư. Nếu giá trị đầu tiên là chi phí hoặc khoản thanh toán thì giá trị đó phải âm. Tất cả các khoản thanh toán tiếp theo được chiết khấu trên cơ sở 365 ngày/năm. Chuỗi giá trị phải chứa ít nhất một giá trị dương và một giá trị âm.' },
+ dates: { name: 'bảng ngày tháng', detail: 'Lịch trình ngày thanh toán tương ứng với các khoản thanh toán dòng tiền. Ngày tháng có thể xuất hiện theo bất kỳ thứ tự nào.' },
},
},
YIELD: {
@@ -783,8 +891,13 @@ 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.' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất chứng khoán.' },
+ pr: { name: 'giá', detail: 'Giá chứng khoán tính theo mệnh giá 100 đô la.' },
+ redemption: { name: 'giá trị chuộc lại', detail: 'Giá trị hoàn lại của chứng khoán trên mỗi mệnh giá 100 đô la.' },
+ frequency: { name: 'tần số', detail: 'Số lần thanh toán phiếu giảm giá mỗi năm. Đối với các khoản thanh toán hàng năm, tần suất = 1; đối với các khoản thanh toán nửa năm, tần suất = 2; đối với các khoản thanh toán hàng quý, tần suất = 4.' },
+ basis: { name: 'cơ sở', detail: 'Loại cơ sở tính ngày cần sử dụng.' },
},
},
YIELDDISC: {
@@ -797,8 +910,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á chứng khoán tính theo mệnh giá 100 đô la.' },
+ redemption: { name: 'giá trị chuộc lại', detail: 'Giá trị hoàn lại của chứng khoán trên mỗi mệnh giá 100 đô la.' },
+ basis: { name: 'cơ sở', detail: 'Loại cơ sở tính ngày cần sử dụng.' },
},
},
YIELDMAT: {
@@ -811,8 +927,12 @@ 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.' },
+ issue: { name: 'ngày phát hành', detail: 'Ngày phát hành chứng khoán.' },
+ rate: { name: 'lãi suất', detail: 'Lãi suất chứng khoán.' },
+ pr: { name: 'giá', detail: 'Giá chứng khoán tính theo mệnh giá 100 đô la.' },
+ basis: { name: 'cơ sở', detail: 'Loại cơ sở tính ngày cần sử dụng.' },
},
},
};
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 89995ea9b3..520d833cb4 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
@@ -306,8 +306,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ coupon: { name: '年息票利率', detail: '有价证券的年息票利率。' },
+ yld: { name: '年收益率', detail: '有价证券的年收益率。' },
+ frequency: { name: '频次', detail: '年付息次数。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
EFFECT: {
@@ -400,8 +404,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: '现金流', detail: '数组或单元格的引用,这些单元格包含用来计算内部收益率的数字。\n1.Values 必须包含至少一个正值和一个负值,以计算返回的内部收益率。\n2.IRR 使用值的顺序来说明现金流的顺序。 一定要按您需要的顺序输入支出值和收益值。\n3.如果数组或引用包含文本、逻辑值或空白单元格,这些数值将被忽略。' },
+ guess: { name: '估计值', detail: '对函数 IRR 计算结果的估计值。' },
},
},
ISPMT: {
@@ -430,8 +434,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ coupon: { name: '年息票利率', detail: '有价证券的年息票利率。' },
+ yld: { name: '年收益率', detail: '有价证券的年收益率。' },
+ frequency: { name: '频次', detail: '年付息次数。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
MIRR: {
@@ -444,8 +452,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: '现金流', detail: '数组或对包含数字的单元格的引用。 这些数值代表一系列定期支出(负值)和收益(正值)。\n1.Values 必须至少包含一个正值和一个负值,才能计算修改后的内部回报率。 否则,MIRR 返回 #DIV/0! 。\n2.如果数组或引用参数包含文本、逻辑值或空白单元格,则这些值将被忽略;但包含零值的单元格将计算在内。' },
+ financeRate: { name: '融资利率', detail: '现金流中使用的资金支付的利率。' },
+ reinvestRate: { name: '再投资收益率', detail: '将现金流再投资的收益率。' },
},
},
NOMINAL: {
@@ -489,8 +498,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '贴现率', detail: '某一期间的贴现率。' },
+ value1: { name: '现金流1', detail: '这些是代表支出及收入的 1 到 254 个参数。' },
+ value2: { name: '现金流2', detail: '这些是代表支出及收入的 1 到 254 个参数。' },
},
},
ODDFPRICE: {
@@ -503,8 +513,15 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ issue: { name: '发行日', detail: '有价证券的发行日。' },
+ firstCoupon: { name: '首期付息日', detail: '有价证券的首期付息日。' },
+ rate: { name: '利率', detail: '有价证券的利率。' },
+ yld: { name: '年收益率', detail: '有价证券的年收益率。' },
+ redemption: { name: '清偿价', detail: '面值 ¥100 的有价证券的清偿价值。' },
+ frequency: { name: '频次', detail: '年付息次数。 如果按年支付,frequency = 1;按半年期支付,frequency = 2;按季支付,frequency = 4。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
ODDFYIELD: {
@@ -517,8 +534,15 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ issue: { name: '发行日', detail: '有价证券的发行日。' },
+ firstCoupon: { name: '首期付息日', detail: '有价证券的首期付息日。' },
+ rate: { name: '利率', detail: '有价证券的利率。' },
+ pr: { name: '价格', detail: '有价证券的价格。' },
+ redemption: { name: '清偿价', detail: '面值 ¥100 的有价证券的清偿价值。' },
+ frequency: { name: '频次', detail: '年付息次数。 如果按年支付,frequency = 1;按半年期支付,frequency = 2;按季支付,frequency = 4。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
ODDLPRICE: {
@@ -531,8 +555,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ lastInterest: { name: '末期付息日', detail: '有价证券的末期付息日。' },
+ rate: { name: '利率', detail: '有价证券的利率。' },
+ yld: { name: '年收益率', detail: '有价证券的年收益率。' },
+ redemption: { name: '清偿价', detail: '面值 ¥100 的有价证券的清偿价值。' },
+ frequency: { name: '频次', detail: '年付息次数。 如果按年支付,frequency = 1;按半年期支付,frequency = 2;按季支付,frequency = 4。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
ODDLYIELD: {
@@ -545,8 +575,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ lastInterest: { name: '末期付息日', detail: '有价证券的末期付息日。' },
+ rate: { name: '利率', detail: '有价证券的利率。' },
+ pr: { name: '价格', detail: '有价证券的价格。' },
+ redemption: { name: '清偿价', detail: '面值 ¥100 的有价证券的清偿价值。' },
+ frequency: { name: '频次', detail: '年付息次数。 如果按年支付,frequency = 1;按半年期支付,frequency = 2;按季支付,frequency = 4。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
PDURATION: {
@@ -559,8 +595,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '每个周期的利率。' },
+ pv: { name: '现值', detail: '投资的现值。' },
+ fv: { name: '未来价值', detail: '投资的预期未来价值。' },
},
},
PMT: {
@@ -608,8 +645,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ rate: { name: '利率', detail: '有价证券的利率。' },
+ yld: { name: '年收益率', detail: '有价证券的年收益率。' },
+ redemption: { name: '清偿价', detail: '面值 ¥100 的有价证券的清偿价值。' },
+ frequency: { name: '频次', detail: '年付息次数。 如果按年支付,frequency = 1;按半年期支付,frequency = 2;按季支付,frequency = 4。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
PRICEDISC: {
@@ -622,8 +664,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ discount: { name: '贴现率', detail: '有价证券的贴现率。' },
+ redemption: { name: '清偿价', detail: '面值 ¥100 的有价证券的清偿价值。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
PRICEMAT: {
@@ -636,8 +681,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ issue: { name: '发行日', detail: '有价证券的发行日。' },
+ rate: { name: '利率', detail: '有价证券的利率。' },
+ yld: { name: '年收益率', detail: '有价证券的年收益率。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
PV: {
@@ -685,8 +734,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ investment: { name: '投资额', detail: '有价证券的投资额。' },
+ discount: { name: '贴现率', detail: '有价证券的贴现率。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
RRI: {
@@ -699,8 +751,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nper: { name: '总期数', detail: '投资的周期数。' },
+ pv: { name: '现值', detail: '投资的现值。' },
+ fv: { name: '未来价值', detail: '投资的未来价值。' },
},
},
SLN: {
@@ -713,8 +766,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '资产原值', detail: '资产原值。' },
+ salvage: { name: '资产残值', detail: '折旧末尾时的值(有时也称为资产残值)。' },
+ life: { name: '资产使用寿命', detail: '资产的折旧期数(有时也称作资产的使用寿命)。' },
},
},
SYD: {
@@ -727,8 +781,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '资产原值', detail: '资产原值。' },
+ salvage: { name: '资产残值', detail: '折旧末尾时的值(有时也称为资产残值)。' },
+ life: { name: '资产使用寿命', detail: '资产的折旧期数(有时也称作资产的使用寿命)。' },
+ per: { name: '期间', detail: '期间。' },
},
},
TBILLEQ: {
@@ -741,8 +797,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '国库券的结算日。' },
+ maturity: { name: '到期日', detail: '国库券的到期日。' },
+ discount: { name: '贴现率', detail: '国库券的贴现率。' },
},
},
TBILLPRICE: {
@@ -755,8 +812,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '国库券的结算日。' },
+ maturity: { name: '到期日', detail: '国库券的到期日。' },
+ discount: { name: '贴现率', detail: '国库券的贴现率。' },
},
},
TBILLYIELD: {
@@ -769,8 +827,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '国库券的结算日。' },
+ maturity: { name: '到期日', detail: '国库券的到期日。' },
+ pr: { name: '价格', detail: '面值 ¥100 的国库券的价格。' },
},
},
VDB: {
@@ -783,8 +842,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '成本', detail: '资产原值。' },
+ salvage: { name: '残值', detail: '折旧末尾时的值(有时也称为资产残值)。' },
+ life: { name: '使用寿命', detail: '资产的折旧期数(有时也称作资产的使用寿命)。' },
+ startPeriod: { name: '起始时期', detail: '您要计算折旧的起始时期。' },
+ endPeriod: { name: '终止时期', detail: '您要计算折旧的终止时期。' },
+ factor: { name: '速率', detail: '余额递减速率。如果省略影响因素,则假定为2(双倍余额递减法)。' },
+ noSwitch: { name: '不切换', detail: '逻辑值,指定当折旧值大于余额递减计算值时,是否转用直线折旧法。' },
},
},
XIRR: {
@@ -797,8 +861,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: '现金流', detail: '与 dates 中的支付时间相对应的一系列现金流。 首期支付是可选的,并与投资开始时的成本或支付有关。 如果第一个值是成本或支付,则它必须是负值。 所有后续支付都基于 365 天/年贴现。 值系列中必须至少包含一个正值和一个负值。' },
+ dates: { name: '日期表', detail: '与现金流支付相对应的支付日期表。 日期可以按任意顺序出现。' },
+ guess: { name: '估计值', detail: '对函数 XIRR 计算结果的估计值。' },
},
},
XNPV: {
@@ -811,8 +876,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '贴现率', detail: '应用于现金流的贴现率。' },
+ values: { name: '现金流', detail: '与 dates 中的支付时间相对应的一系列现金流。 首期支付是可选的,并与投资开始时的成本或支付有关。 如果第一个值是成本或支付,则它必须是负值。 所有后续支付都基于 365 天/年贴现。 值系列中必须至少包含一个正值和一个负值。' },
+ dates: { name: '日期表', detail: '与现金流支付相对应的支付日期表。 日期可以按任意顺序出现。' },
},
},
YIELD: {
@@ -825,8 +891,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ rate: { name: '利率', detail: '有价证券的利率。' },
+ pr: { name: '价格', detail: '有价证券的价格(按面值为 ¥100 计算)。' },
+ redemption: { name: '清偿价', detail: '面值 ¥100 的有价证券的清偿价值。' },
+ frequency: { name: '频次', detail: '年付息次数。 如果按年支付,frequency = 1;按半年期支付,frequency = 2;按季支付,frequency = 4。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
YIELDDISC: {
@@ -839,8 +910,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: '要使用的日计数基准类型。' },
},
},
YIELDMAT: {
@@ -853,8 +927,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '结算日', detail: '有价证券的结算日。' },
+ maturity: { name: '到期日', detail: '有价证券的到期日。' },
+ issue: { name: '发行日', detail: '有价证券的发行日。' },
+ rate: { name: '利率', detail: '有价证券的利率。' },
+ pr: { name: '价格', detail: '有价证券的价格(按面值为 ¥100 计算)。' },
+ basis: { name: '基准', detail: '要使用的日计数基准类型。' },
},
},
};
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 167e6cdd33..d8c74b6873 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
@@ -306,8 +306,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ coupon: { name: '年度票息率', detail: '這是證券的年度票息率。' },
+ yld: { name: '年收益率', detail: '這是證券的年收益。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
EFFECT: {
@@ -400,8 +404,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: '現金流', detail: '這是陣列或儲存格參照,其中包含要計算內部報酬率的數字。\n1.Values 必須至少包含一個正數和一個負數,以計算內部報酬率。\n2.IRR 使用 values 的順序來表示現金流量的順序。 請務必依所要的順序輸入支出及收入的值。\n3.如果陣列或參照引數中包含文字、邏輯值或空白儲存格,則這些值將會略過。' },
+ guess: { name: '猜測值', detail: '這是您猜測接近 IRR 結果的數字。' },
},
},
ISPMT: {
@@ -430,8 +434,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ coupon: { name: '年度票息率', detail: '這是證券的年度票息率。' },
+ yld: { name: '年收益率', detail: '這是證券的年收益。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
MIRR: {
@@ -444,8 +452,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: '現金流', detail: '這是陣列或儲存格參照,其中包含數字。 這些數字代表定期發生的一系列支出 (負值) 和收入 (正值)。\n1.Values 必須至少包含一個正值和一個負值,以計算經修改的內部報酬率。 否則,MIRR 會傳回 #DIV/0! 的錯誤值。\n2.如果陣列或參照引數包含文字、邏輯值或空白儲存格,則忽略這些數值;但包含零值儲存格。' },
+ financeRate: { name: '融資利率', detail: '這是投入資金的融資利率。' },
+ reinvestRate: { name: '轉投資報酬率', detail: '這是各期收入淨額的轉投資報酬率。' },
},
},
NOMINAL: {
@@ -489,8 +498,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '貼現率', detail: '這是一段期間內的貼現率。' },
+ value1: { name: '現金流1', detail: '這是 1 到 254 個代表支出和收入的引數。' },
+ value2: { name: '現金流2', detail: '這是 1 到 254 個代表支出和收入的引數。' },
},
},
ODDFPRICE: {
@@ -503,8 +513,15 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ issue: { name: '發行日期', detail: '這是證券的發行日期。' },
+ firstCoupon: { name: '首次付息日期', detail: '這是證券的首次付息日期。' },
+ rate: { name: '利率', detail: '這是證券的年度票息率。' },
+ yld: { name: '年收益率', detail: '這是證券的年收益。' },
+ redemption: { name: '贖回價', detail: '這是證券到期時的贖回價值。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
ODDFYIELD: {
@@ -512,12 +529,20 @@ export default {
abstract: '返回第一期為奇數的債券的收益',
links: [
{
- title: '教導', url: 'https://support.microsoft.com/zh-tw/office/oddfyield-%E5%87%BD%E6%95%B0-66bc8b7b-6501-4c93-9ce3-2fd16220fe37',
+ title: '教導',
+ url: 'https://support.microsoft.com/zh-tw/office/oddfyield-%E5%87%BD%E6%95%B0-66bc8b7b-6501-4c93-9ce3-2fd16220fe37',
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ issue: { name: '發行日期', detail: '這是證券的發行日期。' },
+ firstCoupon: { name: '首次付息日期', detail: '這是證券的首次付息日期。' },
+ rate: { name: '利率', detail: '這是證券的年度票息率。' },
+ pr: { name: '價格', detail: '這是證券的價格。' },
+ redemption: { name: '贖回價', detail: '這是證券到期時的贖回價值。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
ODDLPRICE: {
@@ -530,8 +555,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ lastInterest: { name: '最後票息日期', detail: '這是證券的最後票息日期。' },
+ rate: { name: '利率', detail: '這是證券的年度票息率。' },
+ yld: { name: '年收益率', detail: '這是證券的年收益。' },
+ redemption: { name: '贖回價', detail: '這是證券到期時的贖回價值。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
ODDLYIELD: {
@@ -544,8 +575,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ lastInterest: { name: '最後票息日期', detail: '這是證券的最後票息日期。' },
+ rate: { name: '利率', detail: '這是證券的年度票息率。' },
+ pr: { name: '價格', detail: '這是證券的價格。' },
+ redemption: { name: '贖回價', detail: '這是證券到期時的贖回價值。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
PDURATION: {
@@ -558,8 +595,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '利率', detail: '每期的利率。' },
+ pv: { name: '現值', detail: '投資的現值。' },
+ fv: { name: '未來價值', detail: '投資所需的未來值。' },
},
},
PMT: {
@@ -607,8 +645,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ rate: { name: '利率', detail: '這是證券的年度票息率。' },
+ yld: { name: '年收益率', detail: '這是證券的年收益。' },
+ redemption: { name: '贖回價', detail: '這是證券到期時的贖回價值。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
PRICEDISC: {
@@ -621,8 +664,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ discount: { name: '貼現率', detail: '這是證券的貼現率。' },
+ redemption: { name: '贖回價', detail: '這是證券到期時的贖回價值。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
PRICEMAT: {
@@ -635,8 +681,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ issue: { name: '發行日期', detail: '這是證券的發行日期。' },
+ rate: { name: '利率', detail: '這是證券的年度票息率。' },
+ yld: { name: '年收益率', detail: '這是證券的年收益。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
PV: {
@@ -684,8 +734,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ investment: { name: '投資額', detail: '這是證券的投資額。' },
+ discount: { name: '貼現率', detail: '這是證券的貼現率。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
RRI: {
@@ -698,8 +751,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ nper: { name: '總期數', detail: '投資的期數。' },
+ pv: { name: '現值', detail: '投資的現值。' },
+ fv: { name: '未來值', detail: '投資的未來值。' },
},
},
SLN: {
@@ -712,8 +766,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '資產原始成本', detail: '這是資產的原始成本。' },
+ salvage: { name: '資產殘餘價值', detail: '這是折舊最後的值 (有時稱為資產的殘餘價值)。' },
+ life: { name: '資產使用年限', detail: '這是固定資產折舊的期數 (有時稱為固定資產的使用年限)。' },
},
},
SYD: {
@@ -726,8 +781,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '資產原始成本', detail: '這是資產的原始成本。' },
+ salvage: { name: '資產殘餘價值', detail: '這是折舊最後的值 (有時稱為資產的殘餘價值)。' },
+ life: { name: '資產使用年限', detail: '這是固定資產折舊的期數 (有時稱為固定資產的使用年限)。' },
+ per: { name: '週期', detail: '這是週期。' },
},
},
TBILLEQ: {
@@ -740,8 +797,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是國庫券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是國庫券的到期日期。' },
+ discount: { name: '貼現率', detail: '這是國庫券的貼現率。' },
},
},
TBILLPRICE: {
@@ -754,8 +812,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是國庫券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是國庫券的到期日期。' },
+ discount: { name: '貼現率', detail: '這是國庫券的貼現率。' },
},
},
TBILLYIELD: {
@@ -768,8 +827,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是國庫券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是國庫券的到期日期。' },
+ pr: { name: '價格', detail: '這是國庫債券每 $100 美元面額的價格。' },
},
},
VDB: {
@@ -782,8 +842,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ cost: { name: '成本', detail: '這是資產的原始成本。' },
+ salvage: { name: '殘值', detail: '這是折舊最後的值 (有時稱為資產的殘餘價值)。' },
+ life: { name: '使用年限', detail: '這是資產折舊的期數 (有時稱為資產的使用年限)。' },
+ startPeriod: { name: '開始期間', detail: '這是要計算折舊的開始期間。' },
+ endPeriod: { name: '結束期間', detail: '這是要計算折舊的結束期間。' },
+ factor: { name: '速率', detail: '這是餘額遞減的速率。如果省略factor,將假設其值為2(倍率遞減法)。' },
+ noSwitch: { name: '不切換', detail: '這是用於指定當折舊大於遞減餘額計算時,是否切換到直線折舊法的邏輯值。' },
},
},
XIRR: {
@@ -796,8 +861,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ values: { name: '現金流', detail: '這是一系列與 dates 的付款日期對應的現金流。第一次付款是選擇性的,而且與投資開始時的成本和付款對應。如果第一個值是成本或付款,則它必須是負值。而之後的付款都會以一年 365 天為基礎來折算。序列值必須至少包括一個正值和一個負值。' },
+ dates: { name: '日期表', detail: '這是一系列與現金流對應的付款日期。日期可能會以任何順序發生。' },
+ guess: { name: '猜測值', detail: '這是您所猜測接近 XIRR 結果的數字。' },
},
},
XNPV: {
@@ -810,8 +876,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ rate: { name: '貼現率', detail: '這是要套用到現金流的貼現率。' },
+ values: { name: '現金流', detail: '這是一系列與 dates 的付款日期對應的現金流。第一次付款是選擇性的,而且與投資開始時的成本和付款對應。如果第一個值是成本或付款,則它必須是負值。而之後的付款都會以一年 365 天為基礎來折算。序列值必須至少包括一個正值和一個負值。' },
+ dates: { name: '日期表', detail: '這是一系列與現金流對應的付款日期。日期可能會以任何順序發生。' },
},
},
YIELD: {
@@ -823,8 +890,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ rate: { name: '利率', detail: '這是證券的年度票息率。' },
+ pr: { name: '價格', detail: '這是證券每 $100 面額的價格。' },
+ redemption: { name: '贖回價', detail: '這是證券到期時的贖回價值。' },
+ frequency: { name: '頻次', detail: '這是每年票息付款的次數。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
YIELDDISC: {
@@ -837,8 +909,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: '這是證券到期時的贖回價值。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
YIELDMAT: {
@@ -851,8 +926,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ settlement: { name: '結算日期', detail: '這是證券的結算日期。' },
+ maturity: { name: '到期日期', detail: '這是證券的到期日期。' },
+ issue: { name: '發行日期', detail: '這是證券的發行日期。' },
+ rate: { name: '利率', detail: '這是證券的年度票息率。' },
+ pr: { name: '價格', detail: '這是證券每 $100 面額的價格。' },
+ basis: { name: '基礎', detail: '這是要使用的日計數基礎類型。' },
},
},
};
diff --git a/packages/sheets-formula/src/services/function-list/financial.ts b/packages/sheets-formula/src/services/function-list/financial.ts
index 57c763f823..851c0ca957 100644
--- a/packages/sheets-formula/src/services/function-list/financial.ts
+++ b/packages/sheets-formula/src/services/function-list/financial.ts
@@ -699,19 +699,47 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.DURATION.abstract',
functionParameter: [
{
- name: 'formula.functionList.DURATION.functionParameter.number1.name',
- detail: 'formula.functionList.DURATION.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DURATION.functionParameter.settlement.name',
+ detail: 'formula.functionList.DURATION.functionParameter.settlement.detail',
+ example: '"2018-7-1"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DURATION.functionParameter.number2.name',
- detail: 'formula.functionList.DURATION.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DURATION.functionParameter.maturity.name',
+ detail: 'formula.functionList.DURATION.functionParameter.maturity.detail',
+ example: '"2048-1-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DURATION.functionParameter.coupon.name',
+ detail: 'formula.functionList.DURATION.functionParameter.coupon.detail',
+ example: '0.08',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DURATION.functionParameter.yld.name',
+ detail: 'formula.functionList.DURATION.functionParameter.yld.detail',
+ example: '0.09',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DURATION.functionParameter.frequency.name',
+ detail: 'formula.functionList.DURATION.functionParameter.frequency.detail',
+ example: '2',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.DURATION.functionParameter.basis.name',
+ detail: 'formula.functionList.DURATION.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -901,17 +929,17 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.IRR.abstract',
functionParameter: [
{
- name: 'formula.functionList.IRR.functionParameter.number1.name',
- detail: 'formula.functionList.IRR.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.IRR.functionParameter.values.name',
+ detail: 'formula.functionList.IRR.functionParameter.values.detail',
+ example: '{-700000,120000,150000,180000,210000,260000}',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.IRR.functionParameter.number2.name',
- detail: 'formula.functionList.IRR.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
+ name: 'formula.functionList.IRR.functionParameter.guess.name',
+ detail: 'formula.functionList.IRR.functionParameter.guess.detail',
+ example: '0.1',
+ require: 0,
repeat: 0,
},
],
@@ -959,19 +987,47 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.MDURATION.abstract',
functionParameter: [
{
- name: 'formula.functionList.MDURATION.functionParameter.number1.name',
- detail: 'formula.functionList.MDURATION.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.MDURATION.functionParameter.settlement.name',
+ detail: 'formula.functionList.MDURATION.functionParameter.settlement.detail',
+ example: '"2018-7-1"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.MDURATION.functionParameter.number2.name',
- detail: 'formula.functionList.MDURATION.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.MDURATION.functionParameter.maturity.name',
+ detail: 'formula.functionList.MDURATION.functionParameter.maturity.detail',
+ example: '"2048-1-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.MDURATION.functionParameter.coupon.name',
+ detail: 'formula.functionList.MDURATION.functionParameter.coupon.detail',
+ example: '0.08',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.MDURATION.functionParameter.yld.name',
+ detail: 'formula.functionList.MDURATION.functionParameter.yld.detail',
+ example: '0.09',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.MDURATION.functionParameter.frequency.name',
+ detail: 'formula.functionList.MDURATION.functionParameter.frequency.detail',
+ example: '2',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.MDURATION.functionParameter.basis.name',
+ detail: 'formula.functionList.MDURATION.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -981,16 +1037,23 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.MIRR.abstract',
functionParameter: [
{
- name: 'formula.functionList.MIRR.functionParameter.number1.name',
- detail: 'formula.functionList.MIRR.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.MIRR.functionParameter.values.name',
+ detail: 'formula.functionList.MIRR.functionParameter.values.detail',
+ example: '{-120000,39000,30000,21000,37000,46000}',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.MIRR.functionParameter.number2.name',
- detail: 'formula.functionList.MIRR.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.MIRR.functionParameter.financeRate.name',
+ detail: 'formula.functionList.MIRR.functionParameter.financeRate.detail',
+ example: '0.1',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.MIRR.functionParameter.reinvestRate.name',
+ detail: 'formula.functionList.MIRR.functionParameter.reinvestRate.detail',
+ example: '0.12',
require: 1,
repeat: 0,
},
@@ -1068,19 +1131,26 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.NPV.abstract',
functionParameter: [
{
- name: 'formula.functionList.NPV.functionParameter.number1.name',
- detail: 'formula.functionList.NPV.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.NPV.functionParameter.rate.name',
+ detail: 'formula.functionList.NPV.functionParameter.rate.detail',
+ example: '0.1',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.NPV.functionParameter.number2.name',
- detail: 'formula.functionList.NPV.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.NPV.functionParameter.value1.name',
+ detail: 'formula.functionList.NPV.functionParameter.value1.detail',
+ example: '{-10000,3000,4200,6800}',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.NPV.functionParameter.value2.name',
+ detail: 'formula.functionList.NPV.functionParameter.value2.detail',
+ example: '-9000',
+ require: 0,
+ repeat: 1,
+ },
],
},
{
@@ -1090,19 +1160,68 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.ODDFPRICE.abstract',
functionParameter: [
{
- name: 'formula.functionList.ODDFPRICE.functionParameter.number1.name',
- detail: 'formula.functionList.ODDFPRICE.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ODDFPRICE.functionParameter.settlement.name',
+ detail: 'formula.functionList.ODDFPRICE.functionParameter.settlement.detail',
+ example: '"2008-11-11"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.ODDFPRICE.functionParameter.number2.name',
- detail: 'formula.functionList.ODDFPRICE.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ODDFPRICE.functionParameter.maturity.name',
+ detail: 'formula.functionList.ODDFPRICE.functionParameter.maturity.detail',
+ example: '"2021-3-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFPRICE.functionParameter.issue.name',
+ detail: 'formula.functionList.ODDFPRICE.functionParameter.issue.detail',
+ example: '"2008-10-15"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFPRICE.functionParameter.firstCoupon.name',
+ detail: 'formula.functionList.ODDFPRICE.functionParameter.firstCoupon.detail',
+ example: '"2009-3-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFPRICE.functionParameter.rate.name',
+ detail: 'formula.functionList.ODDFPRICE.functionParameter.rate.detail',
+ example: '0.0785',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFPRICE.functionParameter.yld.name',
+ detail: 'formula.functionList.ODDFPRICE.functionParameter.yld.detail',
+ example: '0.0625',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFPRICE.functionParameter.redemption.name',
+ detail: 'formula.functionList.ODDFPRICE.functionParameter.redemption.detail',
+ example: '100',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.ODDFPRICE.functionParameter.frequency.name',
+ detail: 'formula.functionList.ODDFPRICE.functionParameter.frequency.detail',
+ example: '2',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFPRICE.functionParameter.basis.name',
+ detail: 'formula.functionList.ODDFPRICE.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1112,19 +1231,68 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.ODDFYIELD.abstract',
functionParameter: [
{
- name: 'formula.functionList.ODDFYIELD.functionParameter.number1.name',
- detail: 'formula.functionList.ODDFYIELD.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ODDFYIELD.functionParameter.settlement.name',
+ detail: 'formula.functionList.ODDFYIELD.functionParameter.settlement.detail',
+ example: '"2008-11-11"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.ODDFYIELD.functionParameter.number2.name',
- detail: 'formula.functionList.ODDFYIELD.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ODDFYIELD.functionParameter.maturity.name',
+ detail: 'formula.functionList.ODDFYIELD.functionParameter.maturity.detail',
+ example: '"2021-3-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFYIELD.functionParameter.issue.name',
+ detail: 'formula.functionList.ODDFYIELD.functionParameter.issue.detail',
+ example: '"2008-10-15"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFYIELD.functionParameter.firstCoupon.name',
+ detail: 'formula.functionList.ODDFYIELD.functionParameter.firstCoupon.detail',
+ example: '"2009-3-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFYIELD.functionParameter.rate.name',
+ detail: 'formula.functionList.ODDFYIELD.functionParameter.rate.detail',
+ example: '0.0575',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFYIELD.functionParameter.pr.name',
+ detail: 'formula.functionList.ODDFYIELD.functionParameter.pr.detail',
+ example: '84.5',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFYIELD.functionParameter.redemption.name',
+ detail: 'formula.functionList.ODDFYIELD.functionParameter.redemption.detail',
+ example: '100',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.ODDFYIELD.functionParameter.frequency.name',
+ detail: 'formula.functionList.ODDFYIELD.functionParameter.frequency.detail',
+ example: '2',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDFYIELD.functionParameter.basis.name',
+ detail: 'formula.functionList.ODDFYIELD.functionParameter.basis.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1134,19 +1302,61 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.ODDLPRICE.abstract',
functionParameter: [
{
- name: 'formula.functionList.ODDLPRICE.functionParameter.number1.name',
- detail: 'formula.functionList.ODDLPRICE.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ODDLPRICE.functionParameter.settlement.name',
+ detail: 'formula.functionList.ODDLPRICE.functionParameter.settlement.detail',
+ example: '"2008-11-11"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.ODDLPRICE.functionParameter.number2.name',
- detail: 'formula.functionList.ODDLPRICE.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ODDLPRICE.functionParameter.maturity.name',
+ detail: 'formula.functionList.ODDLPRICE.functionParameter.maturity.detail',
+ example: '"2021-3-1"',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.ODDLPRICE.functionParameter.lastInterest.name',
+ detail: 'formula.functionList.ODDLPRICE.functionParameter.lastInterest.detail',
+ example: '"2009-3-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDLPRICE.functionParameter.rate.name',
+ detail: 'formula.functionList.ODDLPRICE.functionParameter.rate.detail',
+ example: '0.0785',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDLPRICE.functionParameter.yld.name',
+ detail: 'formula.functionList.ODDLPRICE.functionParameter.yld.detail',
+ example: '0.0625',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDLPRICE.functionParameter.redemption.name',
+ detail: 'formula.functionList.ODDLPRICE.functionParameter.redemption.detail',
+ example: '100',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDLPRICE.functionParameter.frequency.name',
+ detail: 'formula.functionList.ODDLPRICE.functionParameter.frequency.detail',
+ example: '2',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDLPRICE.functionParameter.basis.name',
+ detail: 'formula.functionList.ODDLPRICE.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1156,19 +1366,61 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.ODDLYIELD.abstract',
functionParameter: [
{
- name: 'formula.functionList.ODDLYIELD.functionParameter.number1.name',
- detail: 'formula.functionList.ODDLYIELD.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ODDLYIELD.functionParameter.settlement.name',
+ detail: 'formula.functionList.ODDLYIELD.functionParameter.settlement.detail',
+ example: '"2008-11-11"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.ODDLYIELD.functionParameter.number2.name',
- detail: 'formula.functionList.ODDLYIELD.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ODDLYIELD.functionParameter.maturity.name',
+ detail: 'formula.functionList.ODDLYIELD.functionParameter.maturity.detail',
+ example: '"2021-3-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDLYIELD.functionParameter.lastInterest.name',
+ detail: 'formula.functionList.ODDLYIELD.functionParameter.lastInterest.detail',
+ example: '"2008-10-15"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDLYIELD.functionParameter.rate.name',
+ detail: 'formula.functionList.ODDLYIELD.functionParameter.rate.detail',
+ example: '0.0575',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDLYIELD.functionParameter.pr.name',
+ detail: 'formula.functionList.ODDLYIELD.functionParameter.pr.detail',
+ example: '84.5',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDLYIELD.functionParameter.redemption.name',
+ detail: 'formula.functionList.ODDLYIELD.functionParameter.redemption.detail',
+ example: '100',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.ODDLYIELD.functionParameter.frequency.name',
+ detail: 'formula.functionList.ODDLYIELD.functionParameter.frequency.detail',
+ example: '2',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.ODDLYIELD.functionParameter.basis.name',
+ detail: 'formula.functionList.ODDLYIELD.functionParameter.basis.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1178,16 +1430,23 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.PDURATION.abstract',
functionParameter: [
{
- name: 'formula.functionList.PDURATION.functionParameter.number1.name',
- detail: 'formula.functionList.PDURATION.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PDURATION.functionParameter.rate.name',
+ detail: 'formula.functionList.PDURATION.functionParameter.rate.detail',
+ example: '0.025',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.PDURATION.functionParameter.number2.name',
- detail: 'formula.functionList.PDURATION.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PDURATION.functionParameter.pv.name',
+ detail: 'formula.functionList.PDURATION.functionParameter.pv.detail',
+ example: '2000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PDURATION.functionParameter.fv.name',
+ detail: 'formula.functionList.PDURATION.functionParameter.fv.detail',
+ example: '2200',
require: 1,
repeat: 0,
},
@@ -1293,19 +1552,54 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.PRICE.abstract',
functionParameter: [
{
- name: 'formula.functionList.PRICE.functionParameter.number1.name',
- detail: 'formula.functionList.PRICE.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PRICE.functionParameter.settlement.name',
+ detail: 'formula.functionList.PRICE.functionParameter.settlement.detail',
+ example: '"2008-11-11"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.PRICE.functionParameter.number2.name',
- detail: 'formula.functionList.PRICE.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PRICE.functionParameter.maturity.name',
+ detail: 'formula.functionList.PRICE.functionParameter.maturity.detail',
+ example: '"2021-3-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PRICE.functionParameter.rate.name',
+ detail: 'formula.functionList.PRICE.functionParameter.rate.detail',
+ example: '0.0785',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PRICE.functionParameter.yld.name',
+ detail: 'formula.functionList.PRICE.functionParameter.yld.detail',
+ example: '0.0625',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.PRICE.functionParameter.redemption.name',
+ detail: 'formula.functionList.PRICE.functionParameter.redemption.detail',
+ example: '100',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PRICE.functionParameter.frequency.name',
+ detail: 'formula.functionList.PRICE.functionParameter.frequency.detail',
+ example: '2',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PRICE.functionParameter.basis.name',
+ detail: 'formula.functionList.PRICE.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1315,19 +1609,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.PRICEDISC.abstract',
functionParameter: [
{
- name: 'formula.functionList.PRICEDISC.functionParameter.number1.name',
- detail: 'formula.functionList.PRICEDISC.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PRICEDISC.functionParameter.settlement.name',
+ detail: 'formula.functionList.PRICEDISC.functionParameter.settlement.detail',
+ example: '"2008-11-11"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.PRICEDISC.functionParameter.number2.name',
- detail: 'formula.functionList.PRICEDISC.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PRICEDISC.functionParameter.maturity.name',
+ detail: 'formula.functionList.PRICEDISC.functionParameter.maturity.detail',
+ example: '"2021-3-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PRICEDISC.functionParameter.discount.name',
+ detail: 'formula.functionList.PRICEDISC.functionParameter.discount.detail',
+ example: '0.0625',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PRICEDISC.functionParameter.redemption.name',
+ detail: 'formula.functionList.PRICEDISC.functionParameter.redemption.detail',
+ example: '100',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.PRICEDISC.functionParameter.basis.name',
+ detail: 'formula.functionList.PRICEDISC.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1337,19 +1652,47 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.PRICEMAT.abstract',
functionParameter: [
{
- name: 'formula.functionList.PRICEMAT.functionParameter.number1.name',
- detail: 'formula.functionList.PRICEMAT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PRICEMAT.functionParameter.settlement.name',
+ detail: 'formula.functionList.PRICEMAT.functionParameter.settlement.detail',
+ example: '"2008-11-11"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.PRICEMAT.functionParameter.number2.name',
- detail: 'formula.functionList.PRICEMAT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.PRICEMAT.functionParameter.maturity.name',
+ detail: 'formula.functionList.PRICEMAT.functionParameter.maturity.detail',
+ example: '"2021-3-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PRICEMAT.functionParameter.issue.name',
+ detail: 'formula.functionList.PRICEMAT.functionParameter.issue.detail',
+ example: '"2008-10-15"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PRICEMAT.functionParameter.rate.name',
+ detail: 'formula.functionList.PRICEMAT.functionParameter.rate.detail',
+ example: '0.0785',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.PRICEMAT.functionParameter.yld.name',
+ detail: 'formula.functionList.PRICEMAT.functionParameter.yld.detail',
+ example: '0.0625',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.PRICEMAT.functionParameter.basis.name',
+ detail: 'formula.functionList.PRICEMAT.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1452,19 +1795,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.RECEIVED.abstract',
functionParameter: [
{
- name: 'formula.functionList.RECEIVED.functionParameter.number1.name',
- detail: 'formula.functionList.RECEIVED.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.RECEIVED.functionParameter.settlement.name',
+ detail: 'formula.functionList.RECEIVED.functionParameter.settlement.detail',
+ example: '"2008-2-15"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.RECEIVED.functionParameter.number2.name',
- detail: 'formula.functionList.RECEIVED.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.RECEIVED.functionParameter.maturity.name',
+ detail: 'formula.functionList.RECEIVED.functionParameter.maturity.detail',
+ example: '"2008-3-15"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.RECEIVED.functionParameter.investment.name',
+ detail: 'formula.functionList.RECEIVED.functionParameter.investment.detail',
+ example: '10000000',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.RECEIVED.functionParameter.discount.name',
+ detail: 'formula.functionList.RECEIVED.functionParameter.discount.detail',
+ example: '0.0575',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.RECEIVED.functionParameter.basis.name',
+ detail: 'formula.functionList.RECEIVED.functionParameter.basis.detail',
+ example: '2',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1474,16 +1838,23 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.RRI.abstract',
functionParameter: [
{
- name: 'formula.functionList.RRI.functionParameter.number1.name',
- detail: 'formula.functionList.RRI.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.RRI.functionParameter.nper.name',
+ detail: 'formula.functionList.RRI.functionParameter.nper.detail',
+ example: '96',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.RRI.functionParameter.number2.name',
- detail: 'formula.functionList.RRI.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.RRI.functionParameter.pv.name',
+ detail: 'formula.functionList.RRI.functionParameter.pv.detail',
+ example: '10000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.RRI.functionParameter.fv.name',
+ detail: 'formula.functionList.RRI.functionParameter.fv.detail',
+ example: '11000',
require: 1,
repeat: 0,
},
@@ -1496,16 +1867,23 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.SLN.abstract',
functionParameter: [
{
- name: 'formula.functionList.SLN.functionParameter.number1.name',
- detail: 'formula.functionList.SLN.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.SLN.functionParameter.cost.name',
+ detail: 'formula.functionList.SLN.functionParameter.cost.detail',
+ example: '300000',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.SLN.functionParameter.number2.name',
- detail: 'formula.functionList.SLN.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.SLN.functionParameter.salvage.name',
+ detail: 'formula.functionList.SLN.functionParameter.salvage.detail',
+ example: '75000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.SLN.functionParameter.life.name',
+ detail: 'formula.functionList.SLN.functionParameter.life.detail',
+ example: '10',
require: 1,
repeat: 0,
},
@@ -1518,16 +1896,30 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.SYD.abstract',
functionParameter: [
{
- name: 'formula.functionList.SYD.functionParameter.number1.name',
- detail: 'formula.functionList.SYD.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.SYD.functionParameter.cost.name',
+ detail: 'formula.functionList.SYD.functionParameter.cost.detail',
+ example: '300000',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.SYD.functionParameter.number2.name',
- detail: 'formula.functionList.SYD.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.SYD.functionParameter.salvage.name',
+ detail: 'formula.functionList.SYD.functionParameter.salvage.detail',
+ example: '75000',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.SYD.functionParameter.life.name',
+ detail: 'formula.functionList.SYD.functionParameter.life.detail',
+ example: '10',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.SYD.functionParameter.per.name',
+ detail: 'formula.functionList.SYD.functionParameter.per.detail',
+ example: '10',
require: 1,
repeat: 0,
},
@@ -1540,16 +1932,23 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.TBILLEQ.abstract',
functionParameter: [
{
- name: 'formula.functionList.TBILLEQ.functionParameter.number1.name',
- detail: 'formula.functionList.TBILLEQ.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TBILLEQ.functionParameter.settlement.name',
+ detail: 'formula.functionList.TBILLEQ.functionParameter.settlement.detail',
+ example: '"2008-3-31"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.TBILLEQ.functionParameter.number2.name',
- detail: 'formula.functionList.TBILLEQ.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TBILLEQ.functionParameter.maturity.name',
+ detail: 'formula.functionList.TBILLEQ.functionParameter.maturity.detail',
+ example: '"2008-6-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TBILLEQ.functionParameter.discount.name',
+ detail: 'formula.functionList.TBILLEQ.functionParameter.discount.detail',
+ example: '0.0914',
require: 1,
repeat: 0,
},
@@ -1562,16 +1961,23 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.TBILLPRICE.abstract',
functionParameter: [
{
- name: 'formula.functionList.TBILLPRICE.functionParameter.number1.name',
- detail: 'formula.functionList.TBILLPRICE.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TBILLPRICE.functionParameter.settlement.name',
+ detail: 'formula.functionList.TBILLPRICE.functionParameter.settlement.detail',
+ example: '"2008-3-31"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.TBILLPRICE.functionParameter.number2.name',
- detail: 'formula.functionList.TBILLPRICE.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TBILLPRICE.functionParameter.maturity.name',
+ detail: 'formula.functionList.TBILLPRICE.functionParameter.maturity.detail',
+ example: '"2008-6-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TBILLPRICE.functionParameter.discount.name',
+ detail: 'formula.functionList.TBILLPRICE.functionParameter.discount.detail',
+ example: '0.0914',
require: 1,
repeat: 0,
},
@@ -1584,16 +1990,23 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.TBILLYIELD.abstract',
functionParameter: [
{
- name: 'formula.functionList.TBILLYIELD.functionParameter.number1.name',
- detail: 'formula.functionList.TBILLYIELD.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TBILLYIELD.functionParameter.settlement.name',
+ detail: 'formula.functionList.TBILLYIELD.functionParameter.settlement.detail',
+ example: '"2008-3-31"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.TBILLYIELD.functionParameter.number2.name',
- detail: 'formula.functionList.TBILLYIELD.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TBILLYIELD.functionParameter.maturity.name',
+ detail: 'formula.functionList.TBILLYIELD.functionParameter.maturity.detail',
+ example: '"2008-6-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TBILLYIELD.functionParameter.pr.name',
+ detail: 'formula.functionList.TBILLYIELD.functionParameter.pr.detail',
+ example: '98.45',
require: 1,
repeat: 0,
},
@@ -1606,19 +2019,54 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.VDB.abstract',
functionParameter: [
{
- name: 'formula.functionList.VDB.functionParameter.number1.name',
- detail: 'formula.functionList.VDB.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.VDB.functionParameter.cost.name',
+ detail: 'formula.functionList.VDB.functionParameter.cost.detail',
+ example: '2400',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.VDB.functionParameter.number2.name',
- detail: 'formula.functionList.VDB.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.VDB.functionParameter.salvage.name',
+ detail: 'formula.functionList.VDB.functionParameter.salvage.detail',
+ example: '300',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.VDB.functionParameter.life.name',
+ detail: 'formula.functionList.VDB.functionParameter.life.detail',
+ example: '10',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.VDB.functionParameter.startPeriod.name',
+ detail: 'formula.functionList.VDB.functionParameter.startPeriod.detail',
+ example: '1',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.VDB.functionParameter.endPeriod.name',
+ detail: 'formula.functionList.VDB.functionParameter.endPeriod.detail',
+ example: '2',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.VDB.functionParameter.factor.name',
+ detail: 'formula.functionList.VDB.functionParameter.factor.detail',
+ example: '2',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.VDB.functionParameter.noSwitch.name',
+ detail: 'formula.functionList.VDB.functionParameter.noSwitch.detail',
+ example: 'false',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1628,19 +2076,26 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.XIRR.abstract',
functionParameter: [
{
- name: 'formula.functionList.XIRR.functionParameter.number1.name',
- detail: 'formula.functionList.XIRR.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.XIRR.functionParameter.values.name',
+ detail: 'formula.functionList.XIRR.functionParameter.values.detail',
+ example: '{-10000,2750,4250,3250,2750}',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.XIRR.functionParameter.number2.name',
- detail: 'formula.functionList.XIRR.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.XIRR.functionParameter.dates.name',
+ detail: 'formula.functionList.XIRR.functionParameter.dates.detail',
+ example: '{39448,39508,39751,39859,39904}',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.XIRR.functionParameter.guess.name',
+ detail: 'formula.functionList.XIRR.functionParameter.guess.detail',
+ example: '0.1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1650,16 +2105,23 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.XNPV.abstract',
functionParameter: [
{
- name: 'formula.functionList.XNPV.functionParameter.number1.name',
- detail: 'formula.functionList.XNPV.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.XNPV.functionParameter.rate.name',
+ detail: 'formula.functionList.XNPV.functionParameter.rate.detail',
+ example: '0.1',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.XNPV.functionParameter.number2.name',
- detail: 'formula.functionList.XNPV.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.XNPV.functionParameter.values.name',
+ detail: 'formula.functionList.XNPV.functionParameter.values.detail',
+ example: '{-10000,2750,4250,3250,2750}',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.XNPV.functionParameter.dates.name',
+ detail: 'formula.functionList.XNPV.functionParameter.dates.detail',
+ example: '{39448,39508,39751,39859,39904}',
require: 1,
repeat: 0,
},
@@ -1672,19 +2134,54 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.YIELD.abstract',
functionParameter: [
{
- name: 'formula.functionList.YIELD.functionParameter.number1.name',
- detail: 'formula.functionList.YIELD.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.YIELD.functionParameter.settlement.name',
+ detail: 'formula.functionList.YIELD.functionParameter.settlement.detail',
+ example: '"2008-11-11"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.YIELD.functionParameter.number2.name',
- detail: 'formula.functionList.YIELD.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.YIELD.functionParameter.maturity.name',
+ detail: 'formula.functionList.YIELD.functionParameter.maturity.detail',
+ example: '"2021-3-1"',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.YIELD.functionParameter.rate.name',
+ detail: 'formula.functionList.YIELD.functionParameter.rate.detail',
+ example: '0.0785',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.YIELD.functionParameter.pr.name',
+ detail: 'formula.functionList.YIELD.functionParameter.pr.detail',
+ example: '98.45',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.YIELD.functionParameter.redemption.name',
+ detail: 'formula.functionList.YIELD.functionParameter.redemption.detail',
+ example: '100',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.YIELD.functionParameter.frequency.name',
+ detail: 'formula.functionList.YIELD.functionParameter.frequency.detail',
+ example: '2',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.YIELD.functionParameter.basis.name',
+ detail: 'formula.functionList.YIELD.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1694,19 +2191,40 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.YIELDDISC.abstract',
functionParameter: [
{
- name: 'formula.functionList.YIELDDISC.functionParameter.number1.name',
- detail: 'formula.functionList.YIELDDISC.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.YIELDDISC.functionParameter.settlement.name',
+ detail: 'formula.functionList.YIELDDISC.functionParameter.settlement.detail',
+ example: '"2008-11-11"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.YIELDDISC.functionParameter.number2.name',
- detail: 'formula.functionList.YIELDDISC.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.YIELDDISC.functionParameter.maturity.name',
+ detail: 'formula.functionList.YIELDDISC.functionParameter.maturity.detail',
+ example: '"2021-3-1"',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.YIELDDISC.functionParameter.pr.name',
+ detail: 'formula.functionList.YIELDDISC.functionParameter.pr.detail',
+ example: '98.45',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.YIELDDISC.functionParameter.redemption.name',
+ detail: 'formula.functionList.YIELDDISC.functionParameter.redemption.detail',
+ example: '100',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.YIELDDISC.functionParameter.basis.name',
+ detail: 'formula.functionList.YIELDDISC.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -1716,19 +2234,47 @@ export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [
abstract: 'formula.functionList.YIELDMAT.abstract',
functionParameter: [
{
- name: 'formula.functionList.YIELDMAT.functionParameter.number1.name',
- detail: 'formula.functionList.YIELDMAT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.YIELDMAT.functionParameter.settlement.name',
+ detail: 'formula.functionList.YIELDMAT.functionParameter.settlement.detail',
+ example: '"2008-11-11"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.YIELDMAT.functionParameter.number2.name',
- detail: 'formula.functionList.YIELDMAT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.YIELDMAT.functionParameter.maturity.name',
+ detail: 'formula.functionList.YIELDMAT.functionParameter.maturity.detail',
+ example: '"2021-3-1"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.YIELDMAT.functionParameter.issue.name',
+ detail: 'formula.functionList.YIELDMAT.functionParameter.issue.detail',
+ example: '"2008-10-15"',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.YIELDMAT.functionParameter.rate.name',
+ detail: 'formula.functionList.YIELDMAT.functionParameter.rate.detail',
+ example: '0.0785',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.YIELDMAT.functionParameter.pr.name',
+ detail: 'formula.functionList.YIELDMAT.functionParameter.pr.detail',
+ example: '98.45',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.YIELDMAT.functionParameter.basis.name',
+ detail: 'formula.functionList.YIELDMAT.functionParameter.basis.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
],
},
];