Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (56 loc) · 2.42 KB
/
Copy pathmain.py
File metadata and controls
69 lines (56 loc) · 2.42 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import pandas as pd
import streamlit as st
from loan_with_refinancing import LoanWithRefinancing
st.title("Kalkulačka refinancování hypotéky")
#########################################
# #
# Mortgage calculation #
# #
#########################################
col1, col2 = st.columns(2)
home_value = col1.number_input("Původní splácená částka", min_value=0, value=100_000)
old_loan_length = col1.number_input("Původní délka splácení [roky]", min_value=1, value=20)
old_interest_rate = col1.number_input("Původní úrok [%]", min_value=0.1, value=2.0) / 100
old_loan_current_year = col2.number_input("Rok refinancování", min_value=1, max_value=old_loan_length - 1, value=5)
refinancing_interest_rate = col2.number_input("Úrok po refinancování [%]", min_value=0.1, value=5.0) / 100
new_loan_length = col2.number_input("Doba splácení hypotéky (v letech)", min_value=-20, value=20)
length_change = new_loan_length - old_loan_length
risk_choice = st.selectbox(
"Kterou miru rizika pri investovani preferujete?",
("safe", "medium", "risky"),
)
loan = LoanWithRefinancing(
principal=home_value,
interest=old_interest_rate,
term=old_loan_length,
refinancing_year=old_loan_current_year,
refinancing_interest=refinancing_interest_rate,
new_hypo_length_change_years=length_change,
)
data = []
overpaid = 0.0
for inst in loan.schedule_with_refinancing():
data.append(
{
"number": inst.number,
"payment": float(inst.payment),
"interest": float(inst.interest),
"principal": float(inst.principal),
"total_interest": float(inst.total_interest),
"balance": float(inst.balance),
"investment_values": float(inst.investment_values.get(risk_choice, 0)),
}
)
overpaid += float(inst.interest)
st.write("Graf předčasného splacení hypotéky")
df = pd.DataFrame(data)
df.drop(df.index[0], inplace=True)
overpayment_df = df[["balance", "investment_values"]]
payment_details_df = df[["interest", "principal"]]
investment_data = df["investment_values"]
st.line_chart(overpayment_df, x_label="Mesice", y_label="Kč")
st.write(f"Přeplacená částka: {overpaid:.0f} kč")
st.write("Graf výše spláceného úroku a dlužné částky v čase")
st.line_chart(payment_details_df)
with st.expander("Zdrojova data"):
st.table(df)