File size: 2,300 Bytes
41fee50
 
 
 
82b1468
41fee50
6fb1d1b
 
 
 
 
 
 
41fee50
6fb1d1b
 
 
 
 
41fee50
6fb1d1b
 
 
72ee182
 
6fb1d1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
import yfinance as yf
import pandas as pd
import plotly.graph_objs as go
import numpy as np

isPswdValid = False
try:
    pswdVal = st.experimental_get_query_params()['pwd'][0]
    if pswdVal==st.secrets["PSWD"]:
        isPswdValid = True
except:
    pass

if not isPswdValid:
    st.write("Invalid Password")
else:
    # Set the Streamlit app title and icon
    st.set_page_config(page_title="Stock Analysis", page_icon="📈")

    # 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('2024-01-01'))
    end_date = st.sidebar.date_input("End Date", pd.to_datetime('2024-10-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.")

    # 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)

    # Calculate basic statistics
    st.subheader("Basic Statistics")
    st.write(f"**Average Closing Price**: ${np.mean(stock_data['Close']):.2f}")
    st.write(f"**Minimum Closing Price**: ${np.min(stock_data['Close']):.2f}")
    st.write(f"**Maximum Closing Price**: ${np.max(stock_data['Close']):.2f}")
    st.write(f"**Total Volume Traded**: {np.sum(stock_data['Volume']):,} shares")

    # Add a text summary
    st.subheader("Stock Summary")
    st.write("This is a brief summary of the stock's performance.")
    st.write("You can add more in-depth analysis and insights here.")
    # You can use external libraries or APIs for more advanced analysis