This project provides a general environment for stock market trading simulation using OpenAI Gym. Training data is a close price of each day, which is downloaded from Google Finance, but you can apply any data if you want. Also, it contains simple Deep Q-learning and Policy Gradient from Karpathy's post.
In fact, the purpose of this project is not only providing a best RL solution for stock trading, but also building a general open environment for further research.
So, please, manipulate the model architecture and features to get your own better solution.
This fork uses stock_market_reinforcement_learning.
- Ready for Python 3.6+
- Uses Tennsorflow backend
- Improves PEP8 compliance
- Windows ready
- Implements testing period
- Python 3.6
- Numpy
- HDF5
- Keras
- Tensorflow
- OpenAI Gym
Install
$ pip install -r requirements.txt
Train Deep Q-learning:
$ python dqn.py <portfolio filename> [model_filename]
Train Policy Gradient:
$ python pg.py <portfolio filename> [model_filename]
For example:
$ python pg.py portfolio.csv model # model filename without extension
After model is trained, you can test it against all symbols in portfolio:
$ python test.py model # model filename without extension
Please be aware that the provided neural network architecture in this repo is too small to learn. o, it may under-fit if you try to learn every stock data. It just fitted for 10 to 100 stock data for a few years, thus you need to design your own architecture and let me know if you have better one!
Below is training curve for Top-10 KOSPI stock datas for 4 years using Policy Gradient.
...
And here is the test:
...
[1] Playing Atari with Deep Reinforcement Learning
[2] Deep Reinforcement Learning: Pong from Pixels
[3] KEras Reinforcement Learning gYM agents, KeRLym
[4] Keras plays catch, a single file Reinforcement Learning example