~ubuntu-branches/ubuntu/feisty/gnumeric/feisty

« back to all changes in this revision

Viewing changes to plugins/fn-financial/functions.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2006-12-06 13:55:23 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20061206135523-6bh02cebuk0hduva
Tags: 1.7.5-1ubuntu1
* Merge with debian experimental:
  - debian/control, debian/*-gtk-*, debian/rules,
    debian/shlibs.local: Xubuntu changes for
    gtk/gnome multibuild.
  - run intltool-update in po*
  - Build Depend on intltool

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
static int
85
85
value_get_paytype (GnmValue const *v)
86
86
{
87
 
        if (v) {
88
 
                gnm_float f = value_get_as_float (v);
89
 
                if (f < 0 || f >= 2)
90
 
                        return -1;
91
 
                else
92
 
                        return (int)f;
93
 
        } else
94
 
                return 0;
 
87
        return (v == NULL || value_is_zero (v)) ? 0 : 1;
95
88
}
96
89
 
97
90
/***************************************************************************
145
138
 
146
139
 
147
140
static gnm_float
148
 
calculate_interest_part (gnm_float pv, gnm_float pmt,
149
 
                         gnm_float rate, gnm_float per)
150
 
{
151
 
        return -(pv * pow1p (rate, per) * rate +
152
 
                 pmt * pow1pm1 (rate, per));
153
 
}
154
 
 
155
 
static gnm_float
156
141
calculate_pmt (gnm_float rate, gnm_float nper, gnm_float pv, gnm_float fv,
157
142
               int type)
158
143
{
166
151
        return ((-pv * pvif - fv ) / ((1.0 + rate * type) * fvifa));
167
152
}
168
153
 
 
154
static gnm_float
 
155
calculate_ipmt (gnm_float rate, gnm_float per, gnm_float nper,
 
156
                gnm_float pv, gnm_float fv, int type)
 
157
{
 
158
        gnm_float pmt = calculate_pmt (rate, nper, pv, fv, /*type*/ 0);
 
159
        gnm_float ipmt = -(pv * pow1p (rate, per - 1) * rate +
 
160
                           pmt * pow1pm1 (rate, per - 1));
 
161
 
 
162
        return (type == 0) ? ipmt : ipmt / (1 + rate);
 
163
}
 
164
 
169
165
/***************************************************************************/
170
166
 
171
167
/* Returns the number of days between issue date and maturity date
265
261
         GnmCouponConvention const *conv)
266
262
{
267
263
        GDate date;
268
 
        coup_cd (&date, settlement, maturity, conv->freq, conv->eom, FALSE);
 
264
        go_coup_cd (&date, settlement, maturity, conv->freq, conv->eom, FALSE);
269
265
        return datetime_g_to_serial (&date, conv->date_conv);
270
266
}
271
267
 
274
270
         GnmCouponConvention const *conv)
275
271
{
276
272
        GDate date;
277
 
        coup_cd (&date, settlement, maturity, conv->freq, conv->eom, TRUE);
 
273
        go_coup_cd (&date, settlement, maturity, conv->freq, conv->eom, TRUE);
278
274
        return datetime_g_to_serial (&date, conv->date_conv);
279
275
}
280
276
 
285
281
        gnm_float a, d, e, sum, den, basem1, exponent, first_term, last_term;
286
282
        int       n;
287
283
 
288
 
        a = coupdaybs (settlement, maturity, conv);
289
 
        d = coupdaysnc (settlement, maturity, conv);
290
 
        e = coupdays (settlement, maturity, conv);
 
284
        a = go_coupdaybs (settlement, maturity, conv);
 
285
        d = go_coupdaysnc (settlement, maturity, conv);
 
286
        e = go_coupdays (settlement, maturity, conv);
291
287
        n = coupnum (settlement, maturity, conv);
292
288
 
293
289
        den = 100.0 * rate / conv->freq;
315
311
 ***********************************************************************/
316
312
 
317
313
static GnmValue *
318
 
