File size: 1,422 Bytes
bf5d90d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import yfinance as yf
import pandas as pd
import streamlit as st
import plotly.graph_objs as go

# Function to load data with the updated cache method
@st.cache_data
def load_data(ticker):
    data = yf.download(ticker, start='2020-01-01', end='2023-01-01')
    data.reset_index(inplace=True)
    return data

def calculate_moving_averages(data, window):
    data[f'MA{window}'] = data['Close'].rolling(window=window).mean()
    return data

def main():
    st.title("FinanceTracker: Financial Dashboard")
    st.sidebar.title("Settings")

    # User input for ticker symbol
    ticker = st.sidebar.text_input("Ticker Symbol", "AAPL")

    # Load data
    data = load_data(ticker)

    # User input for moving average window
    ma_window = st.sidebar.slider("Moving Average Window", 5, 100, 20)
    data = calculate_moving_averages(data, ma_window)

    # Plotting the data
    fig = go.Figure()
    fig.add_trace(go.Scatter(x=data['Date'], y=data['Close'], mode='lines', name='Close'))
    fig.add_trace(go.Scatter(x=data['Date'], y=data[f'MA{ma_window}'], mode='lines', name=f'MA{ma_window}'))

    st.plotly_chart(fig)

    # Additional metrics and analysis
    st.write(f"### {ticker} Data Summary")
    st.write(data.describe())

    st.write(f"### {ticker} Close Price")
    st.line_chart(data['Close'])

    st.write(f"### {ticker} Volume")
    st.line_chart(data['Volume'])

if __name__ == "__main__":
    main()