Giter Club home page Giter Club logo

deep-q-trading's Introduction

Multi-DQN: an Ensemble of Deep Q-Learning Agents for Stock Market Forecasting

Abstract

The stock market forecasting is one of the most challenging application of machine learning, as its historical data are naturally noisy and unstable. Most of the successful approaches act in a supervised manner, labeling training data as being of positive or negative moments of the market. However, training machine learning classifiers in such a way may suffer from over-fitting, since the market behavior depends on several external factors like other markets trends, political events, etc. In this paper, we aim at minimizing such problems by proposing an ensemble of reinforcement learning approaches which do not use annotations (i.e., market goes up or down) to learn, but rather learn how to maximize a return function over the training stage. In order to achieve this goal, we exploit a Q-learning agent trained several times with the same training data and investigate its ensemble behavior in important real-world stock markets. Experimental results in intraday trading indicate better performance than the conventional Buy-and-Hold strategy, which still behaves well in our setups. We also discuss qualitative and quantitative analyses of these results.

Authors

  • Salvatore Carta
  • Anselmo Ferreira
  • Alessandro Sebastian Podda
  • Diego Reforgiato Recupero
  • Antonio Sanna

Info

Description

These files are needed to run the main code:

  • main.py: the entry point of the application;
  • deepQTrading.py: used to organize our data in walks and set up the agents;
  • spEnv.py: the environment used for the agents;
  • mergedDataStructure.py: the data structure we use to instantiate the multi-resolution feature vector;
  • callback.py: a module used to log and trace the results.

Other tools:

  • ensemble.py: can be used to generate the threshold ensemble from the main agents;
  • splitEnsemble.py: can be used to generate the final ensemble for the LONG+SHORT agent (after running ensemble.py).

If you want to adapt the code and use it for more markets, you can use the file utils/parserWeek.py, to create a weekly resolution dataset.
On the other hand, the file utils/plotResults.py can be used to generate a .pdf containing several plots, useful to get information on the testing phase of the algorithm.

Requirements

  • Python 3
  • Tensorflow (1.15): pip install tensorflow==1.15
  • Keras: pip install keras
  • Keras-RL: pip install keras-rl
  • OpenAI Gym: pip install gym
  • Pandas: pip install pandas

Usage

The code needs three positional parameters to be correctly executed:
python main.py <numberOfActions> <isOnlyShort> <ensembleFolder>

  • To run the FULL agent you need to run: python main.py 3 0 ensembleFolder
  • To run the ONLY LONG agent you need to run: python main.py 2 0 ensembleFolder
  • To run the ONLY SHORT agent you need to run: python main.py 2 1 ensembleFolder

where the paramenter ensembleFolder is used to set the name of the folder in which you'll get your results.

deep-q-trading's People

Contributors

asostrife avatar sebastianpodda avatar toniomeepo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.