As part of the Formula.js project, I’m trying to re-implement Excel’s ACCRINT function (in JavaScript, but the language should not matter). I’ve been trying to find a proper description for how it’s supposed to work (especially with respect to the first_interest parameter), but could not find anything.
Interestingly enough, Excel, Google Spreadsheets, Apple Numbers, Gnumeric, and OpenOffice all disagree on the way to implement it, even though all three major versions of Excel (Win, Mac, Web) seem to agree with each other. Some more context can be found on this blog post.
Dozens of tests cases and my current (flawed) implementation can be found here.
Any help would be greatly appreciated!
UPDATE: to be clear, the issue is not related to the day count convention, which we implemented using David Wheeler’s pseudocode for YEARFRAC, which itself was validated by over 32 million tests, covering all five basis options. The issue comes from the first_interest parameter, which nobody seems to really understand. As far as we can tell, this parameter is simply ignored by many alternative spreadsheets, including OpenOffice (it’s commented out in the source code). And this parameter really behaves in strange ways. If you use Excel and you change its value, you will see that it will change the results given by the ACCRINT function, but in ways that seem chaotic. Try changing the first_interest date by a full century, and you’ll see the accrued interest changing, but not by much. I really can’t make sense of that. If anyone can, I’m all ears…
Phil H from Quantitative Finance found this .NET library, which provides clean room implementations for all Financial Functions, and all but two seem to pass the test (201,349 test cases in fact). These include ACCRINT. The code is licensed under Creative Commons Attribution. It’s written in F#, but it’s pretty clear. The code for ACCRINT is in the bonds.fs file. We will try to port it to JavaScript and see if we get the same results as what Excel returns. More on this soon…