File size: 1,635 Bytes
c0f4173
 
 
 
e4a10d0
 
 
c0f4173
e4a10d0
d18aeff
e4a10d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c0f4173
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
40
41
42
43
44
45
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.")