|
import streamlit as st |
|
import numpy as np |
|
import pandas as pd |
|
|
|
def calculate_returns(y_initial, A, T, changes_in_interest_rate): |
|
|
|
z = np.arange(T+1) |
|
r_c = np.zeros(T+1) |
|
interest_rate = y_initial / (12 * 100) |
|
interest_rates = [interest_rate] * (T+1) |
|
for month in range(T+1): |
|
for change_month, new_interest_rate in changes_in_interest_rate.items(): |
|
if month >= change_month: |
|
interest_rate = new_interest_rate / (12 * 100) |
|
interest_rates[month] = interest_rate |
|
r_c[month] = A * np.exp(interest_rate * month) |
|
return z, r_c, interest_rates |
|
|
|
def main(): |
|
st.title('App de pruebas 🏦') |
|
|
|
|
|
y_initial = st.number_input("Escribe la tasa de interés nominal inicial (%):") |
|
|
|
|
|
A = st.number_input("Escribe la cantidad que ahorrarás ($):") |
|
|
|
|
|
T = st.number_input("Escribe cuantos meses quieres ver:", min_value=1, step=1, format="%f") |
|
|
|
|
|
change_month = st.number_input("Mes en el que cambia la tasa de interés (dejar en blanco si no hay cambios):", min_value=1, max_value=T, value=1, step=1) |
|
|
|
|
|
changes_in_interest_rate = {} |
|
|
|
|
|
if change_month != 1: |
|
new_interest_rate = st.number_input(f"Nueva tasa de interés a partir del mes {change_month} (%):") |
|
changes_in_interest_rate[change_month] = new_interest_rate |
|
|
|
|
|
z, r_c, interest_rates = calculate_returns(y_initial, A, T, changes_in_interest_rate) |
|
|
|
|
|
new_dict = {"Mes": z, "Tasa de Interés (%)": interest_rates, "Retorno continuo": r_c} |
|
df = pd.DataFrame(new_dict) |
|
|
|
|
|
st.dataframe(df) |
|
st.write(f"En {T} meses tendrás $ {r_c[-1]}") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|