@@ -27,13 +27,8 @@ def render_footer():
27
27
28
28
29
29
def render_stock_info (financial_data ):
30
- stock_info = financial_data .get_stock_info (
31
- st .session_state ["ticker" ],
32
- )
33
30
# Render header
34
- st .markdown (
35
- f"### { stock_info ['symbol' ]} - { stock_info ['longName' ]} " , unsafe_allow_html = True
36
- )
31
+ render_header (financial_data )
37
32
# Renders tabs
38
33
tab_titles = ["Overview" , "Balance Sheet" , "Income Statement" , "CashFlow" ]
39
34
tabs_renderings = [
@@ -48,6 +43,31 @@ def render_stock_info(financial_data):
48
43
render_action (financial_data )
49
44
50
45
46
+ def render_header (financial_data ):
47
+ stock_info = financial_data .get_stock_info (
48
+ st .session_state ["ticker" ],
49
+ )
50
+ st .markdown (
51
+ f"### { stock_info ['symbol' ]} - { stock_info ['longName' ]} " , unsafe_allow_html = True
52
+ )
53
+ # Render price change
54
+ current_price = stock_info ["currentPrice" ]
55
+ previous_close_price = stock_info ["previousClose" ]
56
+ currency = stock_info ["currency" ]
57
+ current_price_content = f"{ convert_currency_symbol (currency )} { current_price } "
58
+ price_diff = calculate_price_changes (current_price , previous_close_price )
59
+ price_diff_content = f"({ price_diff } %)"
60
+ price_change_content = (
61
+ apply_text_color (price_diff_content , "red" )
62
+ if price_diff < 0
63
+ else apply_text_color (price_diff_content , "green" )
64
+ )
65
+ st .markdown (
66
+ f"##### { current_price_content } { price_change_content } " ,
67
+ unsafe_allow_html = True ,
68
+ )
69
+
70
+
51
71
def render_overview (financial_data ):
52
72
ticker = st .session_state ["ticker" ]
53
73
historical_data = financial_data .get_historical_data (
@@ -57,12 +77,14 @@ def render_overview(financial_data):
57
77
interval = "1d" ,
58
78
)
59
79
quotes = financial_data .get_stock_info (ticker )
60
- col1 , col2 = st .columns (2 , gap = "large" )
80
+ stock_performance , ratios_summary = st .columns (2 , gap = "large" )
61
81
62
- with col1 :
82
+ with stock_performance :
83
+ st .markdown ("#### Stock Performance" )
63
84
st .line_chart (historical_data , x_label = "Date" , y_label = "Price" )
64
85
65
- with col2 :
86
+ with ratios_summary :
87
+ st .markdown ("#### Summary" )
66
88
st .write ("Placeholder for Company Summary" )
67
89
68
90
with st .container ():
@@ -82,3 +104,38 @@ def render_income_stmt(financial_data):
82
104
def render_cashflow (financial_data ):
83
105
cashflow = financial_data .get_cashflow (st .session_state ["ticker" ])
84
106
st .dataframe (cashflow )
107
+
108
+
109
+ def convert_currency_symbol (currency_symbol ):
110
+ currency = {
111
+ "USD" : "$" , # US Dollar
112
+ "EUR" : "€" , # Euro
113
+ "JPY" : "¥" , # Japanese Yen
114
+ "GBP" : "£" , # British Pound Sterling
115
+ "AUD" : "A$" , # Australian Dollar
116
+ "CAD" : "C$" , # Canadian Dollar
117
+ "CHF" : "CHF" , # Swiss Franc
118
+ "CNY" : "¥" , # Chinese Yuan Renminbi
119
+ "HKD" : "HK$" , # Hong Kong Dollar
120
+ "INR" : "₹" , # Indian Rupee
121
+ "RUB" : "₽" , # Russian Ruble
122
+ "BRL" : "R$" , # Brazilian Real
123
+ "ZAR" : "R" , # South African Rand
124
+ "KRW" : "₩" , # South Korean Won
125
+ "MXN" : "$" , # Mexican Peso
126
+ "SGD" : "S$" , # Singapore Dollar
127
+ "NZD" : "NZ$" , # New Zealand Dollar
128
+ "TRY" : "₺" , # Turkish Lira
129
+ "SEK" : "kr" , # Swedish Krona
130
+ "NOK" : "kr" , # Norwegian Krone
131
+ }
132
+
133
+ return currency [currency_symbol ]
134
+
135
+
136
+ def calculate_price_changes (current_price , previous_close_price ):
137
+ return round ((current_price - previous_close_price ) / previous_close_price , 2 ) * 100
138
+
139
+
140
+ def apply_text_color (text , color ):
141
+ return f"<span style='color:{ color } '>{ text } </span>"
0 commit comments