Commit 4715611d authored by Jukka Pekka's avatar Jukka Pekka Committed by jpekka
Browse files

Implemented. Thanks for OO, read the comment in sc-fin.c.

2002-07-06  Jukka Pekka  <jiivonen@hutcs.cs.hut.fi>

        * functions.c (gnumeric_amordegrc, gnumeric_amorlinc,
        gnumeric_oddlprice, gnumeric_oddlyield, gnumeric_yieldmat,
        gnumeric_yielddisc): Implemented. Thanks for OO, read the comment
        in sc-fin.c.

        * sc-fin.[ch], Makefile.am: Added new file.
parent 92851904
2002-07-06 Jukka Pekka <jiivonen@hutcs.cs.hut.fi>
* functions.c (gnumeric_amordegrc, gnumeric_amorlinc,
gnumeric_oddlprice, gnumeric_oddlyield, gnumeric_yieldmat,
gnumeric_yielddisc): Implemented. Thanks for OO, read the comment
in sc-fin.c.
* sc-fin.[ch], Makefile.am: Added new file.
2002-06-14 Jody Goldberg <jody@gnome.org>
* functions.c (gnumeric_euro) : add drachma.
......
......@@ -7,7 +7,7 @@ gnumeric_plugin_fnfinancialdir = $(gnumeric_plugindir)/fn-financial
xmldir = $(gnumeric_plugin_fnfinancialdir)
gnumeric_plugin_fnfinancial_LTLIBRARIES = plugin.la
plugin_la_LDFLAGS = -module -avoid-version
plugin_la_SOURCES = functions.c
plugin_la_SOURCES = functions.c sc-fin.c sc-fin.h
xml_in_files = plugin.xml.in
xml_DATA = $(xml_in_files:.xml.in=.xml)
......
......@@ -43,6 +43,7 @@
#include "plugin.h"
#include "plugin-util.h"
#include "module-plugin-defs.h"
#include "sc-fin.h"
GNUMERIC_MODULE_PLUGIN_INFO_DECL;
......@@ -259,7 +260,8 @@ days_monthly_basis (Value *issue_date, Value *maturity_date, int basis)
* and maturity dates.
*/
static gnum_float
coupnum (GDate *settlement, GDate *maturity, int freq, basis_t basis, gboolean eom)
coupnum (GDate *settlement, GDate *maturity, int freq, basis_t basis,
gboolean eom)
{
int months;
GDate this_coupondate;
......@@ -283,7 +285,8 @@ coupnum (GDate *settlement, GDate *maturity, int freq, basis_t basis, gboolean e
}
static gnum_float
couppcd (GDate *settlement, GDate *maturity, int freq, basis_t basis, gboolean eom)
couppcd (GDate *settlement, GDate *maturity, int freq, basis_t basis,
gboolean eom)
{
GDate *date;
int serial_date;
......@@ -296,7 +299,8 @@ couppcd (GDate *settlement, GDate *maturity, int freq, basis_t basis, gboolean
}
static gnum_float
coupncd (GDate *settlement, GDate *maturity, int freq, basis_t basis, gboolean eom)
coupncd (GDate *settlement, GDate *maturity, int freq, basis_t basis,
gboolean eom)
{
GDate *date;
int serial_date;
......@@ -319,7 +323,7 @@ coupncd (GDate *settlement, GDate *maturity, int freq, basis_t basis, gboolean
static Value *
func_coup (FunctionEvalInfo *ei, Value **argv,
gnum_float (coup_fn)(GDate *settlement, GDate *maturity,
int freq, basis_t basis, gboolean eom))
int freq, basis_t basis, gboolean eom))
{
GDate *settlement;
GDate *maturity;
......@@ -345,7 +349,8 @@ func_coup (FunctionEvalInfo *ei, Value **argv,
goto out;
}
result = value_new_float (coup_fn (settlement, maturity, freq, basis, eom));
result = value_new_float (coup_fn (settlement, maturity, freq, basis,
eom));
out:
datetime_g_free (settlement);
......@@ -2489,7 +2494,29 @@ static const char *help_yielddisc = {
static Value *
gnumeric_yielddisc (FunctionEvalInfo *ei, Value **argv)
{
return value_new_error (ei->pos, "#UNIMPLEMENTED!");
GDate *nSettle, *nMat;
gnum_float fPrice, fRedemp;
gint nBase;
Value *result;
nSettle = datetime_value_to_g (argv[0]);
nMat = datetime_value_to_g (argv[1]);
fPrice = value_get_as_float (argv[2]);
fRedemp = value_get_as_float (argv[3]);
nBase = argv[4] ? value_get_as_int (argv[4]) : 0;
if (nBase < 0 || nBase > 4 || nSettle == NULL || nMat == NULL) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
result = get_yielddisc (nSettle, nMat, fPrice, fRedemp, nBase);
out:
datetime_g_free (nSettle);
datetime_g_free (nMat);
return result;
}
/***************************************************************************/
......@@ -2526,7 +2553,32 @@ static const char *help_yieldmat = {
static Value *
gnumeric_yieldmat (FunctionEvalInfo *ei, Value **argv)
{
return value_new_error (ei->pos, "#UNIMPLEMENTED!");
GDate *nSettle, *nMat, *nIssue;
gnum_float fRate, fPrice;
gint nBase;
Value *result;
nSettle = datetime_value_to_g (argv[0]);
nMat = datetime_value_to_g (argv[1]);
nIssue = datetime_value_to_g (argv[2]);
fRate = value_get_as_float (argv[3]);
fPrice = value_get_as_float (argv[4]);
nBase = argv[5] ? value_get_as_int (argv[5]) : 0;
if (nBase < 0 || nBase > 4 || fRate < 0 || nSettle == NULL ||
nMat == NULL || nIssue == NULL) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
result = get_yieldmat (nSettle, nMat, nIssue, fRate, fPrice, nBase);
out:
datetime_g_free (nSettle);
datetime_g_free (nMat);
datetime_g_free (nIssue);
return result;
}
/***************************************************************************/
......@@ -2615,11 +2667,13 @@ gnumeric_oddfprice (FunctionEvalInfo *ei, Value **argv)
/* Odd short first coupon */
term1 = redemption / powgnum (1.0 + yield / freq, n - 1.0 + ds / e);
term2 = (100.0 * rate / freq * df / e) / powgnum (1.0 + yield / freq, ds / e);;
term2 = (100.0 * rate / freq * df / e) / powgnum (1.0 + yield / freq,
ds / e);;
last_term = 100.0 * rate / freq * a / e;
sum = 0;
for (k = 1; k < n; k++)
sum += (100.0 * rate / freq) / powgnum (1 + yield / freq, k + ds / e);
sum += (100.0 * rate / freq) / powgnum (1 + yield / freq,
k + ds / e);
result = value_new_float (term1 + term2 + sum - last_term);
......@@ -2703,7 +2757,36 @@ static const char *help_oddlprice = {
static Value *
gnumeric_oddlprice (FunctionEvalInfo *ei, Value **argv)
{
return value_new_error (ei->pos, "#UNIMPLEMENTED!");
GDate *nSettle, *nMat, *nLastCoup;
gnum_float fRate, fYield, fRedemp;
gint nFreq, nBase;
Value *result;
nSettle = datetime_value_to_g (argv[0]);
nMat = datetime_value_to_g (argv[1]);
nLastCoup = datetime_value_to_g (argv[2]);
fRate = value_get_as_float (argv[3]);
fYield = value_get_as_float (argv[4]);
fRedemp = value_get_as_float (argv[5]);
nFreq = value_get_as_int (argv[6]);
nBase = argv[7] ? value_get_as_int (argv[7]) : 0;
if (nBase < 0 || nBase > 4 || fRate < 0 || nSettle == NULL ||
nMat == NULL || nLastCoup == NULL ||
(nFreq != 1 && nFreq != 2 && nFreq != 4) ) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
result = get_oddlprice (nSettle, nMat, nLastCoup, fRate, fYield,
fRedemp, nFreq, nBase);
out:
datetime_g_free (nSettle);
datetime_g_free (nMat);
datetime_g_free (nLastCoup);
return result;
}
/***************************************************************************/
......@@ -2740,7 +2823,36 @@ static const char *help_oddlyield = {
static Value *
gnumeric_oddlyield (FunctionEvalInfo *ei, Value **argv)
{
return value_new_error (ei->pos, "#UNIMPLEMENTED!");
GDate *nSettle, *nMat, *nLastCoup;
gnum_float fRate, fPrice, fRedemp;
gint nFreq, nBase;
Value *result;
nSettle = datetime_value_to_g (argv[0]);
nMat = datetime_value_to_g (argv[1]);
nLastCoup = datetime_value_to_g (argv[2]);
fRate = value_get_as_float (argv[3]);
fPrice = value_get_as_float (argv[4]);
fRedemp = value_get_as_float (argv[5]);
nFreq = value_get_as_int (argv[6]);
nBase = argv[7] ? value_get_as_int (argv[7]) : 0;
if (nBase < 0 || nBase > 4 || fRate < 0 || nSettle == NULL ||
nMat == NULL || nLastCoup == NULL ||
(nFreq != 1 && nFreq != 2 && nFreq != 4) ) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
result = get_oddlyield (nSettle, nMat, nLastCoup, fRate, fPrice,
fRedemp, nFreq, nBase);
out:
datetime_g_free (nSettle);
datetime_g_free (nMat);
datetime_g_free (nLastCoup);
return result;
}
/***************************************************************************/
......@@ -2771,10 +2883,37 @@ static const char *help_amordegrc = {
"@SEEALSO=")
};
static Value *
gnumeric_amordegrc (FunctionEvalInfo *ei, Value **argv)
{
return value_new_error (ei->pos, "#UNIMPLEMENTED!");
GDate *nDate, *nFirstPer;
gnum_float fRestVal, fRate, fCost;
gint n, nBase, nPer;
Value *result;
fCost = value_get_as_float (argv[0]);
nDate = datetime_value_to_g (argv[1]);
nFirstPer = datetime_value_to_g (argv[2]);
fRestVal = value_get_as_float (argv[3]);
nPer = value_get_as_int (argv[4]);
fRate = value_get_as_float (argv[5]);
nBase = argv[6] ? value_get_as_int (argv[6]) : 0;
if (nBase < 0 || nBase > 4 || fRate < 0 || nDate == NULL ||
nFirstPer == NULL) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
result = get_amordegrc (fCost, nDate, nFirstPer, fRestVal, nPer, fRate,
nBase);
out:
datetime_g_free (nDate);
datetime_g_free (nFirstPer);
return result;
}
/***************************************************************************/
......@@ -2808,7 +2947,33 @@ static const char *help_amorlinc = {
static Value *
gnumeric_amorlinc (FunctionEvalInfo *ei, Value **argv)
{
return value_new_error (ei->pos, "#UNIMPLEMENTED!");
GDate *nDate, *nFirstPer;
gnum_float fCost, fRestVal, fRate;
gint nPer, nBase;
Value *result;
fCost = value_get_as_float (argv[0]);
nDate = datetime_value_to_g (argv[1]);
nFirstPer = datetime_value_to_g (argv[2]);
fRestVal = value_get_as_float (argv[3]);
nPer = value_get_as_int (argv[4]);
fRate = value_get_as_float (argv[5]);
nBase = argv[6] ? value_get_as_int (argv[6]) : 0;
if (nBase < 0 || nBase > 4 || fRate < 0 || nDate == NULL ||
nFirstPer == NULL) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
result = get_amorlinc (fCost, nDate, nFirstPer, fRestVal, nPer, fRate,
nBase);
out:
datetime_g_free (nDate);
datetime_g_free (nFirstPer);
return result;
}
/***************************************************************************/
......@@ -3145,13 +3310,16 @@ gnumeric_vdb (FunctionEvalInfo *ei, Value **argv)
/***************************************************************************/
const ModulePluginFunctionInfo financial_functions[] = {
{ "accrint", "???fff|f", "issue,first_interest,settlement,rate,par,frequency[,basis]",
{ "accrint", "???fff|f",
"issue,first_interest,settlement,rate,par,frequency[,basis]",
&help_accrint, gnumeric_accrint, NULL, NULL, NULL },
{ "accrintm", "??f|ff", "issue,maturity,rate[,par,basis]",
&help_accrintm, gnumeric_accrintm, NULL, NULL, NULL },
{ "amordegrc", "fffffff", "cost,purchase_date,first_period,salvage,period,rate,basis",
{ "amordegrc", "fffffff",
"cost,purchase_date,first_period,salvage,period,rate,basis",
&help_amordegrc, gnumeric_amordegrc, NULL, NULL, NULL },
{ "amorlinc", "fffffff", "cost,purchase_date,first_period,salvage,period,rate,basis",
{ "amorlinc", "fffffff",
"cost,purchase_date,first_period,salvage,period,rate,basis",
&help_amorlinc, gnumeric_amorlinc, NULL, NULL, NULL },
{ "coupdaybs", "fff|fb", "settlement,maturity,frequency[,basis,eom]",
&help_coupdaybs, gnumeric_coupdaybs, NULL, NULL, NULL },
......@@ -3189,7 +3357,8 @@ const ModulePluginFunctionInfo financial_functions[] = {
&help_fv, gnumeric_fv, NULL, NULL, NULL },
{ "fvschedule", "fA", "pv,schedule",
&help_fvschedule, gnumeric_fvschedule, NULL, NULL },
{ "intrate", "??ff|f", "settlement,maturity,investment,redemption[,basis]",
{ "intrate", "??ff|f",
"settlement,maturity,investment,redemption[,basis]",
&help_intrate, gnumeric_intrate, NULL, NULL, NULL },
{ "ipmt", "ffff|ff", "rate,per,nper,pv,fv,type",
&help_ipmt, gnumeric_ipmt, NULL, NULL, NULL },
......@@ -3197,7 +3366,8 @@ const ModulePluginFunctionInfo financial_functions[] = {
&help_irr, gnumeric_irr, NULL, NULL, NULL },
{ "ispmt", "ffff", "rate,per,nper,pv",
&help_ispmt, gnumeric_ispmt, NULL, NULL, NULL },
{ "mduration", "fffff|f", "settlement,maturify,coupon,yield,frequency[,basis]",
{ "mduration", "fffff|f",
"settlement,maturify,coupon,yield,frequency[,basis]",
&help_mduration, gnumeric_mduration, NULL, NULL, NULL },
{ "mirr", "Aff", "values,finance_rate,reinvest_rate",
&help_mirr, gnumeric_mirr, NULL, NULL, NULL },
......@@ -3207,29 +3377,41 @@ const ModulePluginFunctionInfo financial_functions[] = {
&help_nper, gnumeric_nper, NULL, NULL, NULL },
{ "npv", 0, "",
&help_npv, NULL, gnumeric_npv, NULL, NULL },
{ "oddfprice", "????fffff", "settlement,maturity,issue,first_coupon,rate,yld,redemption,frequency,basis",
{ "oddfprice", "????fffff",
"settlement,maturity,issue,first_coupon,rate,yld,redemption,"
"frequency,basis",
&help_oddfprice, gnumeric_oddfprice, NULL, NULL, NULL },
{ "oddfyield", "????fffff", "settlement,maturity,issue,first_coupon,rate,pr,redemption,frequency,basis",
{ "oddfyield", "????fffff",
"settlement,maturity,issue,first_coupon,rate,pr,redemption,"
"frequency,basis",
&help_oddfyield, gnumeric_oddfyield, NULL, NULL, NULL },
{ "oddlprice", "???fffff", "settlement,maturity,last_interest,rate,yld,redemption,frequency,basis",
{ "oddlprice", "???fffff",
"settlement,maturity,last_interest,rate,yld,redemption,"
"frequency,basis",
&help_oddlprice, gnumeric_oddlprice, NULL, NULL, NULL },
{ "oddlyield", "???fffff", "settlement,maturity,last_interest,rate,pr,redemption,frequency,basis",
{ "oddlyield", "???fffff",
"settlement,maturity,last_interest,rate,pr,redemption,"
"frequency,basis",
&help_oddlyield, gnumeric_oddlyield, NULL, NULL, NULL },
{ "pmt", "fff|ff", "rate,nper,pv[,fv,type]",
&help_pmt, gnumeric_pmt, NULL, NULL, NULL },
{ "ppmt", "ffff|ff", "rate,per,nper,pv[,fv,type]",
&help_ppmt, gnumeric_ppmt, NULL, NULL, NULL },
{ "price", "??fff|ff", "settle,mat,rate,yield,redemption_price,frequency,basis",
{ "price", "??fff|ff",
"settle,mat,rate,yield,redemption_price,frequency,basis",
&help_price, gnumeric_price, NULL, NULL, NULL },
{ "pricedisc", "??ff|f", "settlement,maturity,discount,redemption[,basis]",
{ "pricedisc", "??ff|f",
"settlement,maturity,discount,redemption[,basis]",
&help_pricedisc, gnumeric_pricedisc, NULL, NULL, NULL },
{ "pricemat", "???ff|f", "settlement,maturity,issue,rate,yield[,basis]",
{ "pricemat", "???ff|f",
"settlement,maturity,issue,rate,yield[,basis]",
&help_pricemat, gnumeric_pricemat, NULL, NULL, NULL },
{ "pv", "fff|ff", "rate,nper,pmt[,fv,type]",
&help_pv, gnumeric_pv, NULL, NULL, NULL },
{ "rate", "fff|fff", "rate,nper,pmt,fv,type,guess",
&help_rate, gnumeric_rate, NULL, NULL, NULL },
{ "received", "??ff|f", "settlement,maturity,investment,discount[,basis]",
{ "received", "??ff|f",
"settlement,maturity,investment,discount[,basis]",
&help_received, gnumeric_received, NULL, NULL, NULL },
{ "sln", "fff", "cost,salvagevalue,life",
&help_sln, gnumeric_sln, NULL, NULL, NULL },
......@@ -3241,13 +3423,15 @@ const ModulePluginFunctionInfo financial_functions[] = {
&help_tbillprice, gnumeric_tbillprice, NULL, NULL, NULL },
{ "tbillyield", "??f", "settlement,maturity,pr",
&help_tbillyield, gnumeric_tbillyield, NULL, NULL, NULL },
{ "vdb", "fffff|ff", "cost,salvage,life,start_period,end_period[,factor,switch]",
{ "vdb", "fffff|ff",
"cost,salvage,life,start_period,end_period[,factor,switch]",
&help_vdb, gnumeric_vdb, NULL, NULL, NULL },
{ "xirr", "AA|f", "values,dates[,guess]",
&help_xirr, gnumeric_xirr, NULL, NULL, NULL },
{ "xnpv", "fAA", "rate,values,dates",
&help_xnpv, gnumeric_xnpv, NULL, NULL, NULL },
{ "yield", "??fff|ff", "settle,mat,rate,price,redemption_price,frequency,basis",
{ "yield", "??fff|ff",
"settle,mat,rate,price,redemption_price,frequency,basis",
&help_yield, gnumeric_yield, NULL, NULL, NULL },
{ "yielddisc", "??fff", "settlement,maturity,pr,redemption,basis",
&help_yielddisc, gnumeric_yielddisc, NULL, NULL, NULL },
......
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- *//*
* This implementation has been taken from the OpenOffice 1.0, see
* functions in scaddins/source/analysis/analysishelper.cxx. Since
* then there has been made some Gnumeric type system, glib and the C
* language specific changes.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Sun has made the contents of this file available subject to the
* terms of GNU Lesser General Public License Version 2.1 as
* specified in scaddins/source/analysis/analysishelper.cxx revision
* 1.35 available in the OpenOffice package.
*
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include <gnumeric-config.h>
#include <gnumeric.h>
#include <math.h>
#include <value.h>
#include "sc-fin.h"
static gint
GetDiffDate360 (gint nDay1, gint nMonth1, gint nYear1, gint bLeapYear1,
gint nDay2, gint nMonth2, gint nYear2, gboolean bUSAMethod )
{
if ( nDay1 == 31 )
nDay1--;
else if ( bUSAMethod && ( nMonth1 == 2 &&
( nDay1 == 29 ||
( nDay1 == 28 && !bLeapYear1 ) ) ) )
nDay1 = 30;
if ( nDay2 == 31 ) {
if ( bUSAMethod && nDay1 != 30 ) {
/* aDate2 += 1; -> 1.xx.yyyy */
nDay2 = 1;
if ( nMonth2 == 12 ) {
nYear2++;
nMonth2 = 1;
} else
nMonth2++;
} else
nDay2 = 30;
}
return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 *
30 - nYear1 * 360;
}
static void
GetDiffParam (GDate *nStartDate, GDate *nEndDate, gint nMode, gint *rYears,
gint *rDayDiffPart, gint *rDaysInYear)
{
gint nDay1, nDay2;
gint nMonth1, nMonth2;
gint nYear1, nYear2;
gint nYears;
gint nDayDiff, nDaysInYear;
if ( g_date_compare (nStartDate, nEndDate) == 1 ) {
GDate *tmp = nEndDate;
nEndDate = nStartDate;
nStartDate = tmp;
}
nDay1 = g_date_get_day (nStartDate);
nDay2 = g_date_get_day (nEndDate);
nMonth1 = g_date_get_month (nStartDate);
nMonth2 = g_date_get_month (nEndDate);
nYear1 = g_date_get_year (nStartDate);
nYear2 = g_date_get_year (nEndDate);
switch ( nMode ) {
case 0: /* 0=USA (NASD) 30/360 */
case 4: /* 4=Europe 30/360 */
nDaysInYear = 360;
nYears = nYear2 - nYear1;
nDayDiff = GetDiffDate360 ( nDay1, nMonth1, nYear1,
g_date_is_leap_year ( nYear1 ),
nDay2, nMonth2, nYear2,
nMode == 0 )
- nYears * nDaysInYear;
break;
case 1: /* 1=exact/exact */
nYears = nYear2 - nYear1;
nDaysInYear = g_date_is_leap_year ( nYear1 )? 366 : 365;
if ( nYears && ( nMonth1 > nMonth2 ||
( nMonth1 == nMonth2 && nDay1 > nDay2 ) ) )
nYears--;
if ( nYears ) {
GDate *tmp = g_date_new_dmy (nDay1, nMonth1, nYear2);
nDayDiff = g_date_days_between (tmp, nEndDate);
g_free (tmp);
} else
nDayDiff = g_date_days_between (nStartDate, nEndDate);
if ( nDayDiff < 0 )
nDayDiff += nDaysInYear;
break;
case 2: /* 2=exact/360 */
nDaysInYear = 360;
nYears = g_date_days_between ( nStartDate, nEndDate ) /
nDaysInYear; /* ?? */
nDayDiff = g_date_days_between ( nStartDate, nEndDate );
nDayDiff %= nDaysInYear;
break;
case 3: /* 3=exact/365 */
nDaysInYear = 365;
nYears = g_date_days_between ( nStartDate, nEndDate ) /
nDaysInYear; /* ?? */
nDayDiff = g_date_days_between ( nStartDate, nEndDate );
nDayDiff %= nDaysInYear;
break;
default:
break;
}
*rYears = nYears;
*rDayDiffPart = nDayDiff;
*rDaysInYear = nDaysInYear;
}
static gnum_float
GetYearFrac (GDate *nStartDate, GDate *nEndDate, gint nMode)
{
gint nYears, nDayDiff, nDaysInYear;
GetDiffParam ( nStartDate, nEndDate, nMode, &nYears, &nDayDiff,
&nDaysInYear );
return nYears + (gnum_float) nDayDiff / nDaysInYear;
}
Value *
get_amordegrc (gnum_float fCost, GDate *nDate, GDate *nFirstPer,
gnum_float fRestVal, gint nPer, gnum_float fRate,
gint nBase)
{
gint n;
gnum_float fAmorCoeff, fNRate, fRest, fUsePer;
#define Round(x,y) (floorgnum ((x) + 0.5))
fUsePer = 1.0 / fRate;
if (fUsePer < 3.0)
fAmorCoeff = 1.0;
else if (fUsePer < 5.0)
fAmorCoeff = 1.5;
else if (fUsePer <= 6.0)
fAmorCoeff = 2.0;
else
fAmorCoeff = 2.5;
fRate *= fAmorCoeff;
fNRate = Round ( GetYearFrac( nDate, nFirstPer, nBase ) * fRate *
fCost, 0 );
fCost -= fNRate;