|
import streamlit as st |
|
import pandas as pd |
|
import numpy as np |
|
import plotly.express as px |
|
|
|
def calculate_present_value(cash_flows, discount_rate): |
|
years = np.arange(1, len(cash_flows)+1) |
|
present_values = cash_flows / (1 + discount_rate) ** years |
|
return np.sum(present_values) |
|
|
|
st.title('PV calc') |
|
|
|
|
|
st.subheader('Ingresar los Cash Flows 10 años:') |
|
cash_flows = [] |
|
for i in range(1, 11): |
|
cash_flow = st.number_input(f"Cash Flow para el Año {i}:", value=10000.0, step=1000.0, format="%.2f") |
|
cash_flows.append(cash_flow) |
|
|
|
|
|
discount_rate = st.number_input('Ingrese la tasa de descuento (ejemplo: 0.05 para 5%):', value=0.05, step=0.01, format="%.2f") |
|
|
|
if st.button('Calcular Valor Presente'): |
|
cash_flows = np.array(cash_flows) |
|
pv = calculate_present_value(cash_flows, discount_rate) |
|
st.success(f"El valor presente calculado es: ${pv:,.2f}") |
|
|
|
|
|
df = pd.DataFrame({ |
|
'Año': np.arange(1, 11), |
|
'Cash Flow': cash_flows |
|
}) |
|
|
|
|
|
fig = px.scatter(df, x='Año', y='Cash Flow', title="Cash Flows vs. Tiempo", labels={'Cash Flow': 'Cash Flow ($)', 'Año': 'Año'}) |
|
st.plotly_chart(fig) |