Student Loan Calculator
Calculate monthly student loan payments, total interest, and amortization schedule.
Perguntas Frequentes
Implementação de Código
def calculate_student_loan(principal: float, annual_rate: float,
years: int) -> dict:
"""Calculate student loan monthly payment and total interest."""
monthly_rate = annual_rate / 100 / 12
n = years * 12
if monthly_rate == 0:
monthly_payment = principal / n
else:
monthly_payment = principal * (monthly_rate * (1 + monthly_rate) ** n) / ((1 + monthly_rate) ** n - 1)
total_payment = monthly_payment * n
total_interest = total_payment - principal
return {
"monthly_payment": round(monthly_payment, 2),
"total_payment": round(total_payment, 2),
"total_interest": round(total_interest, 2),
}
def amortization_schedule(principal: float, annual_rate: float, years: int):
"""Generate full amortization schedule."""
monthly_rate = annual_rate / 100 / 12
n = years * 12
payment = calculate_student_loan(principal, annual_rate, years)["monthly_payment"]
balance = principal
for month in range(1, n + 1):
interest = balance * monthly_rate
principal_part = payment - interest
balance -= principal_part
yield {
"month": month,
"payment": round(payment, 2),
"principal": round(principal_part, 2),
"interest": round(interest, 2),
"balance": round(max(balance, 0), 2),
}
# Example: $30,000 loan at 5.5% over 10 years
result = calculate_student_loan(30000, 5.5, 10)
print(f"Monthly Payment: ${result['monthly_payment']}")
print(f"Total Payment: ${result['total_payment']}")
print(f"Total Interest: ${result['total_interest']}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.