Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
import pandas as pd
|
5 |
+
from datetime import datetime, timedelta
|
6 |
+
|
7 |
+
# Import your modules here
|
8 |
+
from yfinance_data.fetcher import fetch_data_for_indicators
|
9 |
+
from indicators.sma import add_sma_columns
|
10 |
+
from indicators.bollinger_bands import calculate_bollinger_bands
|
11 |
+
from signals.strategy import generate_buy_signals, generate_sell_signals
|
12 |
+
from utils.plotting import plot_stock_data
|
13 |
+
|
14 |
+
# Initialize the app with Streamlit
|
15 |
+
st.title('StockSwingApp: Stock Signal Generator')
|
16 |
+
|
17 |
+
# User input for the stock symbol
|
18 |
+
symbol = st.text_input('Enter the stock symbol:', value='AAPL')
|
19 |
+
|
20 |
+
# Fetch the stock data
|
21 |
+
data_4h, data_1h = fetch_data_for_indicators(symbol, days=90) # Fetching more days to ensure we have enough data
|
22 |
+
|
23 |
+
# Calculate indicators
|
24 |
+
add_sma_columns(data_4h)
|
25 |
+
add_sma_columns(data_1h)
|
26 |
+
calculate_bollinger_bands(data_4h)
|
27 |
+
|
28 |
+
# Generate signals
|
29 |
+
buy_signals = generate_buy_signals(data_4h, data_1h)
|
30 |
+
sell_signals = generate_sell_signals(data_4h)
|
31 |
+
|
32 |
+
# Plotting
|
33 |
+
st.write(f"Displaying indicators and signals for: {symbol}")
|
34 |
+
plot_stock_data(data_4h, buy_signals=buy_signals, sell_signals=sell_signals, title=f"{symbol} Stock Analysis")
|
35 |
+
|
36 |
+
# Instructions for running the app
|
37 |
+
st.markdown("""
|
38 |
+
To run this app, ensure you have Streamlit and all required packages installed. Then, navigate to the directory containing this script and run: """)
|