Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
from datetime import datetime, timedelta | |
# Import our custom modules | |
from yfinance_data.fetcher import fetch_stock_data | |
from indicators.sma import calculate_21_50_sma | |
from indicators.bollinger_bands import calculate_bollinger_bands | |
from signals.strategy import generate_signals | |
from utils.plotting import plot_stock_data | |
# Streamlit app title | |
st.title('StockSwingApp: Stock Trading Signal Generator') | |
# User inputs | |
st.sidebar.header('User Input Parameters') | |
default_symbol = 'AAPL' | |
symbol = st.sidebar.text_input('Stock Symbol', value=default_symbol, max_chars=5).upper() | |
start_date = st.sidebar.date_input('Start Date', value=datetime.now() - timedelta(days=365)) | |
end_date = st.sidebar.date_input('End Date', value=datetime.now()) | |
# Fetch stock data | |
st.write(f"Fetching data for {symbol} from {start_date} to {end_date}...") | |
stock_data = fetch_stock_data(symbol, start_date.strftime('%Y-%m-%d'), end_date.strftime('%Y-%m-%d'), interval='1d') | |
if not stock_data.empty: | |
# Calculate indicators | |
stock_data_with_indicators = calculate_21_50_sma(stock_data) | |
stock_data_with_indicators = calculate_bollinger_bands(stock_data_with_indicators) | |
# Generate signals | |
signals_data = generate_signals(stock_data_with_indicators) | |
# Display the chart | |
st.write(f"Displaying data for {symbol}") | |
plot_stock_data_with_signals(signals_data) | |
# Optionally, display the data table | |
show_data = st.checkbox('Show Data Table') | |
if show_data: | |
st.write(signals_data) | |
else: | |
st.write("No data available for the given inputs. Please try different parameters.") | |