Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,44 @@
|
|
1 |
-
# app.py
|
2 |
-
|
3 |
import streamlit as st
|
4 |
import pandas as pd
|
5 |
from datetime import datetime, timedelta
|
6 |
|
7 |
-
# Import
|
8 |
-
from yfinance_data.fetcher import
|
9 |
-
from indicators.sma import
|
10 |
from indicators.bollinger_bands import calculate_bollinger_bands
|
11 |
-
from signals.strategy import
|
12 |
-
from utils.plotting import
|
13 |
-
|
14 |
-
#
|
15 |
-
st.title('StockSwingApp: Stock Signal Generator')
|
16 |
-
|
17 |
-
# User
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
# Instructions for running the app
|
37 |
-
st.markdown("""
|
38 |
-
To run this app, ensure you have Streamlit and all required packages installed. Then, navigate to the directory containing this script and run: """)
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
from datetime import datetime, timedelta
|
4 |
|
5 |
+
# Import our custom modules
|
6 |
+
from yfinance_data.fetcher import fetch_stock_data
|
7 |
+
from indicators.sma import calculate_21_50_sma
|
8 |
from indicators.bollinger_bands import calculate_bollinger_bands
|
9 |
+
from signals.strategy import generate_signals
|
10 |
+
from utils.plotting import plot_stock_data_with_signals
|
11 |
+
|
12 |
+
# Streamlit app title
|
13 |
+
st.title('StockSwingApp: Stock Trading Signal Generator')
|
14 |
+
|
15 |
+
# User inputs
|
16 |
+
st.sidebar.header('User Input Parameters')
|
17 |
+
default_symbol = 'AAPL'
|
18 |
+
symbol = st.sidebar.text_input('Stock Symbol', value=default_symbol, max_chars=5).upper()
|
19 |
+
start_date = st.sidebar.date_input('Start Date', value=datetime.now() - timedelta(days=365))
|
20 |
+
end_date = st.sidebar.date_input('End Date', value=datetime.now())
|
21 |
+
|
22 |
+
# Fetch stock data
|
23 |
+
st.write(f"Fetching data for {symbol} from {start_date} to {end_date}...")
|
24 |
+
stock_data = fetch_stock_data(symbol, start_date.strftime('%Y-%m-%d'), end_date.strftime('%Y-%m-%d'), interval='1d')
|
25 |
+
|
26 |
+
if not stock_data.empty:
|
27 |
+
# Calculate indicators
|
28 |
+
stock_data_with_indicators = calculate_21_50_sma(stock_data)
|
29 |
+
stock_data_with_indicators = calculate_bollinger_bands(stock_data_with_indicators)
|
30 |
+
|
31 |
+
# Generate signals
|
32 |
+
signals_data = generate_signals(stock_data_with_indicators)
|
33 |
+
|
34 |
+
# Display the chart
|
35 |
+
st.write(f"Displaying data for {symbol}")
|
36 |
+
plot_stock_data_with_signals(signals_data)
|
37 |
+
|
38 |
+
# Optionally, display the data table
|
39 |
+
show_data = st.checkbox('Show Data Table')
|
40 |
+
if show_data:
|
41 |
+
st.write(signals_data)
|
42 |
+
else:
|
43 |
+
st.write("No data available for the given inputs. Please try different parameters.")
|
44 |
|
|
|
|
|
|