Javascript 房貸公式

近期有個項目要寫房貸的試算公式,但是網路上通常只找得到「本息平均攤還法」的公式,下列就針對不同的房貸算法進行整理了:

本息平均攤還法

依照20年、2%貸款800萬試算,結果與公式如下:

1
2
3
4
5
6
7
8
9
loan_average() {
let rate = 0.02 // 年利率(2%)
let year = 20 // 貸款年份
let totalLoan = 8000000 //總貸款金額(800w)
let rateForMonth = rate / 12 // 平均月利息
let avgRate = (Math.pow(1 + rateForMonth, (year * 12)) * rateForMonth) / (Math.pow((1 + rateForMonth), year * 12) - 1) // 平均每月要繳的百分比
let result = avgRate * totalLoan // 每月要繳的錢
let totalInterest = avgRate * totalLoan * year * 12) - totalLoan )) // 總利息費用
}

三階段調息月付

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
37
38
39
40
41
42
43
44
loan_stages() {
let year = 20 // 貸款年份20年
let totalLoan = 8000000 //貸款800萬
var totalMonth = year * 12
let stagesRateList= [{
id: 1,
rate: 0.01, // 第一年1%利率
monthCount: 12,
resultMessage: ''
},
{
id: 2,
rate: 0.02, // 第二年2%利率
monthCount: 12,
resultMessage: ''
},
{
id: 3,
rate: 0.03,// 第三年3%利率
monthCount: 0, //剩餘月份
resultMessage: ''
}
]
stagesRateList[2].monthCount = totalMonth - 24 // 把剩餘月份填入第三階段
var tempTotalLoan = totalLoan // 餘額
let totalInterest = 0 // 總利息

stagesRateList.forEach((item, index) => {
let rateForMonth = (item.rate) / 12
var avgRate = (Math.pow(1 + rateForMonth, (totalMonth)) * rateForMonth) / (Math.pow((1 + rateForMonth),
totalMonth) - 1)
var avgMonthlyPay = avgRate * tempTotalLoan // 平均每月付金額
for (var i = 0; i < item.monthCount; i++) {
var interest = tempTotalLoan * rateForMonth // 利息
totalInterest += interest
var principal = avgMonthlyPay - interest // 本金
console.log('本金', principal)
tempTotalLoan = tempTotalLoan - principal
console.log('餘額', tempTotalLoan)
}
totalMonth -= 12
item.resultMessage = `第${item.id}年每月貸款償還金額:${avgMonthlyPay}`
})
}

有還本寬限期試算

1
2
3
4
5
6
7
8
9
10
11
12
13
14
loan_repay() {
let year = 20 // 貸款年份
let delayYear = 3 // 寬限年份
let rate = 0.02 // 利率2%
let totalLoan = 8000000 // 總貸款金額
let totalMonth = year * 12 //總貸款月份
let delayMonth = this.delayYear*12 // 總寬限月份
let rateForMonth = rate / 12 // 月利率
let avgRate = (Math.pow(1 + rateForMonth, (totalMonth-delayMonth)) * rateForMonth) / (Math.pow((1 + rateForMonth),
totalMonth-delayMonth) - 1)
let interest = totalLoan * rateForMonth // 寬限期內利息
let delayInterest = interest
let delayRepaymeny = avgRate*totalLoan // 寬限期後本金+利息
}

以上算法提供大家參考~

0%