File size: 5,280 Bytes
9eebab1 2ef7c00 9eebab1 e5c0b7f 9eebab1 7b5441b 9eebab1 1a9023a 9eebab1 fe830ec 2e3198c 607b82d 9eebab1 9fc1766 2e3198c 607b82d 5781348 9eebab1 9fc1766 9eebab1 cc40fd5 f2e9f5f 3e9df64 9eebab1 fe830ec 9eebab1 f2e9f5f 3e9df64 9eebab1 3e9df64 9eebab1 6b42226 44f4cdf 6b42226 44f4cdf 9eebab1 54a8dec 9eebab1 54a8dec 9eebab1 | 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | import gradio as gr
import pandas as pd
import yfinance as yf
import plotly.graph_objects as go
from datetime import datetime, timedelta
from data import *
from config import *
from processes import *
from utils import *
# -----------------------------------------------
# CONFIGURACIÓN DE LA APP CON GRADIO
# -----------------------------------------------
generar_tickers()
with gr.Blocks(title="Análisis de Correlación") as demo:
gr.Image("https://cdn.prod.website-files.com/67174dcb1d43b06a0eae317e/672bbbc7a2b88045e5661994_logo-afi.svg", show_label=False)
gr.Markdown("# Analizador de Correlación de Bitcoin")
gr.Markdown("Explora la correlación de diferentes activos con Bitcoin y sus holdings.")
with gr.Row():
input_company = gr.Dropdown(
label="Buscar por Nombre o Ticker",
choices=tickers,
value="Strategy",
allow_custom_value=True,
interactive=True
)
texto_info1 = gr.Textbox(label="Nombre Completo:", interactive=False)
# ESTE COMPONENTE ALMACENARÁ NUESTRO ESTADO (EL TICKER)
texto_info2 = gr.Textbox(label="Ticker:", interactive=True)
input_company.change(
fn=lambda texto_completo: find_company_online(texto_completo[:6]),
inputs=input_company,
outputs=[texto_info1, texto_info2]
)
# Es buena práctica ejecutar la función al cargar para rellenar los valores iniciales
demo.load(
fn=lambda texto_completo: find_company_online(texto_completo[:6]),
inputs=input_company,
outputs=[texto_info1, texto_info2]
)
with gr.Tab("Evolución de Correlación"):
output_plot = gr.Plot(label="Gráfico de Evolución")
with gr.Row():
gr.HTML("<div style='height: 2px;'></div>")
with gr.Row():
input_step = gr.Slider(minimum=1, maximum=30, value=1, step=1, label="Indica cada cuántos días se calcula la correlación")
input_window = gr.Slider(minimum=1, maximum=60, value=12, step=1, label="Ventana rolling (meses)")
with gr.Row():
gr.HTML("<div style='height: 2px;'></div>")
with gr.Row():
gr.Markdown("## Exportar:")
gr.HTML("<div style='height: 40px;'></div>")
btn_excel = gr.Button("Descargar en Excel")
output_file = gr.File(label="Archivo Excel")
output_msg = gr.Label()
gr.on(
triggers=None, # Esto hace que se ejecute al cargar
fn=plot_evolucion_correlacion_gradio,
inputs=[texto_info2, input_step, input_window],
outputs=[output_plot, output_msg]
)
btn_excel.click(
fn=exportar_correlacion,
inputs=[texto_info2, input_step, input_window],
outputs=[output_file, output_msg]
)
with gr.Tab("Stock vs BTC"):
output_iframe_stock = gr.HTML(label="Stock vs Bitcoin Chart")
gr.Markdown("#### El Multiplicador Valor de Activos Netos (MNAV) representa el valor de liquidación de una empresa. Se calcula vendiendo todos los activos, incluyendo Bitcoin, y pagando las deudas.El Ratio MNAV compara la capitalización de mercado de la empresa con este valor de liquidación.")
gr.Markdown("#### · Ratio menor a 1.0: La empresa cotiza con un descuento.")
gr.Markdown("#### · Ratio mayor a 1.0: La empresa cotiza con una prima.")
gr.Markdown("#### Este ratio ayuda a ver si una empresa está sobrevalorada o infravalorada respecto a sus activos subyacentes.")
gr.on(
triggers=None, # Esto hace que se ejecute al cargar
fn=get_iframe_stock_vs_btc,
inputs=[texto_info2],
outputs=[output_iframe_stock]
)
with gr.Tab("Holding de Bitcoin"):
output_iframe_holdings = gr.HTML(label="Bitcoin Holdings Chart")
gr.on(
triggers=None, # Esto hace que se ejecute al cargar
fn=get_iframe_holdings,
inputs=[texto_info2],
outputs=[output_iframe_holdings]
)
with gr.Tab("Exportar Resumen Holding"):
with gr.Row():
gr.Markdown("## Top Holding:")
with gr.Row():
gr.HTML(value=f"""
<div style='display: flex; justify-content: center; gap: 200px; margin-top: 40px; margin-bottom: 40px;'>
<div>{styled_ETFs.to_html()}</div>
<div>{styled_stocks.to_html()}</div>
</div>
""")
with gr.Row():
gr.Markdown("## Exportar:")
gr.HTML("<div style='height: 40px;'></div>")
btn_descargar_resumen = gr.Button("Descargar Resumen en Excel")
output_resumen_file = gr.File(label="Archivo de Resumen de Holdings")
output_resumen_msg = gr.Label()
btn_descargar_resumen.click(
fn=lambda: descargar_resumen_holding_excel("https://docs.google.com/spreadsheets/d/1Ad3bbYQAAZO6ljkaCGTGSw5aG_FQF7Lg/edit?usp=sharing"),
inputs=[],
outputs=[output_resumen_file, output_resumen_msg]
)
# Inicia la aplicación
demo.launch(share=True) |