markytools commited on
Commit
6fb1d1b
·
1 Parent(s): 82b1468
Files changed (1) hide show
  1. app.py +51 -40
app.py CHANGED
@@ -4,45 +4,56 @@ import pandas as pd
4
  import plotly.graph_objs as go
5
  import numpy as np
6
 
7
- # Set the Streamlit app title and icon
8
- st.set_page_config(page_title="Stock Analysis", page_icon="📈")
 
 
 
 
 
9
 
10
- # Create a Streamlit sidebar for user input
11
- st.sidebar.title("Stock Analysis")
12
- ticker_symbol = st.sidebar.text_input("Enter Stock Ticker Symbol:", value='AAPL')
13
- start_date = st.sidebar.date_input("Start Date", pd.to_datetime('2020-01-01'))
14
- end_date = st.sidebar.date_input("End Date", pd.to_datetime('2021-01-01'))
15
 
16
- # Fetch stock data from Yahoo Finance
17
- try:
18
- stock_data = yf.download(ticker_symbol, start=start_date, end=end_date)
19
- except Exception as e:
20
- st.error("Error fetching stock data. Please check the ticker symbol and date range.")
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
- # Calculate basic statistics
38
- st.subheader("Basic Statistics")
39
- st.write(f"**Average Closing Price**: ${np.mean(stock_data['Close']):.2f}")
40
- st.write(f"**Minimum Closing Price**: ${np.min(stock_data['Close']):.2f}")
41
- st.write(f"**Maximum Closing Price**: ${np.max(stock_data['Close']):.2f}")
42
- st.write(f"**Total Volume Traded**: {np.sum(stock_data['Volume']):,} shares")
43
-
44
- # Add a text summary
45
- st.subheader("Stock Summary")
46
- st.write("This is a brief summary of the stock's performance.")
47
- st.write("You can add more in-depth analysis and insights here.")
48
- # You can use external libraries or APIs for more advanced analysis
 
 
 
 
 
 
 
4
  import plotly.graph_objs as go
5
  import numpy as np
6
 
7
+ isPswdValid = False
8
+ try:
9
+ pswdVal = st.experimental_get_query_params()['pwd'][0]
10
+ if pswdVal==st.secrets["PSWD"]:
11
+ isPswdValid = True
12
+ except:
13
+ pass
14
 
15
+ if not isPswdValid:
16
+ st.write("Invalid Password")
17
+ else:
18
+ # Set the Streamlit app title and icon
19
+ st.set_page_config(page_title="Stock Analysis", page_icon="📈")
20
 
21
+ # Create a Streamlit sidebar for user input
22
+ st.sidebar.title("Stock Analysis")
23
+ ticker_symbol = st.sidebar.text_input("Enter Stock Ticker Symbol:", value='AAPL')
24
+ start_date = st.sidebar.date_input("Start Date", pd.to_datetime('2020-01-01'))
25
+ end_date = st.sidebar.date_input("End Date", pd.to_datetime('2021-01-01'))
26
+
27
+ # Fetch stock data from Yahoo Finance
28
+ try:
29
+ stock_data = yf.download(ticker_symbol, start=start_date, end=end_date)
30
+ except Exception as e:
31
+ st.error("Error fetching stock data. Please check the ticker symbol and date range.")
32
+
33
+ # Display basic stock information
34
+ st.header(f"Stock Analysis for {ticker_symbol}")
35
+ st.subheader("Basic Stock Information")
36
+ st.write(stock_data.tail())
37
+
38
+ # Plot a candlestick chart
39
+ st.subheader("Candlestick Chart")
40
+ fig = go.Figure(data=[go.Candlestick(x=stock_data.index,
41
+ open=stock_data['Open'],
42
+ high=stock_data['High'],
43
+ low=stock_data['Low'],
44
+ close=stock_data['Close'])])
45
+ fig.update_layout(title=f'{ticker_symbol} Candlestick Chart', xaxis_title='Date', yaxis_title='Price')
46
+ st.plotly_chart(fig)
47
+
48
+ # Calculate basic statistics
49
+ st.subheader("Basic Statistics")
50
+ st.write(f"**Average Closing Price**: ${np.mean(stock_data['Close']):.2f}")
51
+ st.write(f"**Minimum Closing Price**: ${np.min(stock_data['Close']):.2f}")
52
+ st.write(f"**Maximum Closing Price**: ${np.max(stock_data['Close']):.2f}")
53
+ st.write(f"**Total Volume Traded**: {np.sum(stock_data['Volume']):,} shares")
54
+
55
+ # Add a text summary
56
+ st.subheader("Stock Summary")
57
+ st.write("This is a brief summary of the stock's performance.")
58
+ st.write("You can add more in-depth analysis and insights here.")
59
+ # You can use external libraries or APIs for more advanced analysis