After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 611436 - ACCRINT doesn't work as advertised
ACCRINT doesn't work as advertised
Status: RESOLVED FIXED
Product: Gnumeric
Classification: Applications
Component: Analytics
1.10.x
Other Linux
: Normal normal
: ---
Assigned To: Morten Welinder
Jody Goldberg
Depends on:
Blocks:
 
 
Reported: 2010-03-01 01:01 UTC by Michael Goetze
Modified: 2010-06-10 04:46 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Michael Goetze 2010-03-01 01:01:39 UTC
For all I can tell, Gnumeric seems to completely ignore the 
"first_interest" and "frequency" parameters to the ACCRINT function and 
always calculates the interest earned between "issue" and "settlement". 
It may be that I'm missing something, but then at least the 
documentation is buggy.
Comment 1 Morten Welinder 2010-03-01 01:41:59 UTC
20:32 <@gm_lap_> mgoetze: the financial functions from the XL era behave 
                 weirdly at the best of times.
20:32 <@gm_lap_> We have, I believe, some approximation of what XL does, but in 
                 general the algorithms and bugs are insufficiently documented.
20:34 <@gm_lap_> mgoetze: the code uses that argument for an error check only.
Comment 2 Morten Welinder 2010-03-01 20:15:05 UTC
Btw, if you happen to have information about what the functions should
do, we'd like to know.  We should match Excel, unless there is a very
good reason not to.
Comment 3 Michael Goetze 2010-03-01 23:14:40 UTC
I don't know what Excel does, but here's what I think the function should do:

ACCRINT(issue,first_interest,settlement,rate,par,frequency,basis)

We want to calculate the interest from the beginning of the current interest period, let's call it "interest_from", to the settlement date. When did the current interest period start? Here's an algorithm:

if (settlement < first_interest)
then
  interest_from := issue
else
  if (frequency == 1) then increment := 1 year
  if (frequency == 2) then increment := 6 months
  if (frequency == 4) then increment := 3 months
  interest_from := first_interest
  while (first_interest <= settlement)
    first_interest += increment
  first_interest -= increment

Note that adding 3 months here means increasing the number of the month by 3, and not something like adding 90 days.

Then we just need to convert "settlement - first_interest" into a percentage (the method for this is determined by "basis") and multiply that by rate and par.
Comment 4 Michael Goetze 2010-03-02 01:26:56 UTC
Sorry, the last three lines should of course have interest_from rather than first_interest.
Comment 5 Andreas J. Guelzow 2010-03-02 19:39:31 UTC
"Note that adding 3 months here means increasing the number of the month by 3,
and not something like adding 90 days." This surely should depend on the value of 'basis'.

While the specification of ACCRINT in OpenFormula at this time is badly incomplete, it includes the constraint:
issue < first_interest < settlement.

Moreover ACCRINT should calculate the "accrued interest for securities with periodic interest payments". I don't think that is the same as "the interest from the beginning of the current interest period".

Note that there is a formula given for ACCRINT at http://office.microsoft.com/en-us/excel/HP052089791033.aspx which is probably what we really should implement. (Of course this depends on somebody understanding that formula.)

