Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
# 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,6 +6,7 @@ from indicators.macd import calculate_macd
|
|
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,6 +21,9 @@ Welcome to the Stock Intraday Signal App! This application analyzes stock data t
|
|
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,6 +33,9 @@ start_date = st.sidebar.date_input('Start Date')
|
|
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,22 +46,21 @@ if analyze_button:
|
|
41 |
else:
|
42 |
st.write("Calculating indicators... π")
|
43 |
ema_periods = [20, 50] # Example periods for EMA
|
44 |
-
|
45 |
-
|
46 |
-
data[f'EMA_{period}'] = ema_series
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
data = pd.concat([data,
|
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 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from data_fetcher.yfinance_client import fetch_intraday_data
|
3 |
from indicators.ema import calculate_ema
|
|
|
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 |
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 |
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 |
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 |
+
|