Skkinycalvs commited on
Commit
748fc1b
1 Parent(s): effc78f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -50
app.py CHANGED
@@ -1,69 +1,57 @@
1
  import streamlit as st
2
- import numpy as np
3
  import pandas as pd
 
4
 
5
- st.title('App de prueba 👻')
6
-
7
- # Obtener la tasa de interés inicial y la cantidad inicial
8
- tasa_inicial = st.number_input("Escribe la tasa de interés nominal inicial (%):")
9
- A = st.number_input("Escribe la cantidad que ahorrarás ($):")
10
- T = st.number_input("Escribe cuantos meses quieres ver:")
11
-
12
- tasas_variables = []
13
-
14
- # Permitir al usuario ingresar tasas variables
15
- for i in range(int(T)):
16
- tasa = st.number_input(f"Tasa de interés nominal para el mes {i+1} (%):", key=f"tasa_{i}")
17
- tasas_variables.append(tasa)
18
-
19
- z = np.arange(T)
20
 
21
- # Calcular los retornos para tasas variables
22
- r_d = []
23
- r_c = []
 
 
 
 
 
 
 
24
 
25
- for i in range(int(T)):
26
- retorno_discreto = A * (1 + tasas_variables[i]/(12*100))**i
27
- retorno_continuo = A * np.exp(tasas_variables[i]/(12*100) * i)
28
-
29
- print(f"Mes {i+1}: retorno_continuo = {retorno_continuo}")
30
-
31
- r_d.append(retorno_discreto)
32
- r_c.append(retorno_continuo)
33
 
34
- print("Longitud de r_c:", len(r_c))
 
35
 
36
- print("r_d:", r_d)
37
- print("r_c:", r_c)
38
 
39
- new_dict = {"Mes": z, "Retorno discreto": r_d, "Retorno continuo": r_c}
 
40
 
41
- df = pd.DataFrame(new_dict)
 
 
 
 
42
 
43
- st.dataframe(df)
 
 
44
 
45
- if len(r_c) > 0:
46
- st.write(f"En {T} meses tendrás $ {r_c[-1]}")
47
- else:
48
- st.write("Aún no se han calculado los retornos.")
49
 
50
- import matplotlib.pyplot as plt
 
51
 
52
- # Crear la figura y los ejes
53
- fig, ax = plt.subplots()
 
 
 
54
 
55
- # Trazar la evolución del crecimiento de la inversión
56
- ax.plot(df["Mes"], df["Retorno discreto"], label="Retorno discreto", marker='o')
57
- ax.plot(df["Mes"], df["Retorno continuo"], label="Retorno continuo", marker='x')
58
 
59
- # Agregar etiquetas y leyenda
60
- ax.set_xlabel('Mes')
61
- ax.set_ylabel('Retorno')
62
- ax.set_title('Evolución del crecimiento de la inversión')
63
- ax.legend()
64
 
65
- # Mostrar la gráfica
66
- st.pyplot(fig)
67
 
68
 
69
 
 
1
  import streamlit as st
2
+ import numpy as np
3
  import pandas as pd
4
+ import matplotlib.pyplot as plt
5
 
6
+ st.title("Investment app ")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ A = st.number_input(
9
+ "Insert the initial investment (in $): "
10
+ )
11
+ r = st.number_input(
12
+ "Insert the interest rate (nominal in %): "
13
+ )
14
+ T = st.number_input(
15
+ "Insert the number of months of your investment: ",
16
+ step=1
17
+ )
18
 
19
+ # Numpy array with the months
20
+ t = np.arange(T + 1)
 
 
 
 
 
 
21
 
22
+ # Numpy array for the interest rate
23
+ r_list = np.array([r] * len(t))
24
 
25
+ # Numpy array with the returns for each month in t
26
+ y = A * (1 + (r_list / (12*100)))**t
27
 
28
+ # Numpy array with the continuously compunded returns
29
+ y_c = A * np.exp(r_list * t / (12*100))
30
 
31
+ # Create the investment dictionary
32
+ inv_dict = {"Month": t,
33
+ "Rate": r_list,
34
+ "Returns": y,
35
+ "Continuous returns": y_c}
36
 
37
+ # Create the investment dataframe
38
+ inv_df = pd.DataFrame(inv_dict)
39
+ inv_df.columns = inv_dict.keys()
40
 
41
+ st.write(f"Table with returns at an interest rate of {r}")
42
+ new_df = st.data_editor(inv_df)
 
 
43
 
44
+ new_y = [A]
45
+ new_y_c = [A]
46
 
47
+ for i in range(1, len(t)):
48
+ r_temp = new_df["Rate"].values[i]
49
+ # New numpy array with the returns for each month in t
50
+ val = new_y[i-1] * (1 + r_temp / (12*100))
51
+ new_y.append(val)
52
 
 
 
 
53
 
 
 
 
 
 
54
 
 
 
55
 
56
 
57