Spaces:
Sleeping
Sleeping
File size: 1,582 Bytes
8a3dd38 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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) |