Also note that GNumeric's calculation currently matches the examples on that page.
Comment 6 Andreas J. Guelzow 2010-03-02 19:47:07 UTC
I probably should have referred to http://openiso.org/Ecma/376/Part4/3.17.7 which contains the same info without the examples.
Comment 7 Michael Goetze 2010-03-02 22:05:10 UTC
(In reply to comment #5)
> "Note that adding 3 months here means increasing the number of the month by 3,
> and not something like adding 90 days." This surely should depend on the value
> of 'basis'.

How so?

> While the specification of ACCRINT in OpenFormula at this time is badly
> incomplete, it includes the constraint:
> issue < first_interest < settlement.

With that constraint, one of the parameters "issue" or "first_interest" is redundant.

However, in the real world, it makes sense to have both parameters, as there actually are securities with a first interest period of a different length than all the other interest periods (if you google "long coupon" you will see this is a well-known phenomenon).

> Moreover ACCRINT should calculate the "accrued interest for securities with
> periodic interest payments". I don't think that is the same as "the interest
> from the beginning of the current interest period".

As far as I am concerned, "the interest from the beginning of the current interest period" is an explanation of "accrued".

Quoting http://en.wikipedia.org/wiki/Accrued_interest , "In finance, accrued interest is the interest that has accumulated since the principal investment, or since the previous interest payment if there has been one already."

> Note that there is a formula given for ACCRINT at
> http://office.microsoft.com/en-us/excel/HP052089791033.aspx which is probably
> what we really should implement. (Of course this depends on somebody
> understanding that formula.)
> 
> Also note that GNumeric's calculation currently matches the examples on that
> page.

Also note that said example fails to satisfy your proposed constraint of first_interest < settlement.

The formula looks like it's trying to calculate the total cumulative earned interest since the security was issued, which would be unfortunate, since that is not what anyone actually dealing with these securities would refer to as "accrued interest".

The example unfortunately only deals with the case where the total cumulative earned interest happens to coincide with the accrued interest. It would be great if someone with a recent version of Excel could check what it actually does in the other cases.
Comment 8 Andreas J. Guelzow 2010-03-03 00:03:45 UTC
Depending on the "basis" value a year is interpreted to be anything between 360  and 366 days. Length of months also varies. For some bases, each month is considered 30 days, in others one looks at the true number of days. I doubt that all of this should have no effect on the return value.

Not ethat wikipedia is not a normative reference but is definitions can change.

Please also not e that I did not "propose" a constraint with respect to issue, settlement etc. but only quoted a constraint currently in the OpenFormula draft. I have no idea what is the correct formula or constraints.
Comment 9 Michael Goetze 2010-03-03 10:18:16 UTC
Of course "basis" should have an effect on the return value. But not by changing the interest dates. I have never seen a security which does not (nominally) pay interest on the same day of the month everytime. Rather, "basis" determines what percentage of the current coupon period is deemed to have elapsed.

My knowledge of what "accrued" means does not come from Wikipedia, but rather from actually dealing with bonds. I provided the Wikipedia quote as a courtesy for those to whom it is not so obvious. Feel free to do further research if you don't want to take my word for it.
Comment 10 Andreas J. Guelzow 2010-03-03 14:13:13 UTC
Michael, I have no doubt that you have excellent knowledge of the bond market, but ACCRINT is supposed to calculate whatever Excel does; this may not be the most useful in the bond market, (If the latter is the case that's an argument of adding another useful function, not to change ACCRINT.)

With respect to the basis issue: If a first-interest date of xxxx/11/30 at a frequency of 4 is not automatically return an error, then we can't just add 3 months since xxxx+1/2/30 does not exist. Now in real live there may not be a bond that has such an interest day but the function needs to be defined in such a way that this makes sense nonetheless.
Comment 11 Michael Goetze 2010-03-03 14:36:24 UTC
OK, I've just borrowed someone's Excel and it seems that Excel does, indeed calculate the cumulative earned interest rather than the accrued interest. Poor Excel users.

So, please consider this a feature request for a function which actually does calculate the accrued interest. Call it something else, that's fine with me.

I've never seen a bond with the problem you mentioned but I expect that the interest dates would be xxxx/11/30, xxxx+1/2/28, xxxx+1/5/30 and so on. (This could get tricky with leap years, of course...)
Comment 12 Andreas J. Guelzow 2010-03-03 18:29:04 UTC
Excel 2007's ACCRINT has another argument calc_method that determines whether to calculate the interest from issue date (the default) or from the last coupon payment date.
Comment 13 Andreas J. Guelzow 2010-03-03 18:50:49 UTC
well, my comment #12 reflected what Excel's function wizard says. 

That is not correct though. 

Its help browser says that calc_method == false calculates the interest from first_interest to settlement date (calc_method == true from issue date to settlement date).

That is not correct either.
Comment 14 Andreas J. Guelzow 2010-03-03 20:18:30 UTC
Okay, apparently:

if calc_method == true, ACCRINT returns the sum of the interest paid or accrued from issue date to settlement.

if calc_method == false, ACCRINT returns the sum of the interest paid or accrued on or after the first interest date to up to the settlement date, i.e. it ignores the interest prior to the coupon period ending on first_interest date.
Comment 15 Andreas J. Guelzow 2010-05-05 05:05:23 UTC
18.17.7.2 of ISO/IEC 29500-1:2008(E) does not mention a calc_method. It does give a mathematical formula but unfortunately it uses values (A_i  and NL_i) that are insufficiently described.
Comment 16 Andreas J. Guelzow 2010-05-05 06:11:29 UTC
It turns out that the examples in 18.17.7.2 of ISO/IEC 29500-1:2008(E) are useless in trying to figure out what A_i and NL_i are. WE are currently calculating the same values as those examples (but are really just using ACCRINTM).
Comment 17 Andreas J. Guelzow 2010-06-10 04:46:07 UTC
I have tried to clarified the description and added the calc_method argument used by Excel 2007 and later. (Note that Excel's calculation changed to Excel 2003 and again to Excel 2007.)  We seem to be matching what Excel 2007/2010 is doing. The Openformula draft make seven less sense and would have us primarily return an error value. 

Note that this is most likely not what you want to calculate. 

This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.