One trick to see through credit card routines

Use Python to solve practical problems

I have done something interesting recently. Although I don't have much technical content, I can share it and amuse everyone.
Because I am poor, I need to borrow from the bank. Currently, China Construction Bank provides two loans: one is a mortgage with an interest rate of 5.39%, with equal principal and interest, and a fixed amount of monthly repayment; the other is a decoration loan with a monthly interest rate of 0.28%, principal Installment repayment is similar to credit card bill installment. The monthly repayment is also a fixed amount. The loan period is up to 5 years and the amount is 300,000.
The CCB manager said that the renovation loan is the bank’s most favorable loan. The basic interest rate of general credit card installment is 0.68%, and the 25% discount for fractures is 0.51%. The monthly interest rate of the renovation loan is 0.28%, which is too cheap. Multiply it by 12 months. , The annual interest rate is only 0.28%*12=3.38%, which is lower than the mortgage interest rate of 5.39%, which is incredibly cheap.
As a financial migrant worker, I can’t help but think: It’s so cheap, should I use a renovation loan to repay the mortgage? Wouldn’t it be possible to simmer some wool? In order to solve this practical computing problem, we need to use Python with powerful computing capabilities. Moreover, the monthly repayment amount of the two loans is a fixed number, so they are comparable and mutually transformable.

official

The calculation formula of the two-minute loan:

  1. Mortgage Loan Formula
    First: The calculation formula for housing loan is: the
    Insert picture description here
    monthly repayment amount is X, the total loan amount is A, the monthly bank interest rate is β, and the total number of periods is m (months).
  2. Credit card installment formula:
    repayment amount per installment = loan principal/number of repayment periods + loan principal*monthly interest rate.
    The loan principal is the initial loan amount.
    Not much to say, just go to the code, Python is very readable, I also added comments to each line, and the variables are in Pinyin, which is very easy to understand. 代码片.
// An highlighted block
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#定义基本参数
benJin=300000     #本金30
nianXian=5      #贷款年限
zongYueShu=nianXian*12  #贷款总月份数
##房贷计算参数
fangDaiLiLv=0.0539    #房贷利率
yueLiLv=fangDaiLiLv/12   #月利率
##房贷计算公式
meiYueHuanKuan=(benJin*yueLiLv*(1+yueLiLv)**zongYueShu)/((1+yueLiLv)**zongYueShu-1)
print('每月房贷还款额度为:',meiYueHuanKuan)
fangDaiZongHuan=meiYueHuanKuan*zongYueShu    #房贷总还款金额
print('房贷总计还款额为:',fangDaiZongHuan)

##信用卡利息计算参数
yueLiXi = 0.0028      #信用卡月利率
meiYueliXi=benJin*yueLiXi    #信用卡月利息
meiYueHuanBenJin = benJin/zongYueShu     #信用卡每月归还本金
meiYueHuanKuanZongE = meiYueliXi+meiYueHuanBenJin   #信用卡每月归还额
print('信用卡每月还款额:',meiYueHuanKuanZongE)
huanKuanZongE = meiYueHuanKuanZongE*zongYueShu   #信用卡总计还款金额
print('信用卡总计还款额为:',huanKuanZongE)

#两种贷款归还金额差额
chaE= huanKuanZongE-fangDaiZongHuan   #信用卡比房贷多还款的金额
print('信用卡比房贷多还款金额:',chaE)

operation result

The results of the operation are as follows: The
monthly mortgage repayment amount is: 5715.1292964977965 The
total mortgage repayment amount is: 342907.7577898678
Credit card monthly
repayment amount: 5840.0 The total credit card repayment amount is: 350400.0 The
credit card repayment amount is more than the mortgage payment amount: 7492.242210132186

Preliminary Conclusions

