Update app.py
Browse files
app.py
CHANGED
@@ -4,33 +4,33 @@ import numpy as np
|
|
4 |
import plotly.express as px
|
5 |
|
6 |
def calculate_present_value(cash_flows, discount_rate):
|
7 |
-
years = np.arange(1, len(cash_flows)+1)
|
8 |
present_values = cash_flows / (1 + discount_rate) ** years
|
9 |
return np.sum(present_values)
|
10 |
|
11 |
-
st.title('
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
cash_flows =
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Input del usuario para la tasa de descuento
|
21 |
-
discount_rate = st.number_input('
|
22 |
|
|
|
23 |
if st.button('Calcular Valor Presente'):
|
24 |
-
|
|
|
25 |
pv = calculate_present_value(cash_flows, discount_rate)
|
26 |
st.success(f"El valor presente calculado es: ${pv:,.2f}")
|
27 |
|
28 |
-
# Crear DataFrame para visualización
|
29 |
-
df = pd.DataFrame({
|
30 |
-
'Año': np.arange(1, 11),
|
31 |
-
'Cash Flow': cash_flows
|
32 |
-
})
|
33 |
-
|
34 |
# Gráfico
|
35 |
-
fig = px.scatter(
|
36 |
st.plotly_chart(fig)
|
|
|
4 |
import plotly.express as px
|
5 |
|
6 |
def calculate_present_value(cash_flows, discount_rate):
|
7 |
+
years = np.arange(1, len(cash_flows) + 1)
|
8 |
present_values = cash_flows / (1 + discount_rate) ** years
|
9 |
return np.sum(present_values)
|
10 |
|
11 |
+
st.title('Calculadora de Valor Presente')
|
12 |
|
13 |
+
# Inicializar DataFrame para cash flows
|
14 |
+
if 'cash_flows' not in st.session_state:
|
15 |
+
st.session_state.cash_flows = pd.DataFrame({
|
16 |
+
'Año': range(1, 11),
|
17 |
+
'Cash Flow': [10000.0] * 10 # Inicializar con un valor default
|
18 |
+
})
|
19 |
+
|
20 |
+
# Mostrar la tabla editable
|
21 |
+
st.subheader('Ingrese los Cash Flows anuales:')
|
22 |
+
cash_flow_table = st.dataframe(st.session_state.cash_flows)
|
23 |
|
24 |
# Input del usuario para la tasa de descuento
|
25 |
+
discount_rate = st.number_input('Ingrese la tasa de descuento (ejemplo: 0.05 para 5%):', value=0.05, step=0.01, format="%.2f")
|
26 |
|
27 |
+
# Botón para calcular el valor presente
|
28 |
if st.button('Calcular Valor Presente'):
|
29 |
+
# Extraer los cash flows desde la tabla
|
30 |
+
cash_flows = st.session_state.cash_flows['Cash Flow'].values
|
31 |
pv = calculate_present_value(cash_flows, discount_rate)
|
32 |
st.success(f"El valor presente calculado es: ${pv:,.2f}")
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# Gráfico
|
35 |
+
fig = px.scatter(st.session_state.cash_flows, x='Año', y='Cash Flow', title="Cash Flows vs. Tiempo", labels={'Cash Flow': 'Cash Flow ($)', 'Año': 'Año'})
|
36 |
st.plotly_chart(fig)
|