go代碼實現(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元。
實際上,公積金貸款的最大金額是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 (和實際值15858非常接近)
- m(500萬) = 37 * 450 - 800 = 17700 (和實際值17715非常接近)
當(dāng)然啦,除了月供, 還有首付的30%,還有這費那費, 多得很。
所以, 買房的總支付是: 首付 + 這費那費 + 月供*360
最后,如果不使用組合貸,而純使用商業(yè)貸, 那么月供是多少呢?
容易大致計算出: m = 37 * y (可以看到,純商業(yè)貸的月供比組合貸的月供貴大約800元,接近1000元)
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接