Delete app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899import streamlit as stimport pandas as pdimport yfinance as yfimport plotly.graph_objs as gofrom datetime import datetime, timedeltaimport requests
# Define the layout using Streamlit componentsst.title('Stonks20.com')stock_symbol = st.text_input('Enter the stock symbol:', 'AAPL')date_range = st.date_input('Select the dates:', [(datetime.today() - timedelta(days=365)).date(), datetime.today().date()])submit_button = st.button('Submit')
# Fetch stock data and update the graphsif submit_button: try: start_date, end_date = date_range stock_data = yf.download(stock_symbol, start=start_date, end=end_date)
# Create a Candlestick chart candlestick_fig = go.Figure(data=[go.Candlestick(x=stock_data.index, open=stock_data['Open'], high=stock_data['High'], low=stock_data['Low'], close=stock_data['Close'])]) candlestick_fig.update_layout( title=f'{stock_symbol} Stock Price', xaxis_title='Date', yaxis_title='Price', autosize=True ) st.plotly_chart(candlestick_fig)
# Create a Volume chart volume_fig = go.Figure(data=[go.Bar(x=stock_data.index, y=stock_data['Volume'])]) volume_fig.update_layout( title='Volume', xaxis_title='Date', yaxis_title='Volume', autosize=True ) st.plotly_chart(volume_fig)
# Create a Moving Average chart moving_average_fig = go.Figure(data=[ go.Scatter(x=stock_data.index, y=stock_data['Close'], name='Price'), go.Scatter(x=stock_data.index, y=stock_data['Close'].rolling(window=50).mean(), name='50-day MA'), go.Scatter(x=stock_data.index, y=stock_data['Close'].rolling(window=200).mean(), name='200-day MA') ]) moving_average_fig.update_layout( title='Moving Averages', xaxis_title='Date', yaxis_title='Price', autosize=True ) st.plotly_chart(moving_average_fig)
# Create an RSI chart delta = stock_data['Close'].diff() gain = delta.mask(delta < 0, 0) loss = -delta.mask(delta > 0, 0) avg_gain = gain.rolling(window=14).mean() avg_loss = loss.rolling(window=14).mean() rs = avg_gain / avg_loss rsi = 100 - (100 / (1 + rs))
rsi_fig = go.Figure(data=[go.Scatter(x=stock_data.index, y=rsi, name='RSI', line=dict(color='blue'))]) rsi_fig.update_layout( title='Relative Strength Index (RSI)', xaxis_title='Date', yaxis_title='RSI', autosize=True ) st.plotly_chart(rsi_fig)
except Exception as e: st.error(f'Error: {str(e)}')
# Display news articlesnews_api_key = 'YOUR_NEWS_API_KEY'if submit_button: try: url = f'https://newsapi.org/v2/everything?q={stock_symbol}&language=en&apiKey={news_api_key}' response = requests.get(url) data = response.json() articles = data['articles'] if articles: st.subheader('News') for article in articles: st.markdown(f"## {article['title']}") st.markdown(article['description']) st.markdown(f"[Read More]({article['url']})") else: st.warning('No news articles found for the given stock symbol.')
except Exception as e: st.error(f'Error: {str(e)}')app.pyDeleted-99