markytools commited on
Commit
7ebe559
·
1 Parent(s): 41fee50
Files changed (1) hide show
  1. app.py +26 -32
app.py CHANGED
@@ -6,39 +6,33 @@ import plotly.graph_objs as go
6
  # Set the Streamlit app title and icon
7
  st.set_page_config(page_title="Stock Analysis", page_icon="📈")
8
 
9
- # Define the Streamlit app
10
- def main():
11
- # Create a Streamlit sidebar for user input
12
- st.sidebar.title("Stock Analysis")
13
- ticker_symbol = st.sidebar.text_input("Enter Stock Ticker Symbol:", value='AAPL')
14
- start_date = st.sidebar.date_input("Start Date", pd.to_datetime('2020-01-01'))
15
- end_date = st.sidebar.date_input("End Date", pd.to_datetime('2021-01-01'))
16
 
17
- # Fetch stock data from Yahoo Finance
18
- try:
19
- stock_data = yf.download(ticker_symbol, start=start_date, end=end_date)
20
- except Exception as e:
21
- st.error("Error fetching stock data. Please check the ticker symbol and date range.")
22
- return
23
 
24
- # Display basic stock information
25
- st.header(f"Stock Analysis for {ticker_symbol}")
26
- st.subheader("Basic Stock Information")
27
- st.write(stock_data.tail())
28
 
29
- # Plot a candlestick chart
30
- st.subheader("Candlestick Chart")
31
- fig = go.Figure(data=[go.Candlestick(x=stock_data.index,
32
- open=stock_data['Open'],
33
- high=stock_data['High'],
34
- low=stock_data['Low'],
35
- close=stock_data['Close'])])
36
- fig.update_layout(title=f'{ticker_symbol} Candlestick Chart', xaxis_title='Date', yaxis_title='Price')
37
- st.plotly_chart(fig)
38
 
39
- # Perform more advanced analysis here
40
- # You can add more Streamlit components and analysis tools as needed
41
-
42
- # Run the Streamlit app
43
- if __name__ == '__main__':
44
- main()
 
6
  # Set the Streamlit app title and icon
7
  st.set_page_config(page_title="Stock Analysis", page_icon="📈")
8
 
9
+ # Create a Streamlit sidebar for user input
10
+ st.sidebar.title("Stock Analysis")
11
+ ticker_symbol = st.sidebar.text_input("Enter Stock Ticker Symbol:", value='AAPL')
12
+ start_date = st.sidebar.date_input("Start Date", pd.to_datetime('2020-01-01'))
13
+ end_date = st.sidebar.date_input("End Date", pd.to_datetime('2021-01-01'))
 
 
14
 
15
+ # Fetch stock data from Yahoo Finance
16
+ try:
17
+ stock_data = yf.download(ticker_symbol, start=start_date, end=end_date)
18
+ except Exception as e:
19
+ st.error("Error fetching stock data. Please check the ticker symbol and date range.")
20
+ return
21
 
22
+ # Display basic stock information
23
+ st.header(f"Stock Analysis for {ticker_symbol}")
24
+ st.subheader("Basic Stock Information")
25
+ st.write(stock_data.tail())
26
 
27
+ # Plot a candlestick chart
28
+ st.subheader("Candlestick Chart")
29
+ fig = go.Figure(data=[go.Candlestick(x=stock_data.index,
30
+ open=stock_data['Open'],
31
+ high=stock_data['High'],
32
+ low=stock_data['Low'],
33
+ close=stock_data['Close'])])
34
+ fig.update_layout(title=f'{ticker_symbol} Candlestick Chart', xaxis_title='Date', yaxis_title='Price')
35
+ st.plotly_chart(fig)
36
 
37
+ # Perform more advanced analysis here
38
+ # You can add more Streamlit components and analysis tools as needed