mauvb21 commited on
Commit
896b7ac
·
verified ·
1 Parent(s): 69826ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -17
app.py CHANGED
@@ -1,31 +1,55 @@
1
- import streamlit as st
2
  import numpy as np
3
  import pandas as pd
 
4
 
5
- st.title('Cashflow App')
6
 
7
- y = st.number_input("Escribe la tasa de interés nominal (%):")
8
 
9
- A = st.number_input("Escribe la cantidad que ahorrarás ($):")
10
 
11
- T = st.number_input("Escribe el número de años que quieres ver: ",
12
- step=1)
13
 
14
- z = np.arange(T+1)
15
 
16
- r_d = A * (1 + y/(12*100))**z
17
 
18
- r_c = A * np.exp(y*z/(12*100))
19
 
20
- future_value = A * ((1 + y) ** T)
21
 
22
- new_dict = {"Año": z,
23
- "Retorno Discreto": r_d,
24
- "Retorno Continuo": r_c}
25
 
26
- df= pd.DataFrame(new_dict)
27
- df.columns = new_dict.keys()
28
 
29
- st.dataframe(df)
30
 
31
- st.write(f"En {T} tendrás un valor futuro de $ {future_value}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
  import numpy as np
3
  import pandas as pd
4
+ import matplotlib.pyplot as plt
5
 
 
6
 
7
+ # Streamlit app layout
8
 
9
+ st.title("Paying insurance with my savings account 💼")
10
 
11
+ # Create the inputs (A, r, n)
 
12
 
13
+ A = st.number_input("How much do you want monthly?")
14
 
15
+ r = st.number_input("What is the interest rate?")
16
 
17
+ n = int(st.number_input("For how many months?", step = 1))
18
 
 
19
 
20
+ # Create the outputs
 
 
21
 
22
+ Pn_d = (A * 12 / r) * (1 - (1 / (1 + r/12)**n))
 
23
 
24
+ # Pn_c = (A / (np.exp(r/12) - 1)) * (1 - np.exp(- r * n / 12))
25
 
26
+
27
+ # Print the outputs
28
+
29
+ st.write(f"The value of P is {Pn_d:,.2f} with discrete model")
30
+
31
+ # st.write(f"The value of P is {Pn_c:,.2f} with continuous model")
32
+
33
+
34
+ # Draw the plot
35
+
36
+ cf_list = [-Pn_d] + [A] * n
37
+ cf_dict = pd.DataFrame({"cashflows": cf_list}).astype(float)
38
+ cf_df = st.dataframe(cf_dict.T)
39
+
40
+ # Prepare data for the plot
41
+ colors = ["green" if cf > 0 else "red" for cf in cf_dict.cashflows]
42
+ plt.scatter(range(n + 1), cf_dict.cashflows, c=colors)
43
+ plt.title("Cashflow Diagram")
44
+ plt.xlabel("Period")
45
+ plt.ylabel("Cashflow")
46
+ for i, cf in enumerate(cf_dict.cashflows):
47
+ plt.annotate(
48
+ f"{cf:,.2f}",
49
+ (i, cf),
50
+ textcoords="offset points",
51
+ xytext=(0, n),
52
+ ha="center",
53
+ )
54
+ st.pyplot(plt)
55
+ 😘