Hi,

 

I found that if we are in the last coupon period gnumeric returns a different price than excel. According to my HP calculator, excel is right, and gnumeric is wrong.

 

Here is one example (dates are in dd-mm-yyyy format):

 

Settlement:       07-10-2005

Maturity:           15-04-2006

Rate:                4.875%

Yield:                2.4394559%

Frequency:        1

Formula:           1

 

For these values, price returns 101.226114 in Excel and HP calculator, when gnumeric gives 101.230116.

 

I am not really a C programmer, but I would suggest the following changes in the price routine (in plugins/fn-financial/functions.c):

 

static gnm_float

price (GDate *settlement, GDate *maturity, gnm_float rate, gnm_float yield,

       gnm_float redemption, GnmCouponConvention const *conv)

{

     gnm_float a, d, e, sum, den, basem1, exponent, first_term, last_term;

     gint       k, n;

 

     a = coupdaybs (settlement, maturity, conv);

     d = coupdaysnc (settlement, maturity, conv);

     e = coupdays (settlement, maturity, conv);

     n = coupnum (settlement, maturity, conv);

 

     sum = 0.0;

     den = 100.0 * rate / conv->freq;

     basem1 = yield / conv->freq;

     exponent = d / e;

 

 

     /* START OF PATCH */

     if   (n == 1)

          return    ((100.0 + den)/(1.0+exponent*basem1)-a/e*den);

     /* END OF PATCH */

 

 

 

     /* FIXME: Eliminate loop.  */

     for (k = 0; k < n; k++)

             sum += den / pow1p (basem1, exponent + k);

 

     first_term = redemption / pow1p (basem1, (n - 1.0 + d / e));

     last_term = a / e * den;

 

     return (first_term + sum - last_term);

}

 

I hope this helps, and forgive me if I am wrong.

 

- Philippe.

_______________________________________________
gnumeric-list mailing list
gnumeric-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gnumeric-list

Reply via email to