Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from binance_api.yfinanceclient import YFinanceClient
|
| 3 |
+
from indicators.sma import calculate_sma
|
| 4 |
+
from indicators.bollinger_bands import calculate_bollinger_bands
|
| 5 |
+
from signals.strategy import generate_signals
|
| 6 |
+
from utils.plotting import plot_data_with_indicators_and_signals
|
| 7 |
+
|
| 8 |
+
# Initialize Streamlit app
|
| 9 |
+
st.title('Stock Signal App')
|
| 10 |
+
|
| 11 |
+
# User inputs
|
| 12 |
+
ticker = st.text_input('Enter the stock ticker symbol (e.g., AAPL):').upper()
|
| 13 |
+
period = st.selectbox('Select the period for analysis:', options=['1mo', '3mo', '6mo'], index=0)
|
| 14 |
+
interval = st.selectbox('Select the data interval:', options=['1h', '1d'], index=0)
|
| 15 |
+
|
| 16 |
+
# Analyze button
|
| 17 |
+
if st.button('Analyze'):
|
| 18 |
+
if not ticker:
|
| 19 |
+
st.error('Please provide the stock ticker symbol.')
|
| 20 |
+
else:
|
| 21 |
+
try:
|
| 22 |
+
# Initialize YFinance Client and fetch historical stock data
|
| 23 |
+
client = YFinanceClient(ticker)
|
| 24 |
+
data = client.fetch_historical_prices(period=period, interval=interval)
|
| 25 |
+
|
| 26 |
+
# Calculate indicators
|
| 27 |
+
data = calculate_sma(data, 'close', 21)
|
| 28 |
+
data = calculate_sma(data, 'close', 50)
|
| 29 |
+
data = calculate_bollinger_bands(data)
|
| 30 |
+
|
| 31 |
+
# Generate signals
|
| 32 |
+
data = generate_signals(data)
|
| 33 |
+
|
| 34 |
+
# Plotting
|
| 35 |
+
st.write(f'Analysis and Signals for {ticker}')
|
| 36 |
+
plot_data_with_indicators_and_signals(data)
|
| 37 |
+
except Exception as e:
|
| 38 |
+
st.error(f'Failed to fetch and analyze data for {ticker}. Error: {str(e)}')
|
| 39 |
+
|