Predict Stock Prices Using RNN: Part 1
Lil'Log
Lilian Weng dropped a hands-on Tensorflow tutorial for building an RNN with LSTM cells to predict S&P 500 prices. It skips synthetic toy data for real market history back to 1950, which most guides don't bother with.
Based on reporting by Lil'Log — read the original for the full story.
Summary, retelling and take written by AI under human oversight; images are AI-generated illustrations. How we work · Report an error
Lilian Weng's latest post is less about beating the stock market and more about beating Tensorflow's own documentation. Her pitch is simple: most RNN tutorials floating around are either stale, built on fake data, or assume you already know the API. So she wrote her own, using real S&P 500 closing prices from January 3, 1950 through June 23, 2017, pulled straight from Yahoo Finance.
The technical setup is where the real value sits. Weng slices the price series into fixed-size, non-overlapping windows, then chains several of those windows together as one training input, an approach borrowed loosely from the Penn Tree Bank example that ships with Tensorflow. With input_size set to 3 and num_steps set to 2, she shows exactly how nine raw prices become one training example and one label. That kind of concrete walkthrough is rare; most tutorials wave their hands at the math and move on.
She also flags a problem that trips up a lot of beginners: raw stock prices trend upward forever, so a model trained on decades of history chokes when asked to predict values it's never seen. Her fix is to normalize each window against the last known price in the previous one, turning the task from predicting absolute dollar figures into predicting relative change. It is not a fancy trick, but it is the difference between a model that produces garbage and one that produces something plausible.
From there the post walks through actual Tensorflow code: placeholders for inputs, targets and learning rate, a stacked LSTMCell wrapped in dropout, a dynamic_rnn call, and a training loop with a decaying learning rate schedule. Weng is upfront that this is a demonstration of mechanics, not a serious trading strategy, and she says as much when she admits she didn't try hard to improve the actual predictions. The full code lives on her GitHub, and she points to TensorBoard for anyone who wants to see the graph instead of guessing at it.
My take — AI-written commentary, not fact-checked reporting
This is a solid teaching artifact, not a trading edge, and Weng is refreshingly honest about that distinction, which is more than most 'AI predicts stocks' content can claim. The real lesson here is normalization, not neural networks: half the internet's failed price-prediction models skip that step and then wonder why their RNN falls apart on unseen highs. I'd rather see ten more tutorials this candid about limitations than one more breathless thread claiming an LSTM cracked the market.
Read more about this at: Lil'Log