|
import streamlit as st |
|
import numpy as np |
|
|
|
|
|
def calculate_loan(loan_amount, loan_term_years, interest_rate): |
|
monthly_rate = interest_rate / 100 / 12 |
|
loan_term_months = loan_term_years * 12 |
|
monthly_payment = loan_amount * (monthly_rate * (1 + monthly_rate) ** loan_term_months) / ((1 + monthly_rate) ** loan_term_months - 1) |
|
total_payments = monthly_payment * loan_term_months |
|
total_interest = total_payments - loan_amount |
|
return monthly_payment, total_payments, total_interest |
|
|
|
|
|
def main(): |
|
st.subheader("Real Estate Loan Calculator") |
|
st.markdown("---") |
|
st.subheader("Loan Details") |
|
col1, col2, col3 = st.columns(3) |
|
|
|
with col1: |
|
loan_amount = st.number_input("Loan Amount (€)", value=150000, step=1000) |
|
loan_term_years = st.number_input("Loan Term (Years)", value=20, step=1) |
|
interest_rate = st.number_input("Interest Rate (%)", value=3.49, step=0.01) |
|
|
|
monthly_payment, total_payments, total_interest = calculate_loan(loan_amount, loan_term_years, interest_rate) |
|
|
|
with col2: |
|
st.markdown( |
|
f""" |
|
<div style="border: 2px solid #ccc; padding: 10px; background-color: #0e1117; border-radius: 5px; text-align: center;"> |
|
<h4 style="font-weight: bold;">Loan Details</h4> |
|
<p>Monthly:<br> <span style="font-weight: bold; color: orange;">{monthly_payment:.2f} €</span><br> |
|
Total:<br> <span style="font-weight: bold; color: teal;">{total_payments:.2f} €</span><br> |
|
Total Interest:<br> <span style="font-weight: bold; color: green;">{total_interest:.2f} €</span></p> |
|
</div> |
|
""", |
|
unsafe_allow_html=True |
|
) |
|
with col3: |
|
st.markdown( |
|
f""" |
|
<div style="padding: 10px; "> |
|
<h5 style="font-style: italic;">Project Costs</h5> |
|
<p style="font-style: italic;"><span style="font-weight: bold;">Costs closing: 10,000 €</span></p> |
|
<p style="font-style: italic;">Notary fees and others: 5,000 €</p> |
|
<p style="font-style: italic;">Notary fees and others: 5,000 €</p> |
|
</div> |
|
""", |
|
unsafe_allow_html=True |
|
) |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|
|
|