2013-04-06 139 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,但它應該是一個容易的任務轉換。