brettapps789's picture
download
raw
1.5 kB
def mortgage_calculator(principal: float, annual_rate: float, years: int) -> dict:
"""
Calculates monthly mortgage payments.
annual_rate: e.g., 0.05 for 5%
"""
monthly_rate = annual_rate / 12
num_payments = years * 12
if monthly_rate == 0:
monthly_payment = principal / num_payments
else:
monthly_payment = principal * (monthly_rate * (1 + monthly_rate)**num_payments) / ((1 + monthly_rate)**num_payments - 1)
total_paid = monthly_payment * num_payments
total_interest = total_paid - principal
return {
"monthly_payment": monthly_payment,
"total_paid": total_paid,
"total_interest": total_interest,
"num_payments": num_payments
}
def savings_projection(initial: float, monthly_addition: float, annual_rate: float, years: int) -> dict:
"""
Projects the future value of savings.
"""
monthly_rate = annual_rate / 12
num_months = years * 12
current = initial
history = [{"month": 0, "balance": current}]
for m in range(1, num_months + 1):
current = (current * (1 + monthly_rate)) + monthly_addition
if m % 12 == 0:
history.append({"year": m // 12, "balance": current})
return {
"future_value": current,
"total_contributions": initial + (monthly_addition * num_months),
"interest_earned": current - (initial + (monthly_addition * num_months)),
"history": history
}

Xet Storage Details

Size:
1.5 kB
·
Xet hash:
34398ac7c6d6126f45be953dfde2afc0b01a703954d2d2e23ee1c0db0581e0ed

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.