func_coup (FunctionEvalInfo *ei, GnmValue const * const *argv,
 
314
func_coup (GnmFuncEvalInfo *ei, GnmValue const * const *argv,
319
315
           gnm_float (coup_fn) (GDate const *settle, GDate const *mat,
320
316
                                GnmCouponConvention const *conv))
321
317
{
390
386
};
391
387
 
392
388
static GnmValue *
393
 
gnumeric_accrint (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
389
gnumeric_accrint (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
394
390
{
395
391
        GDate      issue, first_interest, settlement;
396
392
        gnm_float rate, a, d, par, freq;
469
465
};
470
466
 
471
467
static GnmValue *
472
 
gnumeric_accrintm (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
468
gnumeric_accrintm (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
473
469
{
474
470
        gnm_float rate, a, d, par;
475
471
        int basis;
534
530
};
535
531
 
536
532
static GnmValue *
537
 
gnumeric_intrate (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
533
gnumeric_intrate (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
538
534
{
539
535
        gnm_float investment, redemption, a, d;
540
536
        int basis;
593
589
};
594
590
 
595
591
static GnmValue *
596
 
gnumeric_received (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
592
gnumeric_received (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
597
593
{
598
594
        gnm_float investment, discount, a, d, n;
599
595
        int basis;
654
650
};
655
651
 
656
652
static GnmValue *
657
 
gnumeric_pricedisc (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
653
gnumeric_pricedisc (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
658
654
{
659
655
        gnm_float discount, redemption, a, d;
660
656
        int basis;
710
706
};
711
707
 
712
708
static GnmValue *
713
 
gnumeric_pricemat (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
709
gnumeric_pricemat (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
714
710
{
715
711
        gnm_float discount, yield, a, b, dsm, dim, n;
716
712
        int basis;
773
769
};
774
770
 
775
771
static GnmValue *
776
 
gnumeric_disc (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
772
gnumeric_disc (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
777
773
{
778
774
        gnm_float par, redemption, dsm, b;
779
775
        int basis;
832
828
};
833
829
 
834
830
static GnmValue *
835
 
gnumeric_effect (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
831
gnumeric_effect (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
836
832
{
837
833
        gnm_float rate = value_get_as_float (argv[0]);
838
834
        gnm_float nper = gnm_floor (value_get_as_float (argv[1]));
873
869
};
874
870
 
875
871
static GnmValue *
876
 
gnumeric_nominal (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
872
gnumeric_nominal (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
877
873
{
878
874
        gnm_float rate = value_get_as_float (argv[0]);
879
875
        gnm_float nper = gnm_floor (value_get_as_float (argv[1]));
904
900
};
905
901
 
906
902
static GnmValue *
907
 
gnumeric_ispmt (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
903
gnumeric_ispmt (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
908
904
{
909
905
        gnm_float tmp;
910
906
 
954
950
};
955
951
 
956
952
static GnmValue *
957
 
gnumeric_db (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
953
gnumeric_db (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
958
954
{
959
955
        gnm_float rate;
960
956
        gnm_float cost, salvage, life, period, month;
1018
1014
};
1019
1015
 
1020
1016
static GnmValue *
1021
 
gnumeric_ddb (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1017
gnumeric_ddb (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1022
1018
{
1023
1019
        gnm_float cost, salvage, life, period, factor;
1024
1020
        gnm_float total;
1083
1079
 
1084
1080
 
1085
1081
static GnmValue *
1086
 
gnumeric_sln (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1082
gnumeric_sln (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1087
1083
{
1088
1084
        gnm_float cost,salvage_value,life;
1089
1085
 
1141
1137
};
1142
1138
 
1143
1139
static GnmValue *
1144
 
gnumeric_syd (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1140
gnumeric_syd (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1145
1141
{
1146
1142
        gnm_float cost, salvage_value, life, period;
1147
1143
 
1183
1179
};
1184
1180
 
1185
1181
static GnmValue *
1186
 
gnumeric_dollarde (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1182
gnumeric_dollarde (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1187
1183
{
1188
1184
        gnm_float x = value_get_as_float (argv[0]);
1189
1185
        gnm_float f = gnm_floor (value_get_as_float (argv[1]));
1239
1235
};
1240
1236
 
1241
1237
static GnmValue *
1242
 
gnumeric_dollarfr (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1238
gnumeric_dollarfr (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1243
1239
{
1244
1240
        gnm_float x = value_get_as_float (argv[0]);
1245
1241
        gnm_float f = gnm_floor (value_get_as_float (argv[1]));
1290
1286
};
1291
1287
 
1292
1288
static GnmValue *
1293
 
gnumeric_mirr (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1289
gnumeric_mirr (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1294
1290
{
1295
1291
        gnm_float frate, rrate, npv_neg, npv_pos;
1296
1292
        gnm_float *values = NULL, res;
1361
1357
};
1362
1358
 
1363
1359
static GnmValue *
1364
 
gnumeric_tbilleq (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1360
gnumeric_tbilleq (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1365
1361
{
1366
1362
        gnm_float settlement, maturity, discount;
1367
1363
        gnm_float dsm, divisor;
1411
1407
};
1412
1408
 
1413
1409
static GnmValue *
1414
 
gnumeric_tbillprice (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1410
gnumeric_tbillprice (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1415
1411
{
1416
1412
        gnm_float settlement, maturity, discount;
1417
1413
        gnm_float res, dsm;
1457
1453
};
1458
1454
 
1459
1455
static GnmValue *
1460
 
gnumeric_tbillyield (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1456
gnumeric_tbillyield (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1461
1457
{
1462
1458
        gnm_float settlement, maturity, pr;
1463
1459
        gnm_float res, dsm;
1487
1483
           "@DESCRIPTION="
1488
1484
           "RATE calculates the rate of an investment.\n"
1489
1485
           "\n"
 
1486
           "* If @pmt is ommitted it defaults to 0\n"
1490
1487
           "* If @nper <= 0, RATE returns #NUM! error.\n"
1491
1488
           "* If @type != 0 and @type != 1, RATE returns #VALUE! error.\n"
1492
1489
           "\n"
1534
1531
 
1535
1532
 
1536
1533
static GnmValue *
1537
 
gnumeric_rate (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1534
gnumeric_rate (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1538
1535
{
1539
1536
        GoalSeekData    data;
1540
1537
        GoalSeekStatus  status;
1542
1539
        gnm_float      rate0;
1543
1540
 
1544
1541
        udata.nper = value_get_as_int (argv[0]);
1545
 
        udata.pmt  = value_get_as_float (argv[1]);
 
1542
        /* YES ZERO, it's sick but it's XL compatible */
 
1543
        udata.pmt  = argv[1] ? value_get_as_float (argv[1]) : 0.0;
1546
1544
        udata.pv   = value_get_as_float (argv[2]);
1547
1545
        udata.fv   = argv[3] ? value_get_as_float (argv[3]) : 0.0;
1548
1546
        udata.type = value_get_paytype (argv[4]);
1668
1666
}
1669
1667
 
1670
1668
static GnmValue *
1671
 
gnumeric_irr (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1669
gnumeric_irr (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1672
1670
{
1673
1671
        GoalSeekData    data;
1674
1672
        GoalSeekStatus  status;
1751
1749
};
1752
1750
 
1753
1751
static GnmValue *
1754
 
gnumeric_pv (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1752
gnumeric_pv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1755
1753
{
1756
1754
        gnm_float rate = value_get_as_float (argv[0]);
1757
1755
        gnm_float nper = value_get_as_float (argv[1]);
1815
1813
}
1816
1814
 
1817
1815
static GnmValue *
1818
 
gnumeric_npv (FunctionEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
 
1816
gnumeric_npv (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
1819
1817
{
1820
1818
        return float_range_function (argc, argv, ei,
1821
1819
                                     range_npv,
1848
1846
};
1849
1847
 
1850
1848
static GnmValue *
1851
 
gnumeric_xnpv (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1849
gnumeric_xnpv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1852
1850
{
1853
1851
        gnm_float rate, *payments = NULL, *dates = NULL;
1854
1852
        gnm_float sum;
1953
1951
}
1954
1952
 
1955
1953
static GnmValue *
1956
 
gnumeric_xirr (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
1954
gnumeric_xirr (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
1957
1955
{
1958
1956
        GoalSeekData    data;
1959
1957
        GoalSeekStatus  status;
2032
2030
};
2033
2031
 
2034
2032
static GnmValue *
2035
 
gnumeric_fv (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2033
gnumeric_fv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2036
2034
{
2037
2035
        gnm_float rate = value_get_as_float (argv[0]);
2038
2036
        gnm_float nper = value_get_as_float (argv[1]);
2080
2078
};
2081
2079
 
2082
2080
static GnmValue *
2083
 
gnumeric_pmt (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2081
gnumeric_pmt (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2084
2082
{
2085
2083
        gnm_float rate = value_get_as_float (argv[0]);
2086
2084
        gnm_float nper = value_get_as_float (argv[1]);
2124
2122
};
2125
2123
 
2126
2124
static GnmValue *
2127
 
gnumeric_ipmt (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2125
gnumeric_ipmt (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2128
2126
{
2129
2127
        gnm_float rate = value_get_as_float (argv[0]);
2130
2128
        gnm_float per  = value_get_as_float (argv[1]);
2143
2141
        if (!is_valid_paytype (type))
2144
2142
                return value_new_error_VALUE (ei->pos);
2145
2143
 
2146
 
        {
2147
 
                gnm_float pmt = calculate_pmt (rate, nper, pv, fv, type);
2148
 
                gnm_float ipmt = calculate_interest_part (pv, pmt, rate, per - 1);
2149
 
 
2150
 
                return value_new_float (ipmt);
2151
 
        }
 
2144
        return value_new_float (calculate_ipmt (rate, per, nper, pv, fv, type));
2152
2145
}
2153
2146
 
2154
2147
/***************************************************************************/
2181
2174
};
2182
2175
 
2183
2176
static GnmValue *
2184
 
gnumeric_ppmt (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2177
gnumeric_ppmt (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2185
2178
{
2186
2179
        gnm_float rate = value_get_as_float (argv[0]);
2187
2180
        gnm_float per  = value_get_as_float (argv[1]);
2202
2195
 
2203
2196
        {
2204
2197
                gnm_float pmt = calculate_pmt (rate, nper, pv, fv, type);
2205
 
                gnm_float ipmt = calculate_interest_part (pv, pmt, rate, per - 1);
 
2198
                gnm_float ipmt = calculate_ipmt (rate, per, nper, pv, fv, type);
2206
2199
                return value_new_float (pmt - ipmt);
2207
2200
        }
2208
2201
}
2240
2233
};
2241
2234
 
2242
2235
static GnmValue *
2243
 
gnumeric_nper (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2236
gnumeric_nper (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2244
2237
{
2245
2238
        gnm_float tmp;
2246
2239
 
2303
2296
};
2304
2297
 
2305
2298
static GnmValue *
2306
 
gnumeric_duration (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2299
gnumeric_duration (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2307
2300
{
2308
2301
        GDate     nSettle, nMat;
2309
2302
        gnm_float fCoup, fYield;
2354
2347
};
2355
2348
 
2356
2349
static GnmValue *
2357
 
gnumeric_g_duration (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2350
gnumeric_g_duration (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2358
2351
{
2359
2352
        gnm_float rate, pv, fv;
2360
2353
 
2397
2390
};
2398
2391
 
2399
2392
static GnmValue *
2400
 
gnumeric_fvschedule (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2393
gnumeric_fvschedule (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2401
2394
{
2402
2395
        gnm_float pv, *schedule = NULL;
2403
2396
        GnmValue *result = NULL;
2519
2512
}
2520
2513
 
2521
2514
static GnmValue *
2522
 
gnumeric_euro (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2515
gnumeric_euro (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2523
2516
{
2524
2517
        char const *str = value_peek_string (argv[0]);
2525
2518
        gnm_float v    = one_euro (str);
2568
2561
};
2569
2562
 
2570
2563
static GnmValue *
2571
 
gnumeric_euroconvert (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2564
gnumeric_euroconvert (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2572
2565
{
2573
2566
        gnm_float c1 = one_euro (value_peek_string (argv[1]));
2574
2567
        gnm_float c2 = one_euro (value_peek_string (argv[2]));
2614
2607
};
2615
2608
 
2616
2609
static GnmValue *
2617
 
gnumeric_price (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2610
gnumeric_price (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2618
2611
{
2619
2612
        GDate      settlement, maturity;
2620
2613
        /* gnm_float a, d, e, n; */
2698
2691
 
2699
2692
 
2700
2693
static GnmValue *
2701
 
gnumeric_yield (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2694
gnumeric_yield (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2702
2695
{
2703
2696
        gnm_float n;
2704
2697
        gnumeric_yield_t udata;
2725
2718
 
2726
2719
        n = coupnum (&udata.settlement, &udata.maturity, &udata.conv);
2727
2720
        if (n <= 1.0) {
2728
 
                gnm_float a = coupdaybs (&udata.settlement, &udata.maturity,
2729
 
                                         &udata.conv);
2730
 
                gnm_float d = coupdaysnc (&udata.settlement, &udata.maturity,
2731
 
                                         &udata.conv);
2732
 
                gnm_float e = coupdays (&udata.settlement, &udata.maturity,
 
2721
                gnm_float a = go_coupdaybs (&udata.settlement, &udata.maturity,
 
2722
                                         &udata.conv);
 
2723
                gnm_float d = go_coupdaysnc (&udata.settlement, &udata.maturity,
 
2724
                                         &udata.conv);
 
2725
                gnm_float e = go_coupdays (&udata.settlement, &udata.maturity,
2733
2726
                                         &udata.conv);
2734
2727
 
2735
2728
                gnm_float coeff = udata.conv.freq * e / d;
2805
2798
};
2806
2799
 
2807
2800
static GnmValue *
2808
 
gnumeric_yielddisc (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2801
gnumeric_yielddisc (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2809
2802
{
2810
2803
        GDate     settlement, maturity;
2811
2804
        gnm_float fPrice, fRedemp;
2868
2861
};
2869
2862
 
2870
2863
static GnmValue *
2871
 
gnumeric_yieldmat (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
2864
gnumeric_yieldmat (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
2872
2865
{
2873
2866
        GDate     nSettle, nMat, nIssue;
2874
2867
        gnm_float fRate, fPrice;
2932
2925
        GDate next_coupon, prev_coupon;
2933
2926
        gnm_float res;
2934
2927
 
2935
 
        coup_cd (&next_coupon, d1, d3, conv->freq, conv->eom, TRUE);
2936
 
        coup_cd (&prev_coupon, d1, d3, conv->freq, conv->eom, FALSE);
 
2928
        go_coup_cd (&next_coupon, d1, d3, conv->freq, conv->eom, TRUE);
 
2929
        go_coup_cd (&prev_coupon, d1, d3, conv->freq, conv->eom, FALSE);
2937
2930
 
2938
2931
        if (g_date_compare (&next_coupon, d2) >= 0)
2939
2932
                return days_between_basis (d1, d2, conv->basis) /
2940
 
                        coupdays (&prev_coupon, &next_coupon, conv);
 
2933
                        go_coupdays (&prev_coupon, &next_coupon, conv);
2941
2934
 
2942
2935
        res = days_between_basis (d1, &next_coupon, conv->basis) /
2943
 
                coupdays (&prev_coupon, &next_coupon, conv);
 
2936
                go_coupdays (&prev_coupon, &next_coupon, conv);
2944
2937
        while (1) {
2945
2938
                prev_coupon = next_coupon;
2946
2939
                g_date_add_months (&next_coupon, 12 / conv->freq);
2947
2940
                if (g_date_compare (&next_coupon, d2) >= 0) {
2948
2941
                        res += days_between_basis (&prev_coupon, d2, conv->basis) /
2949
 
                                coupdays (&prev_coupon, &next_coupon, conv);
 
2942
                                go_coupdays (&prev_coupon, &next_coupon, conv);
2950
2943
                        return res;
2951
2944
                }
2952
2945
                res += 1;
2963
2956
        gnm_float a = days_between_basis (issue, settlement, conv->basis);
2964
2957
        gnm_float ds = days_between_basis (settlement, first_coupon, conv->basis);
2965
2958
        gnm_float df = days_between_basis (issue, first_coupon, conv->basis);
2966
 
        gnm_float e = coupdays (settlement, maturity, conv);
 
2959
        gnm_float e = go_coupdays (settlement, maturity, conv);
2967
2960
        int n = (int)coupnum (settlement, maturity, conv);
2968
2961
        gnm_float scale = 100.0 * rate / conv->freq;
2969
2962
        gnm_float f = 1.0 + yield / conv->freq;
2987
2980
                                g_date_add_months (&d, 12 / conv->freq);
2988
2981
                                if (g_date_compare (&d, maturity) >= 0) {
2989
2982
                                        n += (int)gnm_ceil (days_between_basis (&prev_date, maturity, conv->basis) /
2990
 
                                                            coupdays (&prev_date, &d, conv))
 
2983
                                                            go_coupdays (&prev_date, &d, conv))
2991
2984
                                                + 1;
2992
2985
                                        break;
2993
2986
                                }
3010
3003
 
3011
3004
 
3012
3005
static GnmValue *
3013
 
gnumeric_oddfprice (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3006
gnumeric_oddfprice (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3014
3007
{
3015
3008
        GDate     settlement, maturity, issue, first_coupon;
3016
3009
        gnm_float rate, yield, redemption;
3102
3095
}
3103
3096
 
3104
3097
static GnmValue *
3105
 
gnumeric_oddfyield (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3098
gnumeric_oddfyield (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3106
3099
{
3107
3100
        struct gnumeric_oddyield_f udata;
3108
3101
        GoalSeekData data;
3217
3210
 
3218
3211
 
3219
3212
static GnmValue *
3220
 
gnumeric_oddlprice (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3213
gnumeric_oddlprice (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3221
3214
{
3222
3215
        GDate     settlement, maturity, last_interest;
3223
3216
        gnm_float rate, yield, redemption;
3311
3304
 
3312
3305
 
3313
3306
static GnmValue *
3314
 
gnumeric_oddlyield (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3307
gnumeric_oddlyield (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3315
3308
{
3316
3309
        GDate     settlement, maturity, last_interest;
3317
3310
        gnm_float rate, price, redemption;
3387
3380
 
3388
3381
 
3389
3382
static GnmValue *
3390
 
gnumeric_amordegrc (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3383
gnumeric_amordegrc (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3391
3384
{
3392
3385
        GDate     nDate, nFirstPer;
3393
3386
        gnm_float fRestVal, fRate, fCost;
3451
3444
};
3452
3445
 
3453
3446
static GnmValue *
3454
 
gnumeric_amorlinc (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3447
gnumeric_amorlinc (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3455
3448
{
3456
3449
        GDate     nDate, nFirstPer;
3457
3450
        gnm_float fCost, fRestVal, fRate;
3518
3511
};
3519
3512
 
3520
3513
static GnmValue *
3521
 
gnumeric_coupdaybs (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3514
gnumeric_coupdaybs (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3522
3515
{
3523
 
        return func_coup (ei, argv, coupdaybs);
 
3516
        return func_coup (ei, argv, go_coupdaybs);
3524
3517
}
3525
3518
 
3526
3519
/***************************************************************************/
3567
3560
};
3568
3561
 
3569
3562
static GnmValue *
3570
 
gnumeric_coupdays (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3563
gnumeric_coupdays (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3571
3564
{
3572
 
        return func_coup (ei, argv, coupdays);
 
3565
        return func_coup (ei, argv, go_coupdays);
3573
3566
}
3574
3567
 
3575
3568
/***************************************************************************/
3615
3608
};
3616
3609
 
3617
3610
static GnmValue *
3618
 
gnumeric_coupdaysnc (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3611
gnumeric_coupdaysnc (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3619
3612
{
3620
 
        return func_coup (ei, argv, coupdaysnc);
 
3613
        return func_coup (ei, argv, go_coupdaysnc);
3621
3614
}
3622
3615
 
3623
3616
/***************************************************************************/
3662
3655
};
3663
3656
 
3664
3657
static GnmValue *
3665
 
gnumeric_coupncd (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3658
gnumeric_coupncd (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3666
3659
{
3667
3660
        GnmValue *res = func_coup (ei, argv, coupncd);
3668
3661
        value_set_fmt (res, go_format_default_date ());
3712
3705
};
3713
3706
 
3714
3707
static GnmValue *
3715
 
gnumeric_couppcd (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3708
gnumeric_couppcd (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3716
3709
{
3717
3710
        GnmValue *res = func_coup (ei, argv, couppcd);
3718
3711
        value_set_fmt (res, go_format_default_date ());
3758
3751
};
3759
3752
 
3760
3753
static GnmValue *
3761
 
gnumeric_coupnum (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3754
gnumeric_coupnum (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3762
3755
{
3763
3756
        return func_coup (ei, argv, coupnum);
3764
3757
}
3789
3782
};
3790
3783
 
3791
3784
static GnmValue *
3792
 
gnumeric_cumipmt (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3785
gnumeric_cumipmt (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3793
3786
{
3794
3787
        gnm_float fRate, fVal;
3795
3788
        gint       nNumPeriods, nStartPer, nEndPer, nPayType;
3842
3835
};
3843
3836
 
3844
3837
static GnmValue *
3845
 
gnumeric_cumprinc (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3838
gnumeric_cumprinc (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3846
3839
{
3847
3840
        gnm_float fRate, fVal;
3848
3841
        gint       nNumPeriods, nStartPer, nEndPer, nPayType;
3903
3896
};
3904
3897
 
3905
3898
static GnmValue *
3906
 
gnumeric_mduration (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3899
gnumeric_mduration (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3907
3900
{
3908
3901
        GDate     nSettle, nMat;
3909
3902
        gnm_float fCoup, fYield;
3955
3948
};
3956
3949
 
3957
3950
static GnmValue *
3958
 
gnumeric_vdb (FunctionEvalInfo *ei, GnmValue const * const *argv)
 
3951
gnumeric_vdb (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
3959
3952
{
3960
3953
        gnm_float cost, salvage, life, factor, start_period, end_period;
3961
3954
        gboolean   bflag;