File size: 1,246 Bytes
8069421
a6f8c81
 
 
ca5b5b7
a6f8c81
 
 
 
 
 
 
 
 
 
 
08beca7
 
 
 
 
 
 
a6f8c81
 
8069421
 
 
 
 
a6f8c81
8069421
869f501
08beca7
ca5b5b7
869f501
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
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt

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():
    st.title('Calculadora de Cashflow')
    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.p