File size: 1,343 Bytes
8069421
a6f8c81
 
 
2d86d18
 
 
 
 
ca5b5b7
a6f8c81
 
 
 
 
 
 
 
 
 
 
08beca7
 
 
 
 
 
 
a6f8c81
 
dbe4ee3
8069421
 
 
 
a6f8c81
8069421
869f501
08beca7
91c29ab
869f501
91c29ab
 
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
41
42
43
44
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt


# Streamlit app layout

st.title("Paying insurance with my savings account 💼")

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)

if __name__ == "__main__":
    main()