duemig /Stanford-Project-Predicting-stock-prices-using-a-LSTM-Network
CS230 (Stanford) project: LSTM networks vs. regularised logistic regression for the monthly direction of the S&P 500, judged against the base rate
★ 299⑂ 50👁 12⑃ 0● 3▤ 0
+0
日增长
299
stars
50
forks
12
watchers
0
prs
3
issues
0
releases
README
Predicting stock prices with LSTM Networks Can a long short term memory (LSTM) network predict whether the S&P 500 will be up or down over the next month, and does it do any better than a regularised logistic regression or a gradient-boosting model? The short answer is no. Across every feature set the models score close to the naive rule of always predicting "up", and a timing strategy built on their forecasts does not beat buying and holding after costs. It started as my course project for CS230 Deep Learning at Stanford. The written report is report.pdf and the notebook is Final Project.ipynb. Every number below is read from the files in results/, which are produced by run_study.py. Method - Target. One non-overlapping observation per month, labelled by the sign of the next month's return. This removes the heavy overlap of the original daily labelling. - Features. Stationary features over 23 look-back windows for each of three families: summed log returns, rolling volatility, and log volume relative to its trailing one-year mean (which removes the long-term growth in turnover). The three families give the seven feature sets of the original project. The baselines use the 69 month-end aggregates; the LSTM reads the most recent 60 trading days of the daily channels. - Validation. The last 20% of months are held out as a test set, used once. The rest is tuned with purged walk-forward cross-validation: a training month whose label reaches a validation month is purged, and a one-month embargo is dropped before each validation block. The baselines fit their scaler inside each fold; the LSTM standardizes its inputs on the training part of its inner split, so no scaling ever sees the data it is evaluated on. - Models. Always-up (the benchmark), an elastic-net logistic regression and a gradient-boosting classifier on the aggregates, and an LSTM on the daily sequences trained with early stopping over 10 seeds. - Evaluation. Accuracy against the base rate, AUC and Brier score with 95% moving-block bootstrap intervals, a paired comparison against always-up, and a timing strategy (long the index next month when the predicted up-probability exceeds a threshold chosen on validation data only) against buy-and-hold after costs. Data The data are daily S&P 500 quotes (^GSPC) from 1980 to the end of 2025, about 11,595 trading days. The price data is not committed. run_study.py downloads it with yfinance on first use and caches it under data/; the source, coverage and download date are recorded in results/summary.json. If Yahoo is blocked, the code falls back to Stooq. To use a file you downloaded yourself, save it as data/gspc.csv with a Date index and Close and Volume columns. Results The test set is 106 months (February 2017 to November 2025) and is 68.9% up months, so always predicting "up" already scores 68.9%. Test-set accuracy and AUC: | Set | Features | Acc EN | Acc GB | Acc LSTM | AUC EN | AUC GB | AUC LSTM