What? ? ? The seemingly cheap credit card loan is more than 7,000 yuan more than the mortgage interest rate? Is it me who stalks the bank wool or the bank stalks my wool? WO CHA in uppercase! ! !
I was not reconciled. I felt that the credit card loan should be cheap, so I drew a picture and extended the loan period to 40 years. The result is as follows: It
Insert picture description here
can be seen that when the period is 30 years, the mortgage exceeds the credit card for the first time, so If the loan period can exceed 30 years, then the credit card loan is a good deal. Of course, the bank has a group of data analysts who specialize in this strategy. We can think of the woolen method. The other party has long been familiar with it, so it has been set long ago. The loan period is up to 5 years, waiting for you to get the bait.
It's not over yet, so let's ask, what interest rate is equivalent to a 5-year mortgage with a five-year credit card loan?

Solving nonlinear equations

This is the solution of a nonlinear equation. We need to use fsolve in scipy.optimize to solve these high-dimensional equations. Through the gradient descent method, fsolve can quickly find the local optimal solution within the specified range.
So in order to solve the above problem, we need to rewrite the program, write it in the form of an equation, and solve it. The code is as follows:

// An highlighted block
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.optimize import fsolve
#定义基本参数
benJin=300000     #本金30
nianXian=5      #贷款年限
zongYueShu=nianXian*12  #贷款总月份数

#房贷计算公式,输入年利率,输出每月还款额
def fangDaiJiSuan(fangDaiLiLv):
    yueLiLv = fangDaiLiLv / 12  # 月利率
    meiYueHuanKuan = (benJin * yueLiLv * (1 + yueLiLv) ** zongYueShu) / ((1 + yueLiLv) ** zongYueShu - 1)
    print('每月房贷还款额度为:', meiYueHuanKuan)
    fangDaiZongHuan = meiYueHuanKuan * zongYueShu  # 房贷总还款金额
    print('房贷总计还款额为:', fangDaiZongHuan)
    return meiYueHuanKuan

#信用卡利息计算公式,输入月利率,输出每月还款额
def xinYongKaJiSuan(yueLiXi):
    meiYueliXi = benJin * yueLiXi  # 信用卡月利息
    meiYueHuanBenJin = benJin / zongYueShu  # 信用卡每月归还本金
    meiYueHuanKuanZongE = meiYueliXi + meiYueHuanBenJin  # 信用卡每月归还额
    print('信用卡每月还款额:', meiYueHuanKuanZongE)
    huanKuanZongE = meiYueHuanKuanZongE * zongYueShu  # 信用卡总计还款金额
    print('信用卡总计还款额为:', huanKuanZongE)
    return meiYueHuanKuanZongE

#定义差额函数,也就是求非线性方程的解,输入房贷年利率,输出房贷和信用卡的还款差额
def chaE(x):
    ##信用卡利息参数
    yueLiXi = 0.0028  # 信用卡月利率
    return fangDaiJiSuan(x)-xinYongKaJiSuan(yueLiXi)

#主函数
solve = fsolve(chaE,[0.5])  #求解房贷年利率
#打印求解结果
print(solve)
#验证结果是否真的是方程的解
print(np.isclose(chaE(solve), [0.0],atol=1e-3))  #检验解是否是符合方程组的近似解


operation result

The result of the procedure is as follows:
[0.06287284]

Conclusion 2

That is, a 5-year credit card loan, which is equivalent to a 5-year mortgage with an interest rate of 6.29%. That's why credit card loans are more expensive.
Conversely, the mortgage interest rate of 5.39% is converted into a credit card installment rate of 0.238%. The above code can be solved with a little modification, and interested students can try it out. If the bank is willing to use this interest rate to install installments for us, then decisively install them. Of course this is a dream, it's time to wake up.
SO, learning to use Python can make us more sensible in the face of various routines used by bank analysts (such as free interest rates and only handling fees, etc.). Otherwise, the little hair on his body would be taken away by the bank.

Guess you like

Origin blog.csdn.net/weixin_43290383/article/details/111979461