Hi
I have an existing Excel spreadsheet that has a calculation I need to replicate in javascript. I am having problems figuring out how to replicate the results returned by the PMT calculation. I have the following on the first line of a spreadsheet...
.0755 | 36 | 50000 | 22448
The PTM calculation I am attempting to replicate, used on the above data, is...
=PMT(A1/12,B1-2,-((A1/12*(C1+(C1*A1/12)))+(C1+(C1*A1/12))),D1,1)
Here's the javascript I am using to replicate the PMT calculation...
var loan_amount = 50000;
// Residual amount calculated at 46.88%
var residual_amount = 50000 - (50000 * 0.4688);
var interest_rate = 7.55 / 100;
var number_of_payments = 34;
var monthly_interest_rate = interest_rate / 12;
// This replicates the calculation happening in argument 2 of the Excel PMT function
var adjusted_loan_amount = (monthly_interest_rate * (loan_amount + (loan_amount * monthly_interest_rate))) + (loan_amount + (loan_amount * monthly_interest_rate));
function PmtCalculation(payments_per_year, number_of_payments, annual_interest_rate, loan_amount)
{
var payment_interest_rate = 1 / (1 + (annual_interest_rate / payments_per_year));
return ((1 - payment_interest_rate) * loan_amount) / (payment_interest_rate * (1 - Math.pow(payment_interest_rate, number_of_payments)));
}
alert(PmtCalculation(12, number_of_payments, interest_rate, adjusted_loan_amount)); // Returns 1658.7648195153983
alert(PmtCalculation(12, number_of_payments, interest_rate, (adjusted_loan_amount - residual_amount))); // Returns 788.6128052627429
IN tyring to replicate the results of the Excel PMT function with the above javascript, I am out considerably. The PMT function returns a value of $1,056.24.
I am trying to figure out why they are producing very different results. If I understand the Excel PMT function correctly, the the third argument is taking a "residual" value, or what should be left over after the end of the term of repayments. If that's the case then the call to the PmtCalculation function should be close in the javascript, but it's not.
So is there something in the second argument of the Excel PMT calculation affecting this, or I am I just going about it the wrong way?
Thanks!
Bookmarks