{"data":{"slug":"lilianweng-stock-rnn","name":"stock-rnn","tagline":"Predict stock market prices using RNN model with multilayer LSTM cells.","github_url":"https://github.com/lilianweng/stock-rnn","owner":"lilianweng","repo":"stock-rnn","owner_avatar_url":"https://avatars.githubusercontent.com/u/901179?v=4","primary_language":"Python","stars":1990,"forks":673,"topics":["embeddings","lstm","rnn-tensorflow","stock-price-prediction"],"archived":false,"github_pushed_at":"2022-07-28T06:36:59+00:00","maintenance_label":"Dormant","stars_delta_30d":14,"url":"https://www.graphcanon.com/tools/lilianweng-stock-rnn","markdown_url":"https://www.graphcanon.com/tools/lilianweng-stock-rnn.md","api_url":"https://www.graphcanon.com/api/graphcanon/tools/lilianweng-stock-rnn","graph_url":"https://www.graphcanon.com/api/graphcanon/graph?tool=lilianweng-stock-rnn","description":"Predict stock market prices using RNN model with multilayer LSTM cells + optional multi-stock embeddings.","homepage_url":"https://lilianweng.github.io/lil-log","license":null,"open_issues":24,"watchers":115,"ai_summary":"This repository provides a framework for predicting stock market prices using Recurrent Neural Network (RNN) models, particularly focusing on Long Short-Term Memory (LSTM) networks. It includes the implementation of an RNN model with multilayer LSTM cells and supports optional multi-stock embeddings to enhance prediction accuracy.","readme_excerpt":"### Predict stock market prices using RNN\n\nCheck my blog post \"Predict Stock Prices Using RNN\": [Part 1](https://lilianweng.github.io/lil-log/2017/07/08/predict-stock-prices-using-RNN-part-1.html) and [Part 2](https://lilianweng.github.io/lil-log/2017/07/22/predict-stock-prices-using-RNN-part-2.html) for the tutorial associated.\n\nOne thing I would like to emphasize that because my motivation is more on demonstrating how to build and train an RNN model in Tensorflow and less on solve the stock prediction problem, I didn't try too hard on improving the prediction outcomes. You are more than welcome to take this repo as a reference point and add more stock prediction related ideas to improve it. Enjoy.\n\n1. Make sure `tensorflow` has been installed.\n2. First download the full S&P 500 data from [Yahoo! Finance ^GSPC](https://finance.yahoo.com/quote/%5EGSPC?p=^GSPC) (click the \"Historical Data\" tab and select the max time period). And save the .csv file to `data/SP500.csv`.\n3. Run `python data_fetcher.py` to download the prices of individual stocks in S & P 500, each saved to `data/{{stock_abbreviation}}.csv`.\n(NOTE: Google Finance API returns the prices for 4000 days maximum. If you are curious about the data in even early times, try modify `data_fetcher.py` code to send multiple queries for one stock. Here is the data archive ([stock-data-lilianweng.tar.gz](https://drive.google.com/open?id=1QKVkiwgCNJsdQMEsfoi6KpqoPgc4O6DD)) of stock prices I crawled up to Jul, 2017. Please untar this file to replace the \"data\" folder in the repo for test runs.)\n4. Run `python main.py --help` to check the available command line args.\n5. Run `python main.py` to train the model.\n\n\nFor examples,\n- Train a model only on SP500.csv; no embedding\n```bash\npython main.py --stock_symbol=SP500 --train --input_size=1 --lstm_size=128 --max_epoch=50\n```\n\n- Train a model on 100 stocks; with embedding of size 8\n```bash\npython main.py --stock_count=100 --train --input_size=1 --lstm_size=128 --max_epoch=50 --embed_size=8\n```\n\n- Start your Tensorboard\n```bash\ncd stock-rnn\nmkdir logs\ntensorboard --logdir ./logs --port 1234 --debug\n```\n\nMy python environment: \nPython version == 2.7\n```\nBeautifulSoup==3.2.1\nnumpy==1.13.1\npandas==0.16.2\nscikit-learn==0.16.1\nscipy==0.19.1\ntensorflow==1.2.1\nurllib3==1.8\n```","github_created_at":"2017-07-11T05:23:38+00:00","created_at":"2026-07-11T11:29:49.978966+00:00","updated_at":"2026-08-22T06:01:27.725414+00:00","categories":[{"slug":"model-training","name":"Model Training","url":"https://www.graphcanon.com/categories/model-training","markdown_url":"https://www.graphcanon.com/categories/model-training.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/model-training"}],"tags":[{"slug":"embeddings","name":"embeddings"},{"slug":"lstm","name":"lstm"},{"slug":"rnn-tensorflow","name":"rnn-tensorflow"},{"slug":"stock-price-prediction","name":"stock-price-prediction"}],"trust":{"provenance":{"is_fork":false,"github_id":96853855,"owner_type":"User","methodology":"github_public_v1","parent_repo":null,"near_duplicate_slugs":[]},"computed_at":"2026-08-22T06:01:26.909Z","maintenance":{"label":"Dormant","score":18,"methodology":"github_public_v1","releases_90d":0,"days_since_push":1485,"last_release_at":null,"stars_delta_30d":14,"open_issues_delta_30d":0},"security_summary":{"status":"no_lockfile","scanner":null,"low_count":0,"high_count":0,"last_scan_at":"2026-07-11T11:29:51.541Z","medium_count":0,"scan_profile":"none","critical_count":0}},"capability_facts":{"scan":{"source":"repo_scan","observed_at":"2026-08-22T06:01:27.453Z"},"languages":{"value":["python"],"source":"github.language","observed_at":"2026-08-22T06:01:27.453Z"}},"decision_facts":{"hosting":null,"pricing":null,"requirements":null,"constraints":null,"when_to_use":["Forecasting stock prices requires an approach that benefits from long-term memory in sequential data","Improved accuracy is needed when considering multiple stocks for prediction"],"when_not_to_use":["Short-term price predictions dominate the forecasting focus","Single-stock analysis suffices without incorporating multi-stock embeddings"],"source":"enrich:decision_facts","observed_at":"2026-07-12T13:20:55.361Z"},"constraint_facets":null,"decision_summary":[{"label":"Adopt for","value":"Predicts stock market prices using LSTM-based RNNs with optional multi-stock embeddings."}]}}