I know this thread is outdated, but today I was working on converting an Excel spreadsheet to objective-c, and I needed an answer too. Here is the solution in which I ended up writing:
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)); }
I know this is not in PHP, but it should be a simple task to convert.
source share