Sofi1606 commited on
Commit
24fd8c0
1 Parent(s): e19f157

Create app2.py

Browse files
Files changed (1) hide show
  1. app2.py +41 -0
app2.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+
6
+ # Function to compute present value
7
+ def calculate_pv(cashflows, rate):
8
+ pv = sum(cf / (1 + rate) ** i for i, cf in enumerate(cashflows))
9
+ return pv
10
+
11
+ # Streamlit app layout (nombre)
12
+ st.title('Cashflow Calculadora de valor presente')
13
+
14
+ # Input for the discount rate
15
+ rate = st.number_input('Tasa de descuento (%)', min_value=0.0, max_value=100.0, value=15.0, step=0.1)/100
16
+
17
+ # Inputs for the number of years
18
+ n = st.number_input("Cuántos años", min_value = 0, step=1)
19
+
20
+ # Inputs for the cashflows
21
+ cf_list = [0] * (n+1)
22
+ cf_dict = pd.DataFrame({"cashflows": cf_list}).astype(int)
23
+ cf_df = st.data_editor(cf_dict.T)
24
+
25
+ cashflows = np.array(cf_df.values[0])
26
+
27
+ # Button to calculate PV
28
+ if st.button('Calcula el valor presente'):
29
+ pv = calculate_pv(cashflows, rate)
30
+ st.write(f'El valor presnte es: ${pv:,.2f}')
31
+
32
+ # Prepare data for the plot
33
+ colors = ['green' if cf > 0 else 'red' for cf in cashflows]
34
+ plt.scatter(range(n+1), cashflows, c=colors)
35
+ plt.title('Cashflow Diagrama')
36
+ plt.xlabel('Periodo')
37
+ plt.ylabel('Cashflow')
38
+ for i, cf in enumerate(cashflows):
39
+ plt.annotate(f'{cf:,.2f}', (i, cf), textcoords="offset points", xytext=(0,n), ha='center')
40
+ st.pyplot(plt)
41
+