An end-to-end quantitative finance pipeline built with Python, predicting next-day closing prices of SPY (S&P 500 ETF) via 3 machine learning models:
- Logistic Regression (binary classification for bullish/bearish signals)
- SVR Support Vector Regression (direct continuous price prediction)
- LSTM Recurrent Neural Network (time-series deep learning forecasting)
After model evaluation with RMSE and R² metrics, we build a long-only trading strategy based on SVR predicted returns, and implement lightweight manual backtesting to calculate core risk-return indicators: total cumulative return, annualized Sharpe ratio, maximum drawdown.
Key Features
- Historical US ETF data download via AkShare
- Technical feature engineering: 10-day & 50-day moving averages
- Strict chronological train/test split (85% train / 15% test, no shuffle to avoid data leakage)
- MinMax normalization for regression and deep learning inputs
- Cross-model prediction visualization
- Full error handling for network, TensorFlow and training exceptions
- Pure manual backtesting (removed backtrader to eliminate environment compatibility errors)
- No Chinese font dependency, compatible with Windows / macOS / Linux / Kaggle
Project Demo Kaggle Interactive Notebook https://www.kaggle.com/code/jenniferxfl/stock-price-forecasting-algorithmic-backtesting
See requirements.txt. Core dependencies:
- Python ≥ 3.9
- numpy, pandas, scikit-learn
- yfinance, ta
- tensorflow / keras (for LSTM)
- prophet (optional, for Facebook Prophet forecasts)
- matplotlib, seaborn
This project is for educational and research purposes only. It does not constitute financial advice. Past performance does not guarantee future results. Always do your own due diligence before making investment decisions.
MIT License
