Skip to content

Commit 96b8de3

Browse files
committed
Add Header
1 parent 960fb9e commit 96b8de3

File tree

1 file changed

+66
-9
lines changed

1 file changed

+66
-9
lines changed

src/ui/layout.py

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,8 @@ def render_footer():
2727

2828

2929
def render_stock_info(financial_data):
30-
stock_info = financial_data.get_stock_info(
31-
st.session_state["ticker"],
32-
)
3330
# Render header
34-
st.markdown(
35-
f"### {stock_info['symbol']} - {stock_info['longName']}", unsafe_allow_html=True
36-
)
31+
render_header(financial_data)
3732
# Renders tabs
3833
tab_titles = ["Overview", "Balance Sheet", "Income Statement", "CashFlow"]
3934
tabs_renderings = [
@@ -48,6 +43,31 @@ def render_stock_info(financial_data):
4843
render_action(financial_data)
4944

5045

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+
5171
def render_overview(financial_data):
5272
ticker = st.session_state["ticker"]
5373
historical_data = financial_data.get_historical_data(
@@ -57,12 +77,14 @@ def render_overview(financial_data):
5777
interval="1d",
5878
)
5979
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")
6181

62-
with col1:
82+
with stock_performance:
83+
st.markdown("#### Stock Performance")
6384
st.line_chart(historical_data, x_label="Date", y_label="Price")
6485

65-
with col2:
86+
with ratios_summary:
87+
st.markdown("#### Summary")
6688
st.write("Placeholder for Company Summary")
6789

6890
with st.container():
@@ -82,3 +104,38 @@ def render_income_stmt(financial_data):
82104
def render_cashflow(financial_data):
83105
cashflow = financial_data.get_cashflow(st.session_state["ticker"])
84106
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

Comments
 (0)