go代碼實(shí)現(xiàn)買房貸款月供計算的方法
貸款金額:100元(先以100元為例,來對比下公積金貸款和商業(yè)貸款)
公積金貸款年利率: 3.25%
商業(yè)貸款的年利率: 4.90%
貸款期限:360個月(30年)
還款方式:等額本息
計算公式:之前推導(dǎo)過, 用等比數(shù)列搞起即可
go代碼如下:
package main
import (
"fmt"
"math"
)
func get_pmt(f_interest_rate float64, term_number int, principal int) float64 {
compound_rate := math.Pow(1 + f_interest_rate, float64(term_number))
pmt := float64(principal) * f_interest_rate * compound_rate / (compound_rate - 1)
return pmt
}
func main(){
n := 360
year_month := 12
p := 100
r1 := float64(0.0490) / float64(year_month)
r2 := float64(0.0325) / float64(year_month)
a := get_pmt(r1, n, p) * float64(n) - float64(p)
b := get_pmt(r2, n, p) * float64(n) - float64(p)
fmt.Println(a, b)
}
結(jié)果:
91.06161942420968 56.67427486605655
也就是說,如果用商業(yè)貸款100元,利息大概是91元。如果用公積金貸款100元,利息大概是57元。
實(shí)際上,公積金貸款的最大金額是90萬(有要求),其余的缺口需要用商業(yè)貸款, 即組合貸款。
下面來具體算算買450萬房子和500萬房子的月供情況:
package main
import (
"fmt"
"math"
)
func get_pmt(f_interest_rate float64, term_number int, principal int) float64 {
compound_rate := math.Pow(1 + f_interest_rate, float64(term_number))
pmt := float64(principal) * f_interest_rate * compound_rate / (compound_rate - 1)
return pmt
}
func get_month_provide(price int) {
n := 360
year_month := 12
gongjijin_loan_limit := 900000
shoufu_rate := 0.3
r1 := float64(0.0490) / float64(year_month)
r2 := float64(0.0325) / float64(year_month)
month_provide := get_pmt(r2, n, gongjijin_loan_limit)
month_provide += get_pmt(r1, n, int(float64(price) * (float64(1) - float64(shoufu_rate)) - float64(gongjijin_loan_limit)) )
fmt.Println(month_provide)
}
func main(){
get_month_provide(4500000)
get_month_provide(5000000)
}
結(jié)果:
15858.20808566452
17715.751607844337
如上就是月供金額情況。 跟網(wǎng)上提供的房貸計算器的結(jié)果比對了一下,完全一致。
最后,來給一個近似的月供公式, 其中x是買房的房價:
m = ((0.7 * x - 900000) * 1.9106 + 900000 * 1.5677) / 360
= 37.15 * (x/10000) - 860
= 37.15 * y - 860
= 37 * y + 0.15y - 860(以深圳房價為例,近似認(rèn)為0.15y和60相等)
= 37 * y - 800
所以,買450萬的房子和買500萬的房子的月供分別為:
- m(450萬) = 37 * 450 - 800 = 15850 (和實(shí)際值15858非常接近)
- m(500萬) = 37 * 450 - 800 = 17700 (和實(shí)際值17715非常接近)
當(dāng)然啦,除了月供, 還有首付的30%,還有這費(fèi)那費(fèi), 多得很。
所以, 買房的總支付是: 首付 + 這費(fèi)那費(fèi) + 月供*360
最后,如果不使用組合貸,而純使用商業(yè)貸, 那么月供是多少呢?
容易大致計算出: m = 37 * y (可以看到,純商業(yè)貸的月供比組合貸的月供貴大約800元,接近1000元)
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
Golang 端口復(fù)用測試的實(shí)現(xiàn)
這篇文章主要介紹了Golang 端口復(fù)用測試的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
golang中defer執(zhí)行時機(jī)的案例分析
這篇文章主要來通過一些案例和大家一起探討一下golang中defer的執(zhí)行時機(jī),文中的示例代碼講解詳細(xì),對我們深入了解golang有一定的幫助,感興趣的可以跟隨小編一起學(xué)習(xí)一下2023-11-11
golang實(shí)戰(zhàn)之truncate日志文件詳解
這篇文章主要給大家介紹了關(guān)于golang實(shí)戰(zhàn)之truncate日志文件的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-07-07

