Spaces:
Sleeping
Sleeping
lavalley12
commited on
Commit
•
b184ae9
1
Parent(s):
f2d16bc
Create pv_cashflow
Browse files- pv_cashflow +39 -0
pv_cashflow
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
+
import numpy as np
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
def calcular_vpn(n, r, cash_flow):
|
8 |
+
descuento = 1 / ((1 + r) ** np.arange(1, n + 1))
|
9 |
+
vpn = np.sum(cash_flow * descuento)
|
10 |
+
return vpn
|
11 |
+
|
12 |
+
@app.route('/')
|
13 |
+
def index():
|
14 |
+
return render_template('index.html')
|
15 |
+
|
16 |
+
@app.route('/calcular', methods=['POST'])
|
17 |
+
def calcular():
|
18 |
+
data = request.get_json()
|
19 |
+
n = int(data['n'])
|
20 |
+
r = float(data['r'])
|
21 |
+
cash_flow = np.array(data['cash_flow'])
|
22 |
+
|
23 |
+
vpn = calcular_vpn(n, r, cash_flow)
|
24 |
+
|
25 |
+
plt.figure(figsize=(10, 6))
|
26 |
+
plt.plot(np.arange(1, n + 1), cash_flow, marker='o')
|
27 |
+
plt.xlabel('Años')
|
28 |
+
plt.ylabel('Cash Flow')
|
29 |
+
plt.title('Flujo de Efectivo')
|
30 |
+
plt.grid(True)
|
31 |
+
|
32 |
+
# Guardar el gráfico como imagen
|
33 |
+
img_path = 'static/plot.png'
|
34 |
+
plt.savefig(img_path)
|
35 |
+
|
36 |
+
return jsonify({'vpn': vpn, 'plot_path': img_path})
|
37 |
+
|
38 |
+
if __name__ == '__main__':
|
39 |
+
app.run(debug=True)
|