go code to achieve the house loan monthly payment calculation method

  • 2020-06-23 00:38:53
  • OfStack

Loan amount: 100 yuan (take 100 yuan as an example to compare provident fund loan and commercial loan)

Provident fund loan annual interest rate: 3.25%

Annual interest rate for commercial loans: 4.90%

Loan term: 360 months (30 years)

Repayment method: equal amount principal and interest

Calculation formula: derived before, with the geometric series to do

go code is as follows:


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)
}

Results:

[

91.06161942420968 56.67427486605655

]

In other words, if you take out a commercial loan for 100 yuan, the interest rate is about 91 yuan. If you borrow 100 yuan from the PROVIDent fund, the interest will be about 57 yuan.

In fact, the maximum amount of a provident fund loan is 900,000 yuan (as required), and the rest of the gap needs to be made up of commercial loans, namely portfolio loans.

Let's calculate the monthly payment of 4.5 million houses and 5 million houses:


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)
}

Results:

[

15858.20808566452
17715.751607844337

]

The above is the monthly payment amount. Compared with the result of the home loan calculator that provides on the net 1, complete 1 send.

Finally, a similar monthly payment formula is given, in which x is the house price:

[

m = ((0.7 * x - 900000) * 1.9106 + 900000 * 1.5677) / 360
= 37.15 * (x/10000) - 860
= 37.15 * y - 860
= 37 * y + 0.15 ES53en-860 (taking the housing price in Shenzhen as an example, it is approximately assumed that 0.15y and 60 are equal)
= 37 * y - 800

]

So, the monthly payments for a $4.5 million house and a $5 million house are:

m(4.5 million) = 37 * 450-800 = 15850 (very close to the actual value of 15858) m(5 million) = 37 * 450-800 = 17700 (very close to the actual value of 17715)

Of course, in addition to the monthly payment, there's a 30% down payment, and that's a lot.

Therefore, the total payment to buy a house is: down payment + that fee + monthly payment *360

And finally, if you don't use portfolio loans, if you just use commercial loans, what's the monthly payment?

It is easy to roughly calculate: m = 37 * y (it can be seen that the monthly payment of pure commercial loan is about 800 yuan more expensive than that of combined loan, close to 1000 yuan)

conclusion


Related articles: