import streamlit as st import pandas as pd import math def calculate_emi(principal, annual_rate, months): monthly_rate = annual_rate / 12 / 100 emi = principal * monthly_rate * (math.pow(1 + monthly_rate, months)) / (math.pow(1 + monthly_rate, months) - 1) return emi def generate_schedule(principal, annual_rate, months, emi): monthly_rate = annual_rate / 12 / 100 balance = principal schedule = [] for month in range(1, months + 1): interest = balance * monthly_rate principal_payment = emi - interest balance -= principal_payment schedule.append({ "Month": month, "EMI": round(emi, 2), "Principal Payment": round(principal_payment, 2), "Interest": round(interest, 2), "Balance": round(balance, 2) }) if balance < 0: balance = 0 return pd.DataFrame(schedule) # Streamlit UI st.sidebar.header("EMI Calculator") # Inputs loan_amount = st.sidebar.number_input("Loan Amount (₹)", min_value=0.0, value=100000.0, step=1000.0) tenure_months = st.sidebar.number_input("Tenure (Months)", min_value=1, value=12, step=1) interest_rate = st.sidebar.number_input("Annual Interest Rate (%)", min_value=0.0, value=10.0, step=0.1) if st.sidebar.button("Calculate"): emi = calculate_emi(loan_amount, interest_rate, tenure_months) st.write(f"### EMI: ₹{round(emi, 2)} per month") schedule = generate_schedule(loan_amount, interest_rate, tenure_months, emi) st.write("### Payback Schedule") st.dataframe(schedule)