Spaces:
Sleeping
Sleeping
File size: 1,879 Bytes
a5ca742 |
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 |
import streamlit as st
import plotly.graph_objects as go
import yfinance as yf
import pandas as pd
from datetime import datetime, timedelta
from data_fetcher import get_stock_data, get_company_info
from visualization import create_stock_chart, create_metrics_table
import styles
def main():
# Apply custom styles
styles.apply_custom_styles()
st.title("📈 Stock Analysis Terminal")
# Stock Symbol Input
symbol = st.text_input("Enter Stock Symbol (e.g., AAPL)", "").upper()
if symbol:
try:
# Fetch stock data
stock_data = get_stock_data(symbol)
company_info = get_company_info(symbol)
# Display company info
col1, col2 = st.columns(2)
with col1:
st.subheader(company_info.get('longName', symbol))
st.write(f"Sector: {company_info.get('sector', 'N/A')}")
with col2:
st.metric(
"Current Price",
f"${stock_data['Close'].iloc[-1]:.2f}",
f"{((stock_data['Close'].iloc[-1] / stock_data['Close'].iloc[-2]) - 1) * 100:.2f}%"
)
# Stock Chart
st.plotly_chart(create_stock_chart(stock_data, symbol), use_container_width=True)
# Financial Metrics Table
metrics_df = create_metrics_table(company_info)
st.dataframe(metrics_df, use_container_width=True)
# Download button for CSV
csv = stock_data.to_csv(index=True)
st.download_button(
label="Download Data as CSV",
data=csv,
file_name=f"{symbol}_stock_data.csv",
mime="text/csv"
)
except Exception as e:
st.error(f"Error retrieving data for {symbol}: {str(e)}")
if __name__ == "__main__":
main() |