File size: 2,342 Bytes
f70d24a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
import streamlit as st
import numpy as np

# Function to calculate loan details
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

# Main Streamlit app
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()