Check my blog post "Predict Stock Prices Using RNN: Part 1" for the tutorial associated.
- Make sure
tensorflow
has been installed. - 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
. (NOTE: Unfortunately, thestartdate
in the Google finance historical prices url does not seem to work any more. Each stock only gets one year's data, which is too short for training. I will update data_fetcher once I find other better alternative.) - Run
python data_fetcher.py
to download the prices of individual stocks in S & P 500, each saved todata/{{stock_abbreviation}}.csv
. - Run
python main.py --help
to check the available command line args. - 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=5 --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=5 --lstm_size=128 --max_epoch=50 --embed_size=8
My python environment:
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