ASPOSE ACCRINT Excel Calculation

I have this code which is calculating ACCRINT using excel in-built formula.
public static void ACCRINTExcelFile_Aspose()
{
// Define parameters
DateTime previousCouponDate = new DateTime(2024, 5, 30);
DateTime nextCouponDate = new DateTime(2027, 12, 30);
DateTime settlementDate = new DateTime(2028, 12, 12);
decimal coupon = 0.0564m; // Example coupon rate
decimal resultantCF = 300200033m; // Example resultant cash flow
int couponFrequency = 1; // Semi-annual payments
int accrualId = 1; // Example ID

// Manually calculate the ACCRINT value based on your inputs
int daysBetweenSettlementAndPrevCoupon = (settlementDate - previousCouponDate).Days;
int daysBetweenCoupons = (nextCouponDate - previousCouponDate).Days;
decimal accrintValue = (decimal)daysBetweenSettlementAndPrevCoupon / daysBetweenCoupons * coupon * resultantCF;

// Print the manually calculated ACCRINT value to the console
Console.WriteLine($"Manually Calculated ACCRINT value: {accrintValue}");

// Get the current directory and set the file path
string currentDirectory = Directory.GetCurrentDirectory();
string filePath = Path.Combine(currentDirectory, "AccrualCalculation_Aspose.xlsx");

// Create a new workbook and worksheet
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
worksheet.Name = "Accrual Calculation";

// Insert headers
worksheet.Cells["A1"].PutValue("Previous Coupon Date");
worksheet.Cells["B1"].PutValue("Next Coupon Date");
worksheet.Cells["C1"].PutValue("Settlement Date");
worksheet.Cells["D1"].PutValue("Coupon Rate");
worksheet.Cells["E1"].PutValue("Resultant CF");
worksheet.Cells["F1"].PutValue("Coupon Frequency");
worksheet.Cells["G1"].PutValue("Accrual ID");
worksheet.Cells["H1"].PutValue("ACCRINT Formula");

// Insert values into cells
worksheet.Cells["A2"].PutValue(previousCouponDate);
worksheet.Cells["B2"].PutValue(nextCouponDate);
worksheet.Cells["C2"].PutValue(settlementDate);
worksheet.Cells["D2"].PutValue(coupon);
worksheet.Cells["E2"].PutValue(resultantCF);
worksheet.Cells["F2"].PutValue(couponFrequency);
worksheet.Cells["G2"].PutValue(accrualId);

// Insert the ACCRINT formula (Aspose.Cells supports this but it will only work if the formula is correctly recognized by Excel)
worksheet.Cells["H2"].Formula = "ACCRINT(A2, B2, C2, D2, E2, F2, G2)";

// Auto fit columns for better readability
workbook.CalculateFormula();

// Retrieve the calculated value
Aspose.Cells.Cell accrintCell = worksheet.Cells["H2"];
double accrintValuenew = accrintCell.DoubleValue;

// Print the calculated ACCRINT value to the console
Console.WriteLine($"Calculated ACCRINT value: {accrintValuenew}");

// Save the workbook to the specified path
workbook.Save(filePath);

// Notify the user of the file's creation and location
Console.WriteLine($"Excel file generated at: {filePath}");

}
But the result returned by it is wrong in some cases as comapred to excel

@saloniig,

I tested your exact sample code using latest version/fix: Aspose.Cells for .NET v24.9.
Here is console results.

Manually Calculated ACCRINT value: 21432493.540113368983957219243
Calculated ACCRINT value: 76981515.05573077
Excel file generated at: e:\test2\AccrualCalculation_Aspose.xlsx

Please find attached the output Excel file for your reference.
AccrualCalculation_Aspose.zip (6.4 KB)

When I opened the output file into MS Excel manually and checked/recalculated the results (manually), I got:

76836258.45

So, to compare the above resultant value (by MS Excel) with the calculated value by Aspose.Cells’ formula calculation engine:

76981515.05573077

there is difference. Do you want us to mimic what MS Excel calculates the formula?

@amjad.sahi
Yes, this is the exact issue I am facing. The discrepancy in results between Aspose.Cells and Excel is concerning. Can you help explain why Aspose.Cells is not providing the same result as Excel? We need the calculations to match what is produced by Excel for consistency.

@saloniig,

Thanks for your confirmation.

We require thorough evaluation of the issue. We will check if Aspose.Cells’ formula calculation engine could produce the same results with MS Excel for the formula. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-56789

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@amjad.sahi

Thank you. Please let me know once you have a solution or any information on how to calculate Accrued Interest from excel.

@saloniig
You are welcome. We will notify you promptly once there are any updates or temporary solutions.

Hi @John.He
Did you got any update regarding this?

@saloniig,

We haven’t scheduled the ticket yet. Hopefully it will be done soon. Once we we figure it out or we have some other updates on it, we will let you know here.

@saloniig
We have investigated this issue, and tried many ways to solve it these days. Unfortunately, we cannot find a way to give the same result with ms excel. It seems that ms excel uses some special logic which is unknown for us to process this function. We may continue to investigate it later, but we are afraid we cannot solve it currently.