等额本息&等额本金

1、贷款计算器

2024年最新版房贷利率计算器_LPR利率计算器 (K JSON)

贷款计算器

2、等额本息

接下来,我们可以用Python编写一个函数来计算每月还款额:

import pandas as pd


def amortization_schedule(principal, annual_interest_rate, years):
    """
    生成贷款的摊还表。

    参数:
    principal (float): 贷款本金。
    annual_interest_rate (float): 年利率。
    years (int): 贷款年限。

    返回:
    tuple: 包含摊还表 DataFrame, 还款总额, 和支付的总利息。
    """
    # 计算月利率
    monthly_interest_rate = annual_interest_rate / 12
    # 计算总支付期数
    total_payments = years * 12
    # 计算每期还款额
    monthly_payment = principal * (monthly_interest_rate * (1 + monthly_interest_rate) ** total_payments) / (
                (1 + monthly_interest_rate) ** total_payments - 1)

    # 初始化摊还表和剩余本金及累计还款总额和利息
    schedule = []
    remaining_principal = principal
    total_repayment = 0
    total_interest = 0

    # 生成摊还表
    for period in range(1, int(total_payments) + 1):
        # 计算本期利息
        interest = remaining_principal * monthly_interest_rate
        # 计算本期偿还本金
        principal_paid = monthly_payment - interest
        # 更新剩余本金
        remaining_principal -= principal_paid
        # 保留两位小数
        monthly_payment_formatted = round(monthly_payment, 2)
        remaining_principal_formatted = round(remaining_principal, 2)
        # 添加本期记录到摊还表
        schedule.append([period, monthly_payment_formatted, remaining_principal_formatted])

        # 累加还款总额和利息
        total_repayment += monthly_payment
        total_interest += interest

    # 返回摊还表 DataFrame, 还款总额, 和支付的总利息
    return pd.DataFrame(schedule, columns=['期次', '还款金额(元)', '剩余本金(元)']), total_repayment, total_interest


# 输入参数
principal = 1000000  # 贷款本金
annual_interest_rate = 0.0385  # 年利率
years = 20  # 贷款年限

# 创建还款计划表
schedule_df, total_repayment, total_interest = amortization_schedule(principal, annual_interest_rate, years)

# 显示结果
print("还款计划表:")
print(schedule_df.head())  # 显示前几行
print("\n总计:")
print(f"累计还款总额(元): {total_repayment:.2f}")
print(f"累计支付利息(元): {total_interest:.2f}")
还款计划表:
   期次  还款金额(元)    剩余本金(元)
0   1  5981.06  997227.28
1   2  5981.06  994445.66
2   3  5981.06  991655.12
3   4  5981.06  988855.62
4   5  5981.06  986047.14

总计:
累计还款总额(元): 1435453.40
累计支付利息(元): 435453.40

3、等额本金

import pandas as pd

def amortization_schedule_principal(principal, annual_interest_rate, years):
    monthly_interest_rate = annual_interest_rate / 12
    total_payments = years * 12
    monthly_principal = principal / total_payments
    schedule = []
    remaining_principal = principal
    total_repayment = 0
    total_interest = 0
    
    for period in range(1, int(total_payments) + 1):
        interest = remaining_principal * monthly_interest_rate
        monthly_payment = monthly_principal + interest
        remaining_principal -= monthly_principal
        
        # 保留两位小数
        monthly_payment_formatted = round(monthly_payment, 2)
        remaining_principal_formatted = round(remaining_principal, 2)
        interest_formatted = round(interest, 2)
        
        schedule.append([period, monthly_payment_formatted, remaining_principal_formatted])
        
        # 累加还款总额和利息
        total_repayment += monthly_payment
        total_interest += interest
    
    return pd.DataFrame(schedule, columns=['期次', '还款金额(元)', '剩余本金(元)']), total_repayment, total_interest

# 输入参数
principal = 1000000  # 贷款本金
annual_interest_rate = 0.0385  # 年利率
years = 20  # 贷款年限

# 创建还款计划表
schedule_df, total_repayment, total_interest = amortization_schedule_principal(principal, annual_interest_rate, years)

# 显示结果
print("等额本金还款计划表:")
print(schedule_df.head())  # 显示前几行
print("\n总计:")
print(f"累计还款总额(元): {total_repayment:.2f}")
print(f"累计支付利息(元): {total_interest:.2f}")
等额本金还款计划表:
   期次  还款金额(元)    剩余本金(元)
0   1  7375.00  995833.33
1   2  7361.63  991666.67
2   3  7348.26  987500.00
3   4  7334.90  983333.33
4   5  7321.53  979166.67

总计:
累计还款总额(元): 1386604.17
累计支付利息(元): 386604.17

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值