Git Product home page Git Product logo

q-learning-for-trading's Introduction

Overview

This is the code for this video on Youtube by Siraj Raval on Q Learning for Trading as part of the Move 37 course at School of AI. Credits for this code go to ShuaiW.

Related post: Teach Machine to Trade

Dependencies

Python 2.7. To install all the libraries, run pip install -r requirements.txt

Table of content

  • agent.py: a Deep Q learning agent
  • envs.py: a simple 3-stock trading environment
  • model.py: a multi-layer perceptron as the function approximator
  • utils.py: some utility functions
  • run.py: train/test logic
  • requirement.txt: all dependencies
  • data/: 3 csv files with IBM, MSFT, and QCOM stock prices from Jan 3rd, 2000 to Dec 27, 2017 (5629 days). The data was retrieved using Alpha Vantage API

How to run

To train a Deep Q agent, run python run.py --mode train. There are other parameters and I encourage you look at the run.py script. After training, a trained model as well as the portfolio value history at episode end would be saved to disk.

To test the model performance, run python run.py --mode test --weights <trained_model>, where <trained_model> points to the local model weights file. Test data portfolio value history at episode end would be saved to disk.

q-learning-for-trading's People

Contributors

llsourcell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

q-learning-for-trading's Issues

More Fatures

Anyone a hint how i can add more features then just the close price? i am not sure about the prediction values? How does that work?

Thanks

IndexError: tuple index out of range

I have met an error as follows:

File "C:\Users\User\Desktop\research_project\run.py", line 63, in
next_state, reward, done, info = env._step(action)
File "C:\Users\User\Desktop\research_project\env.py", line 73, in _step
self._trade(action)
File "C:\Users\User\Desktop\research_project\env.py", line 97, in _trade
action_vec = action_combo[action]
IndexError: tuple index out of range

May I know how to fix it?

Error during executing run.py file

I am getting the following exception:

None
Traceback (most recent call last):
File "run.py", line 56, in
next_state, reward, done, info = env.step(action)
File "C:\Users\asgha\Anaconda3\envs\tensorflow\lib\site-packages\gym\core.py", line 96, in step
return self._step(action)
File "C:\Users\asgha\OneDrive\Documents\AI\ML\Forex_trading\Q-Learning-for-Trading-master\envs.py", line 68, in _step
self._trade(action)
File "C:\Users\asgha\OneDrive\Documents\AI\ML\Forex_trading\Q-Learning-for-Trading-master\envs.py", line 91, in _trade
action_vec = action_combo[action]
TypeError: 'map' object is not subscriptable

Give credit to the creator you copied the code from

Your content: https://github.com/llSourcell/Q-Learning-for-Trading

Original content: https://github.com/ShuaiW/teach-machine-to-trade (@shuaiw)

It's such a shame that you are running an entire curriculum using code lifted from other people's repositories. The least you could do is give credit to them.

I know it's not a breach of Github's T&S but I expect you to have a decent code of ethics. You don't need to be original and expert but at least be nice and humble. A big chunk of your videos is about finding motivation and being smart about learning. Surely you don't want to come across as a hypocrite.

NotImplementedError by gym

I am getting the following error which executing run.py
state = env.reset()
File "C:\Users\hp\AppData\Local\Programs\Python\Python36\lib\site-packages\gym\core.py", line 69, in reset
raise NotImplementedError
NotImplementedError

Some people have suggested to change env.reset() to env._reset() , I tried it as well but nothing works

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.