{"id":13488660,"url":"https://github.com/lilianweng/stock-rnn","last_synced_at":"2025-05-15T17:03:09.955Z","repository":{"id":50305212,"uuid":"96853855","full_name":"lilianweng/stock-rnn","owner":"lilianweng","description":"Predict stock market prices using RNN model with multilayer LSTM cells + optional multi-stock embeddings.","archived":false,"fork":false,"pushed_at":"2022-07-28T06:36:59.000Z","size":55,"stargazers_count":1869,"open_issues_count":25,"forks_count":678,"subscribers_count":115,"default_branch":"master","last_synced_at":"2025-04-08T00:34:30.225Z","etag":null,"topics":["embeddings","lstm","rnn-tensorflow","stock-price-prediction"],"latest_commit_sha":null,"homepage":"https://lilianweng.github.io/lil-log","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lilianweng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"lilianweng"}},"created_at":"2017-07-11T05:23:38.000Z","updated_at":"2025-04-04T18:59:27.000Z","dependencies_parsed_at":"2022-09-08T01:22:52.360Z","dependency_job_id":null,"html_url":"https://github.com/lilianweng/stock-rnn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lilianweng%2Fstock-rnn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lilianweng%2Fstock-rnn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lilianweng%2Fstock-rnn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lilianweng%2Fstock-rnn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lilianweng","download_url":"https://codeload.github.com/lilianweng/stock-rnn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254384937,"owners_count":22062421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["embeddings","lstm","rnn-tensorflow","stock-price-prediction"],"created_at":"2024-07-31T18:01:19.680Z","updated_at":"2025-05-15T17:03:09.922Z","avatar_url":"https://github.com/lilianweng.png","language":"Python","funding_links":["https://github.com/sponsors/lilianweng"],"categories":["Python","others"],"sub_categories":[],"readme":"### 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\u0026P 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 \u0026 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```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flilianweng%2Fstock-rnn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flilianweng%2Fstock-rnn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flilianweng%2Fstock-rnn/lists"}