Last active
November 14, 2016 19:43
-
-
Save phillro/077321020e2af1f0aa3863f11d81e70b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculatePaymentForPrequalifiedOffer(requestedAmount, loanOffer) { | |
function calcPmnt(amount, apr, months){ | |
var interest = apr / 100 / 12; | |
var x = Math.pow(1 + interest, months); | |
var monthly = (requestedAmount*x*interest)/(x-1); | |
return Math.round(monthly*100)/100; | |
} | |
var out = {}; | |
var months | |
switch(loanOffer.termUnit){ | |
case "day" : months = (loanOffer.termLength / 365) * 12; break; | |
case "month" : months = loanOffer.termLength; break; | |
case "year" : months = loanOffer.termLength * 12; break; | |
} | |
//If its a static offer, the rate will be a range, so the monthly payment has to be a range. | |
if(loanOffer.maxApr && loanOffer.minApr){ | |
out.maxMonthlyPayment = calcPmnt(requestedAmount, loanOffer.maxApr, months); | |
out.minMonthlyPayment = calcPmnt(requestedAmount, loanOffer.minApr, months); | |
} else { | |
out.monthlyPayment = calcPmnt(requestedAmount, loanOffer.maxApr, months); | |
} | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment