Algorithmic Trading, Machine Learning, and Quantitative Strategy with Python The Three Core Projects Project 1: Unsupervised Learning Trading Strategy (S&P 500) Objective: Use unsupervised machine learning (clustering) to group stocks with similar characteristics and build a monthly rebalanced portfolio. Data: 8 years of price data for S&P 500 constituents (note: the instructor acknowledges this introduces survivorship bias). Feature Engineering: Calculates technical indicators: Garman-Klass volatility, RSI, Bollinger Bands, ATR, and MACD. Calculates momentum features using rolling returns (1 to 12 months). Downloads Fama-French 5-factor data and calculates rolling factor betas for each stock to assess risk exposure. Machine Learning Application: Filters for the top 150 most liquid stocks monthly. Applies a K-Means Clustering algorithm. To ensure consistency across months, the instructor uses custom initial centroids based on RSI thresholds to reliably isolate a "high momentum" cluster. Portfolio Optimization: Uses the pypfopt library to apply Mean-Variance Optimization (Efficient Frontier) to maximize the Sharpe Ratio. Applies constraints (e.g., max 10% weight per stock) to ensure diversification. If the optimizer fails, it defaults to an equal-weight portfolio. Benchmark: S&P 500 (SPY). Project 2: Twitter Sentiment Investing Strategy (NASDAQ 100) Objective: Demonstrate how to extract value from alternative data (social media sentiment) to create a quantitative trading signal. Data: NASDAQ 100 stocks paired with daily Twitter metrics (posts, comments, likes, impressions, and sentiment scores). Feature Engineering: Instead of using raw sentiment or likes (which can be skewed by bots), the instructor creates an "Engagement Ratio" (Comments divided by Likes) to measure genuine human interaction. Filters out noise by requiring minimum thresholds for likes and comments. Strategy Logic: Aggregates the monthly average engagement ratio for each stock. Ranks the stocks cross-sectionally and selects the Top 5 stocks with the highest engagement for the upcoming month. Portfolio Construction: Uses a simple equally-weighted portfolio (no complex optimization) to keep the focus on the alternative data signal. Benchmark: NASDAQ (QQQ). Project 3: Intraday Strategy using a GARCH Model (Single Asset) Objective: Combine daily volatility predictions with intraday technical patterns to execute day trades on a single simulated asset. Data: Simulated daily data and 5-minute intraday data. Daily Signal (Volatility Prediction): Uses the arch library to fit a GARCH model (specifically AR=1, MA=3, chosen via the Bayesian Information Criterion) in a rolling 6-month window. Predicts the next day's variance. Calculates a "Prediction Premium" and generates a daily signal if the premium exceeds 1.5 standard deviations. Intraday Signal (Price Action): Calculates 5-minute RSI and Bollinger Bands. Generates a signal based on momentum breakouts (e.g., RSI > 70 and Close > Upper Bollinger Band). Execution Logic: The strategy only enters a trade (Long or Short) when both the daily GARCH signal and the intraday technical signal align. Enters on the first trigger of the day and holds the position until the market close. Key Concepts & Challenges Discussed Ttheoretical and practical challenges in algorithmic trading: Reflexivity / Feedback Loops: If a machine learning model discovers a predictable market pattern (e.g., prices always rise on Fridays), trading on it will eventually arbitrage the pattern away, causing it to disappear. Survivorship Bias: Using current index constituents for historical backtesting artificially inflates returns because it ignores companies that went bankrupt or were removed from the index. Machine Learning Challenges: Overfitting, non-stationarity, regime shifts, and the "black box" nature of complex neural networks. Tech Stack: The course heavily relies on the Python data science ecosystem, including pandas, numpy, yfinance, pandasta (technical indicators), scikit-learn (clustering), pypfopt (portfolio optimization), and arch (GARCH modeling).