[Python]元利均等返済額を計算する方法

calculate_amortization_schedule関数を作成し、借入額、金利、返済年数を入れる

def calculate_amortization_schedule(principal, annual_interest_rate, loan_term_years):
    # Convert annual interest rate to monthly rate and calculate number of payments
    monthly_interest_rate = annual_interest_rate / 12 / 100
    num_payments = loan_term_years * 12

    # Calculate the monthly payment using the amortization formula
    monthly_payment = (principal * monthly_interest_rate) / (1 - (1 + monthly_interest_rate)**-num_payments)
    
    amortization_schedule = []
    remaining_balance = principal
    
    for _ in range(num_payments):
        interest_payment = remaining_balance * monthly_interest_rate
        principal_payment = monthly_payment - interest_payment
        remaining_balance -= principal_payment
        
        amortization_schedule.append((principal_payment, interest_payment, remaining_balance))
    
    return amortization_schedule

# Example usage
principal_amount = 100000  # The initial loan amount
annual_interest_rate = 5   # Annual interest rate in percentage
loan_term_years = 10       # Loan term in years

schedule = calculate_amortization_schedule(principal_amount, annual_interest_rate, loan_term_years)

# Print the schedule
for index, (principal_payment, interest_payment, remaining_balance) in enumerate(schedule, start=1):
    print(f"Month {index}: Principal Payment = {principal_payment:.2f}, Interest Payment = {interest_payment:.2f}, Remaining Balance = {remaining_balance:.2f}")

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です