netflypsb commited on
Commit
e4a10d0
·
verified ·
1 Parent(s): baf05f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -32
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 your modules here
8
- from yfinance_data.fetcher import fetch_data_for_indicators
9
- from indicators.sma import add_sma_columns
10
  from indicators.bollinger_bands import calculate_bollinger_bands
11
- from signals.strategy import generate_buy_signals, generate_sell_signals
12
- from utils.plotting import plot_stock_data
13
-
14
- # Initialize the app with Streamlit
15
- st.title('StockSwingApp: Stock Signal Generator')
16
-
17
- # User input for the stock symbol
18
- symbol = st.text_input('Enter the stock symbol:', value='AAPL')
19
-
20
- # Fetch the stock data
21
- data_4h, data_1h = fetch_data_for_indicators(symbol, days=90) # Fetching more days to ensure we have enough data
22
-
23
- # Calculate indicators
24
- add_sma_columns(data_4h)
25
- add_sma_columns(data_1h)
26
- calculate_bollinger_bands(data_4h)
27
-
28
- # Generate signals
29
- buy_signals = generate_buy_signals(data_4h, data_1h)
30
- sell_signals = generate_sell_signals(data_4h)
31
-
32
- # Plotting
33
- st.write(f"Displaying indicators and signals for: {symbol}")
34
- plot_stock_data(data_4h, buy_signals=buy_signals, sell_signals=sell_signals, title=f"{symbol} Stock Analysis")
 
 
 
 
 
 
 
 
 
 
 
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