Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
from datetime import datetime, timedelta
|
|
|
4 |
|
5 |
-
# Import
|
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
|
@@ -12,33 +12,39 @@ from utils.plotting import plot_stock_data_with_signals
|
|
12 |
# Streamlit app title
|
13 |
st.title('StockSwingApp: Stock Trading Signal Generator')
|
14 |
|
15 |
-
#
|
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=
|
20 |
end_date = st.sidebar.date_input('End Date', value=datetime.now())
|
21 |
|
22 |
-
#
|
23 |
-
st.
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
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 |
-
|
32 |
-
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
st.write(signals_data)
|
42 |
-
else:
|
43 |
-
st.write("No data available for the given inputs. Please try different parameters.")
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from datetime import datetime, timedelta
|
3 |
+
import pandas as pd
|
4 |
|
5 |
+
# Import 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
|
|
|
12 |
# Streamlit app title
|
13 |
st.title('StockSwingApp: Stock Trading Signal Generator')
|
14 |
|
15 |
+
# Sidebar for 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=90))
|
20 |
end_date = st.sidebar.date_input('End Date', value=datetime.now())
|
21 |
|
22 |
+
# Data fetching and processing
|
23 |
+
if st.sidebar.button('Generate Signals'):
|
24 |
+
st.write(f"Fetching data for {symbol} from {start_date} to {end_date}...")
|
25 |
|
26 |
+
try:
|
27 |
+
stock_data = fetch_stock_data(symbol, start_date.strftime('%Y-%m-%d'), end_date.strftime('%Y-%m-%d'), interval='1d')
|
|
|
|
|
28 |
|
29 |
+
if not stock_data.empty:
|
30 |
+
# Calculate indicators and signals
|
31 |
+
stock_data = calculate_21_50_sma(stock_data)
|
32 |
+
stock_data = calculate_bollinger_bands(stock_data)
|
33 |
+
signals_data = generate_signals(stock_data)
|
34 |
|
35 |
+
# Plotting
|
36 |
+
fig = plot_stock_data_with_signals(signals_data)
|
37 |
+
st.pyplot(fig)
|
38 |
|
39 |
+
# Option to display raw data
|
40 |
+
if st.checkbox('Show Raw Data'):
|
41 |
+
st.write(signals_data)
|
|
|
|
|
|
|
42 |
|
43 |
+
else:
|
44 |
+
st.error("No data available for the given symbol. Please try another one.")
|
45 |
+
|
46 |
+
except Exception as e:
|
47 |
+
st.error(f"An error occurred: {e}")
|
48 |
+
|
49 |
+
else:
|
50 |
+
st.info('Enter parameters and click "Generate Signals" to view analysis.')
|