We apply reinforcement learning for stock trading.
import utils
# fetch symbols from yahoo finance
symbols = utils.get_sap_symbols('sap500')
# fetch Open value from 01/04/2015 to 01/04/2016
input_data = utils.get_data_list_key('2015-04-01', '2016-04-01', symbols, 'Open')
We have two models:
When is optimal to sell out stocks is challenging task. I implemented the following alogrithm to determine if selling out stocks is more profitable than holding stocks. A learning is based on based on DQN. To give stability, I introduced Double Q-Learning. The figure below is a learned result from 01/04/2015 to 01/04/2016. The blue points inidiate points where it's better to sell stocks if you have.
Edit DQNConfig of config.py from
self.save_path = '/path/to/your/save/path/model.ckpt'
to your save path. Then, you can try
python main.py "dqn"
Constructing optimal portfolio that makes profits safely is important for fund management. I implemented an algorithm to prdocue portfolios that makes profits. A learning algorighm is based on DDPG. The figure below is a trading result. After learned with data from 01/04/2012 to 01/04/2013, trade on data from 01/04/2013 to 01/04/2014.
Edit DDPGConfig of config.py from
self.save_path = '/path/to/your/save/path/model.ckpt'
to your save path. Then, you can try
python main.py "ddpg"