当前位置: 代码迷 >> 综合 >> 当LPR利率来临的时候,我们的房贷该不该改?
  详细解决方案

当LPR利率来临的时候,我们的房贷该不该改?

热度:48   发布时间:2024-01-27 03:26:58.0

根据中国人民银行公告,存量浮动利率贷款定价基准转换自2020年3月1日如期启动。根据规定,存量浮动利率房贷的贷款人,重签合同时可以选择固定利率也可以选择贷款市场报价利率(LPR)的浮动利率。定价基准只能转换一次,转换之后不能再次转换。注意,这里的意思应该是LPR的bp值只能改一次,而不是LPR的数值不能改。

那么,买房、有房贷的小伙伴们该如何选择?对此,专家表示,监管层明确要继续推进LPR改革,引导整体市场利率和贷款利率下行,LPR或许是更好的选择。此外,换锚将推进利率市场化“两轨并一轨”,先增量、后存量渐进式改革,有效保障贷款合约基准的平稳转换,为实体经济降成本打开新空间。

但是,专家靠谱吗?我想大部分人应该是从来没有成功薅过社会主义羊毛的。所以,我们自己写程序,判断下到底该不该换成LPR。以下是源代码。兄弟姐妹们自己跑一下,心里就有底了。

 

# -*- coding: utf-8 -*-
# @Time    : 20/2/27 11:14
# @Author  : Jay Lam
# @File    : LPR_Calculator.py
# @Software: PyCharmimport math
import randomimport numpy as np# LPR计算
def LPRCalculator():currentLPR = round(float(input("输入更改合同时的LPR利率(%):")), 2)currentInterest = round(float(input("输入更改合同时的固定利率(%):")), 2)totalMonth = int(input("输入贷款总月数:"))residueMonth = int(input("输入剩余贷款月数:"))paymentPlan = int(input("输入还款方式。等额本金输入0,等额本息输入1:"))rangeLimit = int(input("输入是否限制未来LPR利率预测。不限制0,减少输入-1,增加输入1:"))totalLoan = round(float(input("输入贷款总额(元):")), 2)bp = currentInterest - currentLPR  # 基点计算changeTimes = math.floor((totalMonth - residueMonth) / 12)  # 一年允许改变一次利率if paymentPlan == 0:oldTotalPayment = averageCapital(totalLoan, 1, currentInterest, totalMonth)[0]oldResidueAmount = oldTotalPayment - averageCapital(totalLoan, 1, currentInterest, totalMonth)[1][0:(totalMonth - residueMonth)].sum()print(oldResidueAmount)print("LPR和原计划支出总额差为:",round(LPR(changeTimes, bp, rangeLimit, totalLoan, residueMonth, currentLPR)[0] - oldResidueAmount, 2),"元")elif paymentPlan == 1:oldTotalPayment = averageCapitalPlusInterest(totalLoan, 1, currentInterest, totalMonth)[0]oldResidueAmount = averageCapitalPlusInterest(totalLoan, 1, currentInterest, totalMonth)[1]*residueMonthprint("LPR和原计划支出总额差为:",round(LPR(changeTimes, bp, rangeLimit, totalLoan, residueMonth, currentLPR)[1] - oldResidueAmount, 2),"元")# 随机预测LPR
def LPR(changeTimes, bp, rangeLimit, totalLoan, resMonth, currentLPR):plan0 = []plan1 = []if rangeLimit == 0:for i in range(1, changeTimes):actualRatio = random.random() + bpcurrentYearPayment0 = averageCapital(totalLoan, 1, actualRatio, resMonth)[1][0:12].sum()currentYearPayment1 = averageCapitalPlusInterest(totalLoan, 1, actualRatio, resMonth)[1] * 12# 等额本息法直接每个月乘以12获得年度支出值plan0.append(currentYearPayment0)plan1.append(currentYearPayment1)actualTotalPayment0 = np.array(plan0).sum()actualTotalPayment1 = np.array(plan1).sum()elif rangeLimit == 1:actualRatio = randAscending(changeTimes, currentLPR + 0.15, currentLPR - 0.15)  # 未来变化幅度不超过签约时LPR±0.15for i in range(0, len(actualRatio)):currentYearPayment0 = averageCapital(totalLoan, 1, actualRatio[i], resMonth)[1][0:12].sum()currentYearPayment1 = averageCapitalPlusInterest(totalLoan, 1, actualRatio[i], resMonth)[1] * 12plan0.append(currentYearPayment0)plan1.append(currentYearPayment1)actualTotalPayment0 = np.array(plan0).sum()actualTotalPayment1 = np.array(plan1).sum()elif rangeLimit == -1:actualRatio = randDecending(changeTimes, currentLPR + 0.15, currentLPR - 0.15)for i in range(0, len(actualRatio)):currentYearPayment0 = averageCapital(totalLoan, 1, actualRatio[i], resMonth)[1][0:12].sum()currentYearPayment1 = averageCapitalPlusInterest(totalLoan, 1, actualRatio[i], resMonth)[1] * 12plan0.append(currentYearPayment0)plan1.append(currentYearPayment1)actualTotalPayment0 = np.array(plan0).sum()actualTotalPayment1 = np.array(plan1).sum()return round(actualTotalPayment0, 2), round(actualTotalPayment1, 2)# 生成升序随机数序列
def randAscending(changetimes, uplimit, lowlimit):se = []for _ in range(changetimes):se.append(round(random.uniform(lowlimit, uplimit), 4))se.sort(reverse=False)return se# 生成降序随机数序列
def randDecending(changetimes, uplimit, lowlimit):se = []for _ in range(changetimes):se.append(round(random.uniform(lowlimit, uplimit), 4))se.sort(reverse=True)return se# 等额本息法
def averageCapitalPlusInterest(principal, principalRatio, anualInterestRate, month):# principal表示房价总额,principalRatio表示房贷百分比,anualInterestRate表示房贷年利率,month表示房贷月份mortgage = np.around(principal * principalRatio, 2)  # 计算需要贷款的金额monthlyPayment = np.around(mortgage * averageCapitalPlusInterestRate(month, monthlyInterestRate(anualInterestRate)),2)  # 计算每月应还款金额totalInt = np.around(totalInterest(mortgage, monthlyPayment, month), 2)mortgageIntoTenThousand = np.around(mortgage / 10000, 2)  # 将贷款总金额转化为万元print("贷款:", mortgageIntoTenThousand, "万元")  # 输出结果print("年利率:", anualInterestRate, "%")print("按揭月数:", month, "月")print("每月应还:", monthlyPayment, "元")  # 输出结果print("需付利息:", totalInt, "元")totalPayment = np.around(monthlyPayment * month, 2)  # 还款总额return totalPayment, monthlyPayment# 等额本息法计算每月利率
def monthlyInterestRate(anualInterestRate):return (anualInterestRate / 12) / 100  # 年利率/12# 等额本息法计算比例系数
def averageCapitalPlusInterestRate(month, monthlyInterestRate):R = monthlyInterestRateN = monthI = R * math.pow(1 + R, N) / (math.pow(1 + R, N) - 1)return Idef totalInterest(mortgage, monthlyPayment, month):return monthlyPayment * month - mortgage# 等额本金法
def averageCapital(principal, principalRatio, anualInterestRate, month):# principal表示房价总额,principalRatio表示房贷百分比,anualInterestRate表示房贷年利率,month表示房贷月份monthlyPayment = np.zeros(month)  # 初始化每月还款金额cont = 0mortgage = np.around(principal * principalRatio, 2)  # 计算需要贷款的金额mortgageIntoTenThousand = np.around(mortgage / 10000, 2)  # 将贷款总金额转化为万元print("贷款:", mortgageIntoTenThousand, "万元")  # 输出结果print("年利率:", anualInterestRate, "%")print("按揭月数:", month, "月")for i in range(0, month):monthlyPayment[i] = np.around((mortgage / month) + (mortgage * monthlyInterestRate2(anualInterestRate)) - (i * (mortgage / month) * monthlyInterestRate(anualInterestRate)), 2)# 每月还款金额cont += np.around(monthlyPayment[i], 2)print("第", i + 1, "月应还款:", monthlyPayment[i], "元")  # 输出结果totalPayment = np.around(sum(monthlyPayment), 2)  # 计算还款总额print("还款总额:", totalPayment, "元")return totalPayment, monthlyPayment# 等额本金法计算每月利率
def monthlyInterestRate2(anualInterestRate):return (anualInterestRate / 12) / 100  # 年利率/12if __name__ == "__main__":#print(LPR(25, 0.833, -1, 2730000, 300, 4.9))#print(averageCapitalPlusInterest(2000000,1,4.3,360))LPRCalculator()

 

  相关解决方案