-
Notifications
You must be signed in to change notification settings - Fork 0
/
mortgage.js
36 lines (22 loc) · 1012 Bytes
/
mortgage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export const calcMonthlyPayments = (loanAmount, interestRate, loanPayPeriod = 15) => {
// https://www.youtube.com/watch?v=6bLg_Ex0A-4
const numMonths = loanPayPeriod * 12
const ratePerMonth = interestRate / 12
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow
return (loanAmount * ratePerMonth * (Math.pow((1 + ratePerMonth), numMonths))) / ((Math.pow((1 + ratePerMonth), numMonths)) - 1)
}
export const calcTotalMortgage = (loanAmount, interestRate, loanPayPeriod = 15) => {
const perMonth = calcMonthlyPayments(loanAmount, interestRate, loanPayPeriod)
return perMonth * loanPayPeriod * 12
}
export const getBreakdown = (loanAmount, interestRate, loanPayPeriod = 15) => {
const total = calcTotalMortgage(loanAmount, interestRate, loanPayPeriod)
return {
total: total,
interestPaid: total - loanAmount,
term: loanPayPeriod
}
}
const principle = 300000
const rate = 0.05
const loanYears = 30