Loan and Mortgage Calculator Template: Loan & Mortgage Calculator Calculate monthly payments, total interest, and total cost of a loan. homePrice = 300000 $
# Loan & Mortgage Calculator
# Calculate monthly payments, total interest, and total cost of a loan.
# Inputs
homePrice = 300000 $
downPayment = 20 %
annualInterestRate = 4.5 %
loanTerm = 30 years
# Calculated Loan Details
# Calculate down payment amount
downPaymentAmount = homePrice * downPayment
# Loan amount (principal) to borrow
loanAmount = homePrice - downPaymentAmount
# Total number of payments (months)
totalPayments = loanTerm to months
# Monthly Payment Calculation
# Amortization Formula: P = L * [ r(1+r)^n ] / [ (1+r)^n - 1 ]
# where:
# L = loanAmount
# r = monthly interest rate (annual rate / 12)
# n = total number of payments (months, unitless)
r = annualInterestRate / 12
n = totalPayments / (1 month)
monthlyPayment = loanAmount * (r * (1 + r)^n) / ((1 + r)^n - 1)
# Total Lifetime Costs
# Total amount paid over the entire term
totalCost = monthlyPayment * n
# Total interest paid to the lender
totalInterest = totalCost - loanAmount
# Percentage of total cost that goes to interest
interestRatio = (totalInterest / totalCost) * 100 %