Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,15 @@ interest_rate = st.number_input("Interest rate (%):")
|
|
12 |
months = int(st.number_input("Number of months:", step=1))
|
13 |
|
14 |
# Calculate the present value
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Display the present value
|
18 |
st.write(f"The present value is {present_value:,.2f} using the discrete model")
|
@@ -30,4 +38,4 @@ plt.xlabel("Period")
|
|
30 |
plt.ylabel("Cashflow")
|
31 |
for i, cf in enumerate(cf_df.cashflows):
|
32 |
plt.annotate(f"{cf:,.2f}", (i, cf), textcoords="offset points", xytext=(0, months), ha="center")
|
33 |
-
st.pyplot(plt)
|
|
|
12 |
months = int(st.number_input("Number of months:", step=1))
|
13 |
|
14 |
# Calculate the present value
|
15 |
+
if interest_rate == 0:
|
16 |
+
st.error("Interest rate cannot be zero.")
|
17 |
+
st.stop()
|
18 |
+
|
19 |
+
try:
|
20 |
+
present_value = (monthly_payment * 12 / interest_rate) * (1 - (1 / (1 + interest_rate/12)**months))
|
21 |
+
except ZeroDivisionError:
|
22 |
+
st.error("Please enter a non-zero interest rate.")
|
23 |
+
st.stop()
|
24 |
|
25 |
# Display the present value
|
26 |
st.write(f"The present value is {present_value:,.2f} using the discrete model")
|
|
|
38 |
plt.ylabel("Cashflow")
|
39 |
for i, cf in enumerate(cf_df.cashflows):
|
40 |
plt.annotate(f"{cf:,.2f}", (i, cf), textcoords="offset points", xytext=(0, months), ha="center")
|
41 |
+
st.pyplot(plt)
|