Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
|
6 |
+
# Streamlit app layout
|
7 |
+
st.title("Insurance Payment with Savings 💼")
|
8 |
+
|
9 |
+
# Create the inputs (A, r, n)
|
10 |
+
monthly_payment = st.number_input("Desired monthly payment:")
|
11 |
+
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 |
+
present_value = (monthly_payment * 12 / interest_rate) * (1 - (1 / (1 + interest_rate/12)**months))
|
16 |
+
|
17 |
+
# Display the present value
|
18 |
+
st.write(f"The present value is {present_value:,.2f} using the discrete model")
|
19 |
+
|
20 |
+
# Cashflow DataFrame
|
21 |
+
cashflows = [-present_value] + [monthly_payment] * months
|
22 |
+
cf_df = pd.DataFrame({"cashflows": cashflows}).astype(float)
|
23 |
+
st.dataframe(cf_df.T)
|
24 |
+
|
25 |
+
# Plot the Cashflow Diagram
|
26 |
+
colors = ["green" if cf > 0 else "red" for cf in cf_df.cashflows]
|
27 |
+
plt.scatter(range(months + 1), cf_df.cashflows, c=colors)
|
28 |
+
plt.title("Cashflow Diagram")
|
29 |
+
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)
|