Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import yfinance as yf | |
| import pandas as pd | |
| import pandas_ta as ta | |
| import matplotlib.pyplot as plt | |
| # Streamlit interface setup | |
| st.title("Breakout Trading Analysis Tool") | |
| ticker = st.text_input("Enter Stock Ticker:", value="AAPL") | |
| timeframe = st.selectbox("Select Time Frame:", options=["1d", "1wk", "1mo"], index=0) | |
| analyze_button = st.button("Analyze Breakout Points") | |
| if analyze_button: | |
| # Fetching the stock data | |
| stock_data = yf.download(ticker, period="1y", interval=timeframe) | |
| # Calculating technical indicators for breakout identification (e.g., moving averages) | |
| stock_data['SMA50'] = ta.sma(stock_data['Close'], length=50) | |
| stock_data['SMA200'] = ta.sma(stock_data['Close'], length=200) | |
| # Example breakout logic: SMA50 crossing above SMA200 | |
| crossover_points = stock_data[(stock_data['SMA50'] > stock_data['SMA200']) & (stock_data['SMA50'].shift(1) < stock_data['SMA200'].shift(1))] | |
| # Plotting | |
| plt.figure(figsize=(10, 6)) | |
| plt.plot(stock_data['Close'], label='Close Price', color='skyblue') | |
| plt.plot(stock_data['SMA50'], label='50-Day SMA', color='green') | |
| plt.plot(stock_data['SMA200'], label='200-Day SMA', color='red') | |
| plt.scatter(crossover_points.index, crossover_points['Close'], color='magenta', label='Breakout Points', zorder=5) | |
| plt.title(f"{ticker} Breakout Points Analysis") | |
| plt.legend() | |
| # Display plot in Streamlit | |
| st.pyplot(plt) | |