Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,61 @@
|
|
1 |
-
|
2 |
import numpy as np
|
3 |
-
import
|
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 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
import numpy as np
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
def analizar_inversiones(lista1, lista2):
|
6 |
+
# Convertir las listas en arrays numpy
|
7 |
+
array1 = np.array(lista1)
|
8 |
+
array2 = np.array(lista2)
|
9 |
+
|
10 |
+
# Calcular desviación estándar
|
11 |
+
std_dev1 = np.std(array1)
|
12 |
+
std_dev2 = np.std(array2)
|
13 |
+
|
14 |
+
# Calcular valor esperado
|
15 |
+
mean1 = np.mean(array1)
|
16 |
+
mean2 = np.mean(array2)
|
17 |
+
|
18 |
+
# Calcular correlación
|
19 |
+
correlation = np.corrcoef(array1, array2)[0, 1]
|
20 |
+
|
21 |
+
# Crear gráfica
|
22 |
+
fig, ax = plt.subplots()
|
23 |
+
ax.scatter(array1, array2)
|
24 |
+
ax.set_xlabel('Lista 1')
|
25 |
+
ax.set_ylabel('Lista 2')
|
26 |
+
ax.set_title('Investment graph')
|
27 |
+
ax.grid(True)
|
28 |
+
st.pyplot(fig)
|
29 |
+
|
30 |
+
# Decidir a cuál invertir más y a cuál menos
|
31 |
+
if mean1 > mean2:
|
32 |
+
invertir_mas = "List 1"
|
33 |
+
invertir_menos = "List 2"
|
34 |
+
else:
|
35 |
+
invertir_mas = "List 2"
|
36 |
+
invertir_menos = "List 1"
|
37 |
+
|
38 |
+
# Mostrar resultados con un formato agradable
|
39 |
+
st.write("Results of the Analisis:")
|
40 |
+
st.write(f"Standar desviation of list 1: {std_dev1}")
|
41 |
+
st.write(f"Standar desviation of list 2: {std_dev2}")
|
42 |
+
st.write(f"Estimated value list 1: {mean1}")
|
43 |
+
st.write(f"Estimated value list 2: {mean2}")
|
44 |
+
st.write(f"Correlation: {correlation}")
|
45 |
+
st.write(f"Invest more in: {invertir_mas}")
|
46 |
+
st.write(f"Invest less in: {invertir_menos}")
|
47 |
+
|
48 |
+
def main():
|
49 |
+
st.title("Portfolio")
|
50 |
+
st.write("Isert the values for the lists:")
|
51 |
+
|
52 |
+
# Solicitar al usuario que ingrese los valores de las listas
|
53 |
+
lista1 = [st.number_input(f"List 1 - Value {i+1}", value=0.0) for i in range(10)]
|
54 |
+
lista2 = [st.number_input(f"List 2 - Value {i+1}", value=0.0) for i in range(10)]
|
55 |
+
|
56 |
+
# Botón para realizar el análisis
|
57 |
+
if st.button("Make Analisis"):
|
58 |
+
analizar_inversiones(lista1, lista2)
|
59 |
+
|
60 |
+
if _name_ == "_main_":
|
61 |
+
main()
|