netflypsb commited on
Commit
6a80d9e
β€’
1 Parent(s): 75ec5ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -18
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import streamlit as st
2
  from data_fetcher.yfinance_client import fetch_intraday_data
3
  from indicators.ema import calculate_ema
@@ -6,7 +8,6 @@ from indicators.macd import calculate_macd
6
  from indicators.bollinger_bands import calculate_bollinger_bands
7
  from signals.strategy import generate_combined_signals
8
  from utils.plotting import plot_stock_data_with_signals
9
- from utils.plotting_interactive import plot_stock_data_with_signals_interactive
10
  import pandas as pd
11
 
12
  # Streamlit app title with emoji
@@ -21,9 +22,6 @@ Welcome to the Stock Intraday Signal App! This application analyzes stock data t
21
  1. Enter a stock symbol in the sidebar. πŸ“
22
  2. Choose the date range for the analysis. πŸ—“οΈ
23
  3. Click on "Analyze" to view the stock data, indicators, and signals. πŸ”
24
-
25
- ### Optimal Time Frame for Best Visualization πŸ•’
26
- For the best experience, it's recommended to select a time range of up to 2 weeks when using the 15-minute data. This will ensure the charts remain clear and interactive features perform well.
27
  """)
28
 
29
  # Sidebar inputs with emojis
@@ -33,9 +31,6 @@ start_date = st.sidebar.date_input('Start Date')
33
  end_date = st.sidebar.date_input('End Date')
34
  analyze_button = st.sidebar.button('Analyze πŸš€')
35
 
36
- # Option for selecting chart type
37
- chart_type = st.sidebar.radio("Chart Type:", ('Static', 'Interactive'))
38
-
39
  # Main functionality
40
  if analyze_button:
41
  st.write(f"Fetching data for {stock_symbol} from {start_date} to {end_date}... πŸ”„")
@@ -46,21 +41,23 @@ if analyze_button:
46
  else:
47
  st.write("Calculating indicators... πŸ”")
48
  ema_periods = [20, 50] # Example periods for EMA
49
- for period in ema_periods:
50
- data[f'EMA_{period}'] = calculate_ema(data['Close'], period)
 
51
 
52
- data['RSI'] = calculate_rsi(data['Close'])
53
- macd_result = calculate_macd(data['Close'])
54
- data = pd.concat([data, macd_result], axis=1)
55
- bb_result = calculate_bollinger_bands(data['Close'])
56
- data = pd.concat([data, bb_result], axis=1)
 
 
 
57
 
58
  st.write("Generating signals... 🚦")
59
  data = generate_combined_signals(data)
60
 
61
  st.write("Visualizing data, indicators, and signals... πŸ“Š")
62
- if chart_type == 'Static':
63
- plot_stock_data_with_signals(data)
64
- else:
65
- plot_stock_data_with_signals_interactive(data)
66
 
 
1
+ I have placed the new file in this location: utils/plotting_interactive.py. based on this, please rewrite the full app.py to account for the new file and to display the interactive chart. Also instruct user on the optimal time frame for best visualisation: # app.py
2
+
3
  import streamlit as st
4
  from data_fetcher.yfinance_client import fetch_intraday_data
5
  from indicators.ema import calculate_ema
 
8
  from indicators.bollinger_bands import calculate_bollinger_bands
9
  from signals.strategy import generate_combined_signals
10
  from utils.plotting import plot_stock_data_with_signals
 
11
  import pandas as pd
12
 
13
  # Streamlit app title with emoji
 
22
  1. Enter a stock symbol in the sidebar. πŸ“
23
  2. Choose the date range for the analysis. πŸ—“οΈ
24
  3. Click on "Analyze" to view the stock data, indicators, and signals. πŸ”
 
 
 
25
  """)
26
 
27
  # Sidebar inputs with emojis
 
31
  end_date = st.sidebar.date_input('End Date')
32
  analyze_button = st.sidebar.button('Analyze πŸš€')
33
 
 
 
 
34
  # Main functionality
35
  if analyze_button:
36
  st.write(f"Fetching data for {stock_symbol} from {start_date} to {end_date}... πŸ”„")
 
41
  else:
42
  st.write("Calculating indicators... πŸ”")
43
  ema_periods = [20, 50] # Example periods for EMA
44
+ ema_data = calculate_ema(data['Close'], ema_periods)
45
+ for period, ema_series in ema_data.items():
46
+ data[f'EMA_{period}'] = ema_series
47
 
48
+ rsi_results = calculate_rsi(data['Close'])
49
+ data = data.join(rsi_results) # Merge the RSI results back into the main DataFrame
50
+
51
+ macd_data = calculate_macd(data['Close'])
52
+ data = pd.concat([data, macd_data], axis=1)
53
+
54
+ bb_data = calculate_bollinger_bands(data['Close'])
55
+ data = pd.concat([data, bb_data], axis=1)
56
 
57
  st.write("Generating signals... 🚦")
58
  data = generate_combined_signals(data)
59
 
60
  st.write("Visualizing data, indicators, and signals... πŸ“Š")
61
+ plot_stock_data_with_signals(data)
62
+
 
 
63