!DOCTYPE html> CommercEye-Stock Price Monitor

CommercEye-Stock Price Monitor

Welcome to the Stock Price Monitor!

Monitor stock prices and receive alerts to your email when they reach your target levels.

$ python -m pip install -e django/ import yfinance as yf import pandas as pd import time import importlib try: plt = importlib.import_module("matplotlib.pyplot") except ImportError: # matplotlib is optional; provide a minimal stub to avoid NameError in callers class _PltStub: def plot(self, *args, **kwargs): raise RuntimeError("matplotlib is not installed") def show(self, *args, **kwargs): raise RuntimeError("matplotlib is not installed") plt = _PltStub() def calculate_rsi(data, period=14): """ Calculate the Relative Strength Index (RSI) for a given dataset. Parameters: data (pd.DataFrame): The input data frame containing closing prices. period (int): The number of periods to use for calculating RSI. Returns: pd.Series: The RSI values. """ delta = data['Close'].diff() gain = delta.where(delta > 0, 0).rolling(window=period).mean() loss = (-delta.where(delta < 0, 0)).rolling(window=period).mean() rs = gain / loss rsi = 100 - (100 / (1 + rs)) return rsi def calculate_macd(data, short_window=12, long_window=26, signal_window=9): """ Calculate the Moving Average Convergence Divergence (MACD) for a given dataset. Parameters: data (pd.DataFrame): The input data series (e.g., closing prices). short_window (int): The number of periods for the short-term EMA. long_window (int): The number of periods for the long-term EMA. signal_window (int): The number of periods for the signal line. Returns: tuple: A tuple containing MACD, signal line, and histogram values. """ short_ema = data['Close'].ewm(span=short_window, adjust=False).mean() long_ema = data['Close'].ewm(span=long_window, adjust=False).mean() macd = short_ema - long_ema signal = macd.ewm(span=signal_window, adjust=False).mean() histogram = macd - signal return macd, signal, histogram if __name__ == "__main__": try: data = pd.read_csv('lrcx.csv') except FileNotFoundError: raise FileNotFoundError("Required file 'lrcx.csv' not found.") # Example usage: # rsi = calculate_rsi(data) # macd, signal, histogram = calculate_macd(data) def check_stock_price(): print(f"Starting monitoring for {TICKER}...") while True: try: # Fetch the latest stock data # --- CONFIGURATION --- TICKER = "AAPL" # Stock symbol to monitor TARGET_PRICE = 180.00 # Price threshold for alert CONDITION = "above" # Alert when "above" or "below" target CHECK_INTERVAL = 60 # Time to wait between checks (in seconds) def check_stock_price(): print(f"Starting monitoring for {TICKER}...") while True: try: # Fetch the latest stock data stock = yf.Ticker(TICKER) # Get current market price current_price = stock.fast_info["last_price"] print(f"Current {TICKER} price: ${current_price:.2f}") # Check alert conditions if CONDITION == "above" and current_price >= TARGET_PRICE: print( f" ALERT! {TICKER} is ${current_price:.2f} (Target: >= ${TARGET_PRICE:.2f})" ) break # Stop the bot after alerting elif CONDITION == "below" and current_price <= TARGET_PRICE: print( f" ALERT! {TICKER} is ${current_price:.2f} (Target: <= ${TARGET_PRICE:.2f})" ) break # Stop the bot after alerting except Exception as e: print(f"Error fetching data: {e}") # Wait before checking again time.sleep(CHECK_INTERVAL) if __name__ == "__main__": check_stock_price() # Get current market price stock = yf.Ticker(TICKER) current_price = stock.fast_info["last_price"] print(f"Current {TICKER} price: ${current_price:.2f}") # Check alert conditions if CONDITION == "above" and current_price >= TARGET_PRICE: print( f" ALERT! {TICKER} is ${current_price:.2f} (Target: >= ${TARGET_PRICE:.2f})" ) break # Stop the bot after alerting elif CONDITION == "below" and current_price <= TARGET_PRICE: print( f" ALERT! {TICKER} is ${current_price:.2f} (Target: <= ${TARGET_PRICE:.2f})" ) break # Stop the bot after alerting except Exception as e: print(f"Error fetching data: {e}") # Wait before checking again time.sleep(CHECK_INTERVAL) if __name__ == "__main__": check_stock_price()