5

谁能告诉我这个 MS Excel 函数背后的数学原理。我正在用 php 编写代码,我无法使用 Excel 来计算这些,但我仍然需要相同的结果。

CUMIPMT(rate,nper,pv,start_period,end_period,type) Returns the cumulative
interest paid on a loan between start_period and end_period.

我的 Excel 函数 -

=IF($C$33<0,CUMIPMT($C$36/12,$C$35,-$C$33,$C$34,$C$34+11,0),-CUMIPMT($C$36/12,$C$35,$C$33,$C$34,$C$34+11,0))

还有一个问题 - 我使用(=E11-E12)了但它没有减去,它增加了两个值,我不明白为什么?

先感谢您

4

3 回答 3

2

我没用过,但你可能想看看PHPExcel Library。Excel 和 PHP 完全不同,您要么需要使用我链接到的库,要么需要编写函数来手动完成所有这些数学运算。就您而言,处理 excel 文件似乎是实现目标的最简单方法。

于 2013-04-06T20:24:04.293 回答
1

我知道这个线程很旧,但是我今天正在将 Excel 电子表格转换为 Objective-c,并且也需要对此的答案。这是我最终写的解决方案:

double cumipmt(double rate, int nper, double pv, int start_period, int end_period, BOOL type)
{
    double cumipmt = 0;
    double thePmt = pmt(rate, nper, pv, 0, type);
    double endValue = pv;

    if (type==0)
{
    for (int i=1; i<=end_period; i++)
    {
        double beginning = endValue;
        double interest = beginning * rate;
        endValue = beginning + interest + thePmt;

        if (i>=start_period)
        {
            cumipmt += interest;
        }
    }
}
else
{
    for (int i=1; i<end_period; i++)
    {
        double beginning = endValue + thePmt;
        double interest = beginning * rate;
        endValue = beginning + interest + thePmt;

        if (i>=start_period)
        {
            cumipmt += interest;
        }
    }
}

    return cumipmt;
}

double pvFactor(double rate, int nper)
{
    return (1 / fvFactor(rate, nper));
}

double fvFactor(double rate, int nper)
{
    return pow(1+rate,nper);
}

double annuityPvFactor(double rate, int nper, bool type)
{
    if (rate == 0) {
        return nper;
    }
    else {
        return (1 + rate * type) * (1 - pvFactor(rate, nper)) / rate;
    }

}

double pmt(double rate, int nper, double pv, double fv, bool type)
{
    return (-1 * (pv + fv + pvFactor(rate, nper))) / (annuityPvFactor(rate, nper, type));
}

我知道这不在 PHP 中,但转换起来应该很容易。

于 2014-12-19T19:29:10.167 回答
0

IF( condition, [value_if_true], [value_if_false] )

条件是您要测试的值。

value_if_true是可选的。如果条件评估为 TRUE,则返回该值。

value_if_false是可选的。如果条件评估为 FALSE,则返回该值。

所以基本上,它是这么说的

if ($C$33 < 0) {
    // if the condition is TRUE
    return CUMIPMT($C$36 / 12, $C$35, -$C$33, $C$34, $C$34 + 11, 0);
} else {
    // if the condition is FALSE
    return -CUMIPMT($C$36 / 12, $C$35, $C$33, $C$34, $C$34 + 11, 0);
}

关于你的(=E11-E12)问题。尝试将其更改为 this =E11-E12。如果 E12 是负数,您必须记住减号将分配。

编辑: 关于你的评论,我希望这个链接有帮助

http://www.excelforum.com/excel-programming-vba-macros/515109-need-longhand-formulas-for-cumipmt-and-cumprinc-functions-in-excel.html

于 2013-04-06T20:27:59.803 回答