EMI計算機
ローンのEMIを計算し、完全な償却スケジュールを表示します。
よくある質問
コード実装
def calculate_emi(principal: float, annual_rate: float, months: int) -> dict:
"""Calculate EMI and generate amortization schedule."""
monthly_rate = annual_rate / 100 / 12
if monthly_rate == 0:
emi = principal / months
else:
emi = principal * monthly_rate * (1 + monthly_rate) ** months / (
(1 + monthly_rate) ** months - 1
)
schedule = []
balance = principal
total_interest = 0
for month in range(1, months + 1):
interest = balance * monthly_rate
principal_part = emi - interest
balance -= principal_part
total_interest += interest
schedule.append({
"month": month,
"emi": round(emi, 2),
"principal": round(principal_part, 2),
"interest": round(interest, 2),
"balance": round(max(balance, 0), 2),
})
return {
"emi": round(emi, 2),
"total_payment": round(emi * months, 2),
"total_interest": round(total_interest, 2),
"schedule": schedule,
}
result = calculate_emi(principal=500000, annual_rate=8.5, months=240)
print(f"Monthly EMI: {result['emi']}")
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.