Commit c219bf4a authored by jpekka's avatar jpekka
Browse files

Implemented CUMIPMT().

parent 04811f9a
2002-07-07 Jukka Pekka <jiivonen@hutcs.cs.hut.fi>
* functions (gnumeric_cumprinc): Implemented.
* functions (gnumeric_cumprinc, gnumeric_cumipmt): Implemented.
* sc-fin.c (GetRmz,GetZw,get_cumprinc): Added.
* sc-fin.c (GetRmz,GetZw,get_cumprinc,get_cumipmt): Added.
2002-07-07 Jukka Pekka <jiivonen@hutcs.cs.hut.fi>
......
......@@ -3305,7 +3305,29 @@ static const char *help_cumipmt = {
static Value *
gnumeric_cumipmt (FunctionEvalInfo *ei, Value **argv)
{
return value_new_error (ei->pos, "#UNIMPLEMENTED!");
gnum_float fRate, fVal;
gint nNumPeriods, nStartPer, nEndPer, nPayType;
Value *result;
fRate = value_get_as_float (argv[0]);
nNumPeriods = value_get_as_int (argv[1]);
fVal = value_get_as_float (argv[2]);
nStartPer = value_get_as_int (argv[3]);
nEndPer = value_get_as_int (argv[4]);
nPayType = value_get_as_int (argv[5]);
if ( nStartPer < 1 || nEndPer < nStartPer || fRate <= 0
|| nEndPer > nNumPeriods || nNumPeriods <= 0
|| fVal <= 0 || (nPayType != 0 && nPayType != 1) ) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
result = get_cumipmt (fRate, nNumPeriods, fVal, nStartPer, nEndPer,
nPayType);
out:
return result;
}
/***************************************************************************/
......
......@@ -410,3 +410,35 @@ Value * get_cumprinc (gnum_float fRate, gint nNumPeriods, gnum_float fVal,
}
/***************************************************************************/
Value * get_cumipmt (gnum_float fRate, gint nNumPeriods, gnum_float fVal,
gint nStart, gint nEnd, gint nPayType)
{
gnum_float fRmz, fZinsZ;
gint i;
fRmz = GetRmz ( fRate, nNumPeriods, fVal, 0.0, nPayType );
fZinsZ = 0.0;
if ( nStart == 1 ) {
if ( nPayType <= 0 )
fZinsZ = -fVal;
nStart++;
}
for ( i = nStart ; i <= nEnd ; i++ ) {
if ( nPayType > 0 )
fZinsZ += GetZw ( fRate, ( i - 2 ), fRmz, fVal, 1 )
- fRmz;
else
fZinsZ += GetZw ( fRate, ( i - 1 ), fRmz, fVal, 0 );
}
fZinsZ *= fRate;
return value_new_float ( fZinsZ );
}
/***************************************************************************/
......@@ -23,6 +23,8 @@ Value * get_duration (GDate *nSettle, GDate *nMat, gnum_float fCoup,
gnum_float fNumOfCoups);
Value * get_cumprinc (gnum_float fRate, gint nNumPeriods, gnum_float fVal,
gint nStartPer, gint nEndPer, gint nPayType);
Value * get_cumipmt (gnum_float fRate, gint nNumPeriods, gnum_float fVal,
gint nStartPer, gint nEndPer, gint nPayType);
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment