stkmkt / app.py
markytools's picture
msg
41fee50
raw
history blame
1.62 kB
import streamlit as st
import yfinance as yf
import pandas as pd
import plotly.graph_objs as go
# Set the Streamlit app title and icon
st.set_page_config(page_title="Stock Analysis", page_icon="📈")
# Define the Streamlit app
def main():
# Create a Streamlit sidebar for user input
st.sidebar.title("Stock Analysis")
ticker_symbol = st.sidebar.text_input("Enter Stock Ticker Symbol:", value='AAPL')
start_date = st.sidebar.date_input("Start Date", pd.to_datetime('2020-01-01'))
end_date = st.sidebar.date_input("End Date", pd.to_datetime('2021-01-01'))
# Fetch stock data from Yahoo Finance
try:
stock_data = yf.download(ticker_symbol, start=start_date, end=end_date)
except Exception as e:
st.error("Error fetching stock data. Please check the ticker symbol and date range.")
return
# Display basic stock information
st.header(f"Stock Analysis for {ticker_symbol}")
st.subheader("Basic Stock Information")
st.write(stock_data.tail())
# Plot a candlestick chart
st.subheader("Candlestick Chart")
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'])])
fig.update_layout(title=f'{ticker_symbol} Candlestick Chart', xaxis_title='Date', yaxis_title='Price')
st.plotly_chart(fig)
# Perform more advanced analysis here
# You can add more Streamlit components and analysis tools as needed
# Run the Streamlit app
if __name__ == '__main__':
main()