Spaces:
Sleeping
Sleeping
Commit
·
6fb1d1b
1
Parent(s):
82b1468
mm
Browse files
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 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
st.
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
st.
|
21 |
-
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
st.
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
st.
|
46 |
-
st.write("
|
47 |
-
st.write("
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|