CoolFace
Apppublic

PAcomem/termial_optimus

sourceHugging Facemitupdated 8mo agoView on Hugging Face
0likes
app.py67 linesDownload Raw Back to root
1import streamlit as st2import yfinance as yf3import plotly.graph_objects as go4import pandas as pd5from datetime import datetime, timedelta6 7st.set_page_config(page_title="Terminal Optimus", layout="wide")8 9# Título e interfaz10st.title("🦅 Optimus: Buscador de Market Leaders")11ticker_input = st.sidebar.text_input("Ticker de la empresa (ej: NU, MSTR, PLTR)", "NU").upper()12 13if ticker_input:14    # Obtener datos15    stock = yf.Ticker(ticker_input)16    hist = stock.history(period="2y", interval="1wk") # Gráfico Semanal como pide el método17    18    # 1. ANALISIS FUNDAMENTAL (Módulo Optimus)19    info = stock.info20    st.header(f"Análisis de {ticker_input}")21    22    col1, col2, col3, col4 = st.columns(4)23    24    # Cálculo de edad de IPO (Simplificado)25    # Buscamos ventas y márgenes26    try:27        sales_growth = info.get('revenueGrowth', 0) * 10028        market_cap = info.get('marketCap', 0) / 1e929        roe = info.get('returnOnEquity', 0) * 10030    except:31        sales_growth, market_cap, roe = 0, 0, 032 33    with col1:34        color = "inverse" if sales_growth < 20 else "normal"35        st.metric("Crecimiento Ventas", f"{sales_growth:.1f}%", delta="Target: >20%", delta_color=color)36    with col2:37        st.metric("Market Cap", f"{market_cap:.1f}B", f"Target: <30B")38    with col3:39        st.metric("ROE", f"{roe:.1f}%", "Target: >10%")40    with col4:41        st.metric("Precio Actual", f"${hist['Close'].iloc[-1]:.2f}")42 43    # 2. ANALISIS TÉCNICO PAVA44    st.subheader("Gráfico Semanal PAVA (Price & Volume Action)")45    46    fig = go.Figure()47    # Velas Japonesas48    fig.add_trace(go.Candlestick(x=hist.index, open=hist['Open'], high=hist['High'], low=hist['Low'], close=hist['Close'], name="Precio"))49    50    # Volumen con color (Rastreo Institucional)51    vol_mean = hist['Volume'].rolling(20).mean()52    colors = ['red' if row['Open'] > row['Close'] else 'green' for index, row in hist.iterrows()]53    # Resaltar volumen Optimus (2x media)54    colors = ['gold' if vol > (mean * 2) else c for vol, mean, c in zip(hist['Volume'], vol_mean, colors)]55    56    fig.add_trace(go.Bar(x=hist.index, y=hist['Volume'], name="Volumen", marker_color=colors, yaxis="y2"))57 58    fig.update_layout(59        yaxis=dict(title="Precio"),60        yaxis2=dict(title="Volumen", overlaying="y", side="right", showgrid=False),61        template="plotly_dark",62        height=60063    )64    st.plotly_chart(fig, use_container_width=True)65 66    st.success("Nota: Las barras DORADAS indican volumen institucional detectado (>2x media).")67