MCPcopy
hub / github.com/lilianweng/stock-rnn

github.com/lilianweng/stock-rnn @main sqlite

repository ↗ · DeepWiki ↗
35 symbols 104 edges 8 files 5 documented · 14%
README

Predict stock market prices using RNN

Check my blog post "Predict Stock Prices Using RNN": Part 1 and Part 2 for the tutorial associated.

One 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.

  1. Make sure tensorflow has been installed.
  2. First download the full S&P 500 data from Yahoo! Finance ^GSPC (click the "Historical Data" tab and select the max time period). And save the .csv file to data/SP500.csv.
  3. Run python data_fetcher.py to download the prices of individual stocks in S & P 500, each saved to data/{{stock_abbreviation}}.csv. (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) of stock prices I crawled up to Jul, 2017. Please untar this file to replace the "data" folder in the repo for test runs.)
  4. Run python main.py --help to check the available command line args.
  5. Run python main.py to train the model.

For examples, - Train a model only on SP500.csv; no embedding

python main.py --stock_symbol=SP500 --train --input_size=1 --lstm_size=128 --max_epoch=50
  • Train a model on 100 stocks; with embedding of size 8
python main.py --stock_count=100 --train --input_size=1 --lstm_size=128 --max_epoch=50 --embed_size=8
  • Start your Tensorboard
cd stock-rnn
mkdir logs
tensorboard --logdir ./logs --port 1234 --debug

My python environment: Python version == 2.7

BeautifulSoup==3.2.1
numpy==1.13.1
pandas==0.16.2
scikit-learn==0.16.1
scipy==0.19.1
tensorflow==1.2.1
urllib3==1.8

Core symbols most depended-on inside this repo

_create_one_cell
called by 4
scripts/build_graph.py
to_dict
called by 4
scripts/config.py
save
called by 3
model_rnn.py
generate_one_epoch
called by 2
data_model.py
build_graph
called by 1
model_rnn.py
train
called by 1
model_rnn.py
load
called by 1
model_rnn.py
plot_samples
called by 1
model_rnn.py

Shape

Method 18
Function 14
Class 3

Languages

Python100%

Modules by API surface

model_rnn.py12 symbols
data_model.py5 symbols
scripts/train_model.py4 symbols
scripts/config.py4 symbols
data_fetcher.py4 symbols
main.py3 symbols
scripts/build_graph.py2 symbols
scripts/restore_model.py1 symbols

For agents

$ claude mcp add stock-rnn \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact