File size: 5,000 Bytes
50e9fe0
 
7b70d02
 
 
 
50e9fe0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4236398
50e9fe0
7b70d02
e458064
7b70d02
803210e
 
 
 
 
 
 
 
 
4236398
50e9fe0
 
803210e
 
 
 
 
 
 
 
 
 
 
 
 
c119a98
803210e
 
50e9fe0
 
 
 
 
 
 
 
 
803210e
50e9fe0
 
803210e
50e9fe0
 
 
803210e
50e9fe0
 
803210e
50e9fe0
 
 
803210e
50e9fe0
 
803210e
 
 
50e9fe0
803210e
 
50e9fe0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
145
146
147
148
149
"""Financial Analysis Dashboard - Main Application."""

import streamlit as st
from dotenv import load_dotenv
import os

from styles import DARK_THEME_CSS
from data import (
    load_stock_data,
    load_company_profile,
    load_income_statement,
    calculate_technical_indicators,
    get_price_metrics,
)
from charts import (
    create_price_chart,
    create_rsi_chart,
    create_financial_chart,
)
from ui import (
    display_price_metrics,
    display_company_info,
    display_financial_metrics,
    display_income_statement,
    display_profitability_metrics,
)


# ---- Configuration ----
load_dotenv()
token = os.getenv("TOKEN")

st.set_page_config(
    page_title="Financial Dashboard",
    page_icon="πŸ“ˆ",
    layout="wide",
    initial_sidebar_state="expanded",
    menu_items={
        "About": "A professional financial analysis dashboard with technical indicators"
    }
)

# ---- Apply Dark Theme ----
st.markdown(DARK_THEME_CSS, unsafe_allow_html=True)

# ---- Header ----
st.markdown("# πŸ“ˆ Financial Analysis Dashboard")
st.markdown("Real-time technical analysis with multiple indicators")

# ---- Sidebar Configuration ----
with st.sidebar:
    st.markdown("## βš™οΈ Settings")
    symbol = st.text_input("Stock Ticker", "AAPL", help="Enter a valid stock ticker symbol").upper()
    period = st.slider("Indicator Period", 5, 50, 20, help="Period for SMA, EMA, and RSI calculations")

    st.markdown("---")
    st.markdown("### About")
    st.info("This dashboard provides real-time technical analysis with comprehensive financial metrics.")


def main():
    """Main application logic."""
    if st.button("οΏ½οΏ½ Load Dashboard", key="load_btn", use_container_width=True):
        try:
            # Load data
            with st.spinner("Loading data..."):
                df = load_stock_data(symbol)
                profile_info = load_company_profile(symbol)
                income_stmt = load_income_statement(symbol)

            # Calculate technical indicators
            df = calculate_technical_indicators(df, period)

            # Display price metrics
            metrics = get_price_metrics(df)
            display_price_metrics(metrics)

            # Display company information
            display_company_info(profile_info)

            # Display financial metrics
            if not income_stmt.empty:
                display_financial_metrics(income_stmt)

                # Financial history chart
                st.markdown('<div class="section-title">πŸ“Š Revenue & Net Income Trend</div>', unsafe_allow_html=True)
                income_chart_data = income_stmt[['period_ending', 'total_revenue', 'net_income']].dropna()

                if len(income_chart_data) > 0:
                    fig_financial = create_financial_chart(income_chart_data)
                    st.plotly_chart(fig_financial, use_container_width=True)

            # ---- Tabs ----
            tab1, tab2, tab3, tab4 = st.tabs([
                "πŸ“ˆ Price & Moving Averages",
                "πŸ“Š RSI Indicator",
                "πŸ“‰ TradingView",
                "πŸ“‹ Financials"
            ])

            # Tab 1: Price & Moving Averages
            with tab1:
                fig_price = create_price_chart(df, symbol, period)
                st.plotly_chart(fig_price, use_container_width=True)

            # Tab 2: RSI Indicator
            with tab2:
                fig_rsi = create_rsi_chart(df, symbol)
                st.plotly_chart(fig_rsi, use_container_width=True)

            # Tab 3: TradingView
            with tab3:
                tradingview_html = f"""
                <div class="tradingview-widget-container">
                  <div id="tradingview_{symbol}"></div>
                  <script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
                  <script type="text/javascript">
                    new TradingView.widget({{
                      "width": "100%",
                      "height": 600,
                      "symbol": "{symbol}",
                      "interval": "D",
                      "timezone": "Etc/UTC",
                      "theme": "dark",
                      "style": "1",
                      "locale": "en",
                      "enable_publishing": false,
                      "allow_symbol_change": true,
                      "container_id": "tradingview_{symbol}"
                    }});
                  </script>
                </div>
                """
                st.components.v1.html(tradingview_html, height=650)

            # Tab 4: Detailed Financials
            with tab4:
                if not income_stmt.empty:
                    display_income_statement(income_stmt)
                    display_profitability_metrics(income_stmt)

        except Exception as e:
            st.error(f"Error loading data for {symbol}: {str(e)}")
            st.info("Please check the ticker symbol and try again.")


if __name__ == "__main__":
    main()