import streamlit as st import yfinance as yf import plotly.express as px import pandas as pd st.set_page_config(page_title="Company Financials", layout="wide") st.title("Company Financial Dashboard") ticker_input = st.text_input("Enter Stock Ticker") # Choosing financial report type report_type = st.selectbox("Select Financial Report", ["Balance Sheet", "Income Statement", "Cash Flow"]) if ticker_input: try: ticker = yf.Ticker(ticker_input) if report_type == "Balance Sheet": df = ticker.balance_sheet elif report_type == "Income Statement": df = ticker.financials else: df = ticker.cashflow if df.empty: st.warning("No financial data available for this selection.") else: st.subheader(f"{report_type} for {ticker_input.upper()}") st.dataframe(df, use_container_width=True) df_plot = pd.DataFrame( df.T, pd.to_datetime(df.T.index) ) metric = st.selectbox("Select Metric to Visualize", df_plot.columns) if metric: fig = px.line( df_plot, x=df_plot.index, y=metric, title=f"{metric}", markers=True, labels={metric: metric, "index": "Date"} ) st.plotly_chart(fig, use_container_width=True) except Exception as e: st.error(f"Error: {e}")