Skip to content

Deep Q-learning driven crypto trader bot

Notifications You must be signed in to change notification settings

chmbrs/DeepQTrader

 
 

Repository files navigation

DeepQTrader

Python 3.6

An implementation of Q-learning applied to (short-term) Bitcoin trading. The model uses n-day windows of OHLC data to determine the best action to take at a given time. i.e. buy, sell or sit.

Motivation

The simple prediction of future prices with RNNs or CNNs is not enough to make mostly correct decisions in the crypto-trading world given the complexity and volatility of such environment. One possible solution could be to use reinforcement learning in combination with some clever deep neural network optimized policies.

This project is an attempt to see if is possible to use reinforcement and Q learning to predict and act super-humanly upon cryptocurrency prices and positions, despite the lack of evidence.

Screenshots

See EpisodesViz notebook

Features

  • Keras neural network.
  • State shape is the window_size x columns.
  • Training happens at each state.
  • Data sequences can have n-dimensions.
  • Visualization plots appear at each tenth episode.
  • Most profitable models and plots are saved.

Installation

To run in your local machine, follow these steps:

  1. Create your working environment. $ python3 -m venv /path/to/venv
  2. Install the dependencies with $ pip3 install.
  3. Create the models directory on the project root. $ mkdir model
  4. Grab the data, choose the window length and the number of episodes.

(bit1.csv or bit2.csv into $ data/ are ready-to-use examples.)

  1. Train the model with the selected parameters.
$ python3 train.py bit1 10 1000

The code then is going to generate an HTML plot at each tenth episode, containing all the actions it took along the training. The most profitable models are saved aswell as their plots.

How to use?

When training finishes (minimum 200 episodes for results):

python3 evaluate.py bit2 model_ep200

Contribute

Please

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Feedbacks, questions, critics, ideas, etc. are extremely welcome.

References

Credits

Inspired and initially forked from Deep Q-Learning

License: MIT

Copyright (c) 2019 Juan José Chambers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT © Juan José Chambers

About

Deep Q-learning driven crypto trader bot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 62.6%
  • Jupyter Notebook 37.4%