Spaces:
Runtime error
Runtime error
File size: 1,542 Bytes
2ab2b02 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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)}')
|