Spaces:
Runtime error
Runtime error
import streamlit as st | |
from binance_api.yfinanceclient import YFinanceClient | |
from indicators.sma import calculate_sma | |
from indicators.bollinger_bands import calculate_bollinger_bands | |
from signals.strategy import generate_signals | |
from utils.plotting import plot_data_with_indicators_and_signals | |
# Initialize Streamlit app | |
st.title('Stock Signal App') | |
# User inputs | |
ticker = st.text_input('Enter the stock ticker symbol (e.g., AAPL):').upper() | |
period = st.selectbox('Select the period for analysis:', options=['1mo', '3mo', '6mo'], index=0) | |
interval = st.selectbox('Select the data interval:', options=['1h', '1d'], index=0) | |
# Analyze button | |
if st.button('Analyze'): | |
if not ticker: | |
st.error('Please provide the stock ticker symbol.') | |
else: | |
try: | |
# Initialize YFinance Client and fetch historical stock data | |
client = YFinanceClient(ticker) | |
data = client.fetch_historical_prices(period=period, interval=interval) | |
# Calculate indicators | |
data = calculate_sma(data, 'close', 21) | |
data = calculate_sma(data, 'close', 50) | |
data = calculate_bollinger_bands(data) | |
# Generate signals | |
data = generate_signals(data) | |
# Plotting | |
st.write(f'Analysis and Signals for {ticker}') | |
plot_data_with_indicators_and_signals(data) | |
except Exception as e: | |
st.error(f'Failed to fetch and analyze data for {ticker}. Error: {str(e)}') | |