|
import streamlit as st |
|
import numpy as np |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
|
|
|
|
def calcular_vp(flujos_de_efectivo, tasa): |
|
vp = sum(cf / (1 + tasa) ** i for i, cf in enumerate(flujos_de_efectivo)) |
|
return vp |
|
|
|
|
|
st.title('Calculadora de Valor Presente de Flujos de Efectivo') |
|
|
|
|
|
tasa = st.number_input('Tasa de Descuento (%)', min_value=0.0, max_value=100.0, value=15.0, step=0.1)/100 |
|
|
|
|
|
n = st.number_input("¿Cuántos años?", min_value=0, step=1) |
|
|
|
|
|
flujos_efectivo_lista = [0] * (n+1) |
|
flujos_efectivo_dict = pd.DataFrame({"flujos_efectivo": flujos_efectivo_lista}).astype(int) |
|
flujos_efectivo_df = st.dataframe(flujos_efectivo_dict.T) |
|
|
|
flujos_de_efectivo = np.array(flujos_efectivo_df.values[0]) |
|
|
|
|
|
if st.button('Calcular Valor Presente'): |
|
vp = calcular_vp(flujos_de_efectivo, tasa) |
|
st.write(f'El Valor Presente es: ${vp:,.2f}') |
|
|
|
|
|
colores = ['green' if cf > 0 else 'red' for cf in flujos_de_efectivo] |
|
plt.scatter(range(n+1), flujos_de_efectivo, c=colores) |
|
plt.title('Diagrama de Flujos de Efectivo') |
|
plt.xlabel('Periodo') |
|
plt.ylabel('Flujo de Efectivo') |
|
for i, cf in enumerate(flujos_de_efectivo): |
|
plt.annotate(f'{cf:,.2f}', (i, cf), textcoords="offset points", xytext=(0,n), ha='center') |
|
st.pyplot(plt) |