Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import yfinance as yf
|
2 |
+
import pandas as pd
|
3 |
+
import streamlit as st
|
4 |
+
import plotly.graph_objs as go
|
5 |
+
|
6 |
+
# Function to load data with the updated cache method
|
7 |
+
@st.cache_data
|
8 |
+
def load_data(ticker):
|
9 |
+
data = yf.download(ticker, start='2020-01-01', end='2023-01-01')
|
10 |
+
data.reset_index(inplace=True)
|
11 |
+
return data
|
12 |
+
|
13 |
+
def calculate_moving_averages(data, window):
|
14 |
+
data[f'MA{window}'] = data['Close'].rolling(window=window).mean()
|
15 |
+
return data
|
16 |
+
|
17 |
+
def main():
|
18 |
+
st.title("FinanceTracker: Financial Dashboard")
|
19 |
+
st.sidebar.title("Settings")
|
20 |
+
|
21 |
+
# User input for ticker symbol
|
22 |
+
ticker = st.sidebar.text_input("Ticker Symbol", "AAPL")
|
23 |
+
|
24 |
+
# Load data
|
25 |
+
data = load_data(ticker)
|
26 |
+
|
27 |
+
# User input for moving average window
|
28 |
+
ma_window = st.sidebar.slider("Moving Average Window", 5, 100, 20)
|
29 |
+
data = calculate_moving_averages(data, ma_window)
|
30 |
+
|
31 |
+
# Plotting the data
|
32 |
+
fig = go.Figure()
|
33 |
+
fig.add_trace(go.Scatter(x=data['Date'], y=data['Close'], mode='lines', name='Close'))
|
34 |
+
fig.add_trace(go.Scatter(x=data['Date'], y=data[f'MA{ma_window}'], mode='lines', name=f'MA{ma_window}'))
|
35 |
+
|
36 |
+
st.plotly_chart(fig)
|
37 |
+
|
38 |
+
# Additional metrics and analysis
|
39 |
+
st.write(f"### {ticker} Data Summary")
|
40 |
+
st.write(data.describe())
|
41 |
+
|
42 |
+
st.write(f"### {ticker} Close Price")
|
43 |
+
st.line_chart(data['Close'])
|
44 |
+
|
45 |
+
st.write(f"### {ticker} Volume")
|
46 |
+
st.line_chart(data['Volume'])
|
47 |
+
|
48 |
+
if __name__ == "__main__":
|
49 |
+
main()
|