|
import streamlit as st |
|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
|
|
|
|
|
|
|
|
st.title("Savings account interest 💼") |
|
|
|
def calcular_cashflow(n, A, r, Pi): |
|
cashflow = [] |
|
saldo = Pi |
|
for i in range(n): |
|
interes = saldo * (r/100) |
|
abono_capital = A - interes |
|
saldo += abono_capital |
|
cashflow.append(saldo) |
|
return cashflow |
|
|
|
def graficar_cashflow(cashflow): |
|
meses = range(1, len(cashflow) + 1) |
|
fig, ax = plt.subplots() |
|
ax.plot(meses, cashflow, marker='o', linestyle='-') |
|
ax.set_title('Cashflow por Mensualidad') |
|
ax.set_xlabel('Mes') |
|
ax.set_ylabel('Saldo') |
|
ax.grid(True) |
|
return fig, ax |
|
|
|
def main(): |
|
|
|
n = st.number_input("Ingrese el número de mensualidades:", min_value=1, step=1, format='%d') |
|
A = st.number_input("Ingrese el monto de la mensualidad:", min_value=0.0, step=1.0, format='%f') |
|
r = st.number_input("Ingrese la tasa de interés (%):", min_value=0.0, step=0.01, format='%f') |
|
Pi = st.number_input("Ingrese el depósito inicial:", min_value=0.0, step=1.0, format='%f') |
|
|
|
if st.button('Calcular y Graficar Cashflow'): |
|
cashflow = calcular_cashflow(int(n), float(A), float(r), float(Pi)) |
|
fig, ax = graficar_cashflow(cashflow) |
|
st.pyplot(fig) |