Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,6 @@ from datetime import datetime
|
|
| 15 |
st.set_page_config(page_title='Stocks Analysis', layout='wide', page_icon=':rocket:')
|
| 16 |
|
| 17 |
st.sidebar.title("Stock Option")
|
| 18 |
-
# Custom CSS to change the sidebar color
|
| 19 |
sidebar_css = """
|
| 20 |
<style>
|
| 21 |
div[data-testid="stSidebar"] > div:first-child {
|
|
@@ -120,8 +119,6 @@ try:
|
|
| 120 |
else:
|
| 121 |
st.write("Price-to-Book (P/B) Ratio information not available for this stock.")
|
| 122 |
|
| 123 |
-
## ............................................... ##
|
| 124 |
-
# Display more detailed information
|
| 125 |
st.subheader('Company Summary')
|
| 126 |
if 'longBusinessSummary' in stock_info:
|
| 127 |
LongBusinessSummary = stock_info['longBusinessSummary']
|
|
@@ -157,11 +154,8 @@ try:
|
|
| 157 |
else:
|
| 158 |
st.write("Company Officers information not available for this stock.")
|
| 159 |
|
| 160 |
-
## ............................................... ##
|
| 161 |
-
# Display the latest news
|
| 162 |
st.subheader('Latest News')
|
| 163 |
|
| 164 |
-
# Prepare the data for the DataFrame
|
| 165 |
news_data_for_dataframe = []
|
| 166 |
for news_item in news_data:
|
| 167 |
news_title = news_item['title']
|
|
@@ -171,30 +165,21 @@ try:
|
|
| 171 |
news_link = f"[Link]({news_item['link']})"
|
| 172 |
news_data_for_dataframe.append([news_title, news_publisher, news_provider_publish_time, news_type, news_link])
|
| 173 |
|
| 174 |
-
# Create a Pandas DataFrame
|
| 175 |
df = pd.DataFrame(news_data_for_dataframe, columns=["Title", "Publisher", "Provider Publish Time", "Type", "Link"])
|
| 176 |
|
| 177 |
-
# Display the DataFrame using Markdown without the index column
|
| 178 |
st.markdown(df.to_markdown(index=False), unsafe_allow_html=True)
|
| 179 |
|
| 180 |
-
## ............................................... ##
|
| 181 |
-
# Enhanced title with larger font size and a different color
|
| 182 |
title = f"<h1 style='color: white; font-size: 25px; text-align: center; '>{stock_name}'s Technical Analysis</h1>"
|
| 183 |
st.markdown(title, unsafe_allow_html=True)
|
| 184 |
|
| 185 |
with st.expander("Expand"):
|
| 186 |
-
# Describing the data
|
| 187 |
st.subheader(f'Data from {start_date} - {end_date}')
|
| 188 |
data = yf.download(user_input, start_date, end_date)
|
| 189 |
|
| 190 |
if data.empty:
|
| 191 |
-
# Display a message to the user when no data is available
|
| 192 |
st.warning(f"No data available for stock symbol {stock_name} in the specified date range.")
|
| 193 |
else:
|
| 194 |
-
# Reset the index to add the date column
|
| 195 |
data = data.reset_index()
|
| 196 |
-
|
| 197 |
-
# Display data in a Plotly table
|
| 198 |
fig = go.Figure(data=[go.Table(
|
| 199 |
header=dict(values=list(data.columns),
|
| 200 |
font=dict(size=12, color='white'),
|
|
@@ -212,7 +197,6 @@ try:
|
|
| 212 |
|
| 213 |
st.plotly_chart(fig, use_container_width=True)
|
| 214 |
|
| 215 |
-
### ............................................... ##
|
| 216 |
# Stock Price Over Time
|
| 217 |
g1, g2, g3 = st.columns((1.2,1.2,1))
|
| 218 |
|
|
@@ -283,8 +267,6 @@ try:
|
|
| 283 |
fig9.update_layout(title_text="MACD", title_x=0, margin=dict(l=0, r=10, b=10, t=30), yaxis_title=None, xaxis_title=None)
|
| 284 |
g9.plotly_chart(fig9, use_container_width=True)
|
| 285 |
|
| 286 |
-
### ............................................... ##
|
| 287 |
-
|
| 288 |
# Relative Strength Index (RSI)
|
| 289 |
|
| 290 |
delta = data['Close'].diff()
|
|
@@ -308,7 +290,6 @@ try:
|
|
| 308 |
fig11.update_layout(title_text="Candlestick Chart", title_x=0, margin=dict(l=0, r=10, b=10, t=30))
|
| 309 |
g11.plotly_chart(fig11, use_container_width=True)
|
| 310 |
|
| 311 |
-
### ............................................... ##
|
| 312 |
# Price Rate of Change (ROC)
|
| 313 |
n = 12
|
| 314 |
data['ROC'] = ((data['Close'] - data['Close'].shift(n)) / data['Close'].shift(n)) * 100
|
|
|
|
| 15 |
st.set_page_config(page_title='Stocks Analysis', layout='wide', page_icon=':rocket:')
|
| 16 |
|
| 17 |
st.sidebar.title("Stock Option")
|
|
|
|
| 18 |
sidebar_css = """
|
| 19 |
<style>
|
| 20 |
div[data-testid="stSidebar"] > div:first-child {
|
|
|
|
| 119 |
else:
|
| 120 |
st.write("Price-to-Book (P/B) Ratio information not available for this stock.")
|
| 121 |
|
|
|
|
|
|
|
| 122 |
st.subheader('Company Summary')
|
| 123 |
if 'longBusinessSummary' in stock_info:
|
| 124 |
LongBusinessSummary = stock_info['longBusinessSummary']
|
|
|
|
| 154 |
else:
|
| 155 |
st.write("Company Officers information not available for this stock.")
|
| 156 |
|
|
|
|
|
|
|
| 157 |
st.subheader('Latest News')
|
| 158 |
|
|
|
|
| 159 |
news_data_for_dataframe = []
|
| 160 |
for news_item in news_data:
|
| 161 |
news_title = news_item['title']
|
|
|
|
| 165 |
news_link = f"[Link]({news_item['link']})"
|
| 166 |
news_data_for_dataframe.append([news_title, news_publisher, news_provider_publish_time, news_type, news_link])
|
| 167 |
|
|
|
|
| 168 |
df = pd.DataFrame(news_data_for_dataframe, columns=["Title", "Publisher", "Provider Publish Time", "Type", "Link"])
|
| 169 |
|
|
|
|
| 170 |
st.markdown(df.to_markdown(index=False), unsafe_allow_html=True)
|
| 171 |
|
|
|
|
|
|
|
| 172 |
title = f"<h1 style='color: white; font-size: 25px; text-align: center; '>{stock_name}'s Technical Analysis</h1>"
|
| 173 |
st.markdown(title, unsafe_allow_html=True)
|
| 174 |
|
| 175 |
with st.expander("Expand"):
|
|
|
|
| 176 |
st.subheader(f'Data from {start_date} - {end_date}')
|
| 177 |
data = yf.download(user_input, start_date, end_date)
|
| 178 |
|
| 179 |
if data.empty:
|
|
|
|
| 180 |
st.warning(f"No data available for stock symbol {stock_name} in the specified date range.")
|
| 181 |
else:
|
|
|
|
| 182 |
data = data.reset_index()
|
|
|
|
|
|
|
| 183 |
fig = go.Figure(data=[go.Table(
|
| 184 |
header=dict(values=list(data.columns),
|
| 185 |
font=dict(size=12, color='white'),
|
|
|
|
| 197 |
|
| 198 |
st.plotly_chart(fig, use_container_width=True)
|
| 199 |
|
|
|
|
| 200 |
# Stock Price Over Time
|
| 201 |
g1, g2, g3 = st.columns((1.2,1.2,1))
|
| 202 |
|
|
|
|
| 267 |
fig9.update_layout(title_text="MACD", title_x=0, margin=dict(l=0, r=10, b=10, t=30), yaxis_title=None, xaxis_title=None)
|
| 268 |
g9.plotly_chart(fig9, use_container_width=True)
|
| 269 |
|
|
|
|
|
|
|
| 270 |
# Relative Strength Index (RSI)
|
| 271 |
|
| 272 |
delta = data['Close'].diff()
|
|
|
|
| 290 |
fig11.update_layout(title_text="Candlestick Chart", title_x=0, margin=dict(l=0, r=10, b=10, t=30))
|
| 291 |
g11.plotly_chart(fig11, use_container_width=True)
|
| 292 |
|
|
|
|
| 293 |
# Price Rate of Change (ROC)
|
| 294 |
n = 12
|
| 295 |
data['ROC'] = ((data['Close'] - data['Close'].shift(n)) / data['Close'].shift(n)) * 100
|