File size: 1,287 Bytes
2f3728d 54f2919 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
# Streamlit app layout
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) |