Skip to content
Reinforcement Learning for finance
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets add assets Nov 19, 2016
model Merge branch 'master' of Jan 7, 2017 modified the instruction for using function Apr 7, 2017 change the architecture for ddpg Jan 7, 2017 modified Nov 19, 2016 modified Nov 17, 2016 modified Jan 6, 2017

Reinforcement Learning for Finance

We apply reinforcement learning for stock trading.

Fetch Data Example

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(symbols, '2015-04-01', '2016-04-01', 'Open')

We have two models:

Exit Rule

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 from

self.save_path = '/path/to/your/save/path/model.ckpt'

to your save path. Then, you can try

python "dqn"

Optimal Portfolio

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 from

self.save_path = '/path/to/your/save/path/model.ckpt'

to your save path. Then, you can try

python "ddpg"
You can’t perform that action at this time.