2013-04-06 239 views
4

任何人都可以告诉我这个MS Excel函数背后的数学。我在PHP中编写代码,我无法使用Excel来计算这些,但我仍然需要相同的结果。在Excel中的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)但不从其减去,它增加了两个值,我无法理解为什么呢?

预先感谢您

+0

你是什么意思(= E11-E12)不是减法?它不适用于Excel?它不适用于PHP?请显示详细信息 – 2013-04-06 21:00:22

回答

2

我还没有使用它,但你可能要检查出PHPExcel Library。 Excel和PHP的不同之处在于,您需要使用像链接到的库或编写函数来手动执行所有这些数学运算。就你而言,似乎处理Excel文件可能是实现你的目标的最简单的方法。

+0

感谢您的回复。 还有一个问题 - 我使用(= E11-E12),但它并没有减少,它增加了两个值,我不明白为什么? – 2013-04-06 20:25:38

+0

它可能假定' - '字符表示列E11通过E12而不是E11减去E12。我不能太确定,因为我没有真正使用excel。 – 2013-04-07 00:31:14

+0

一旦你编写了你自己的函数,你就可以使用这个Excel CUMIPMT计算器http://thinkanddone.co.uk/en-gb/excel_cumipmt_calculator比较并确认你的结果。html – 2013-04-07 04:50:02

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)问题。尝试将其更改为=E11-E12。如果E12是一个负数,你必须记住负号会分配。

编辑: 至于您的意见,我希望这个链接可以帮助

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

+0

感谢您的回复,但我的问题仍未得到解答。我需要PHP中CUMIPMT函数背后的代码逻辑。 我试过,但没有工作 - P =本金(初始投资) R =年利率(以十进制) N =每年的利息是复利次数 T =年数 A =在时间t之后的量n = 4(不是1/4),t = 6,其中P = 1500,r = 4.3/100 = 0.043, A = P(1 + r / – 2013-04-07 08:21:37

0

我知道这个线程是老了,但我的工作今天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,但它应该是一个容易的任务转换。