Spaces:
Running
Running
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 | |
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() | |