Giter Club home page Giter Club logo

gym-trading's Introduction

OpenAI Gym Environment for Trading

Environment for reinforcement-learning algorithmic trading models

The Trading Environment provides an environment for single-instrument trading using historical bar data.

See here for a jupyter notebook describing basic usage and illustrating a (sometimes) winning strategy based on policy gradients implemented on tensorflow.

gym-trading's People

Contributors

hackthemarket avatar ratajczak 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  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

gym-trading's Issues

Importing Data

Hello and Thanks for the repo, is there a way to import data from a csv (limit order data, bid and offer price) as input to the enviroment?

Environment isn't getting created upon running test_policy_gradients.py

Hi,

I am kind of new to this OpenAI Gym.

While I was trying to run the test_policy_gradient.py file, I am getting the following error.

[2017-04-16 07:51:37,265] policy_gradient logger started.
[2017-04-16 07:51:37,266] Making new env: trading-v0
Traceback (most recent call last):
  File "test_policy_gradient.py", line 17, in <module>
    env = gym.make('trading-v0')
  File "/home/ubuntu/gym/gym/envs/registration.py", line 161, in make
    return registry.make(id)
  File "/home/ubuntu/gym/gym/envs/registration.py", line 118, in make
    spec = self.spec(id)
  File "/home/ubuntu/gym/gym/envs/registration.py", line 147, in spec
    raise error.UnregisteredEnv('No registered env with id: {}'.format(id))
gym.error.UnregisteredEnv: No registered env with id: trading-v0

trying to debug, I included " import gym_trading" in the beginning of the file.

Now, I am facing the following error
unnamed 1

I understand that for some reason, the data frame isn't getting downloaded when I "make" the gym to create an environment, which is why I suspect I am getting this error.

Could you please point out where I am going wrong? Or if there is any fix around this?

Thanks a lot in advance!
Sanketh

How to add this environment to gym?

I am new to OpenAi Gym so i don't know how to add third party environment .So can tell me how to add this environment to gym it will be a great help.

incorrect Quandl code (QECx02)

Hi

thanks a lot for a great project, its really hard to find smth such useful.

I bump in the same issue as in #1, make described changes and came up to next error:

---------------------------------------------------------------------------
NotFoundError                             Traceback (most recent call last)
<ipython-input-3-b93e6210c1a2> in <module>()
----> 1 env = gym.make('trading-v0')
      2 #env.time_cost_bps = 0 #

C:\Anaconda\envs\py353\lib\site-packages\gym\envs\registration.py in make(id)
    159 
    160 def make(id):
--> 161     return registry.make(id)
    162 
    163 def spec(id):

C:\Anaconda\envs\py353\lib\site-packages\gym\envs\registration.py in make(self, id)
    117         logger.info('Making new env: %s', id)
    118         spec = self.spec(id)
--> 119         env = spec.make()
    120         if (env.spec.timestep_limit is not None) and not spec.tags.get('vnc'):
    121             from gym.wrappers.time_limit import TimeLimit

C:\Anaconda\envs\py353\lib\site-packages\gym\envs\registration.py in make(self)
     84 
     85         cls = load(self._entry_point)
---> 86         env = cls(**self._kwargs)
     87 
     88         # Make the enviroment aware of which spec it came from.

c:\users\root\documents\upwork\anton\gitlab\notebooks\lime\gym-trading-master\gym_trading\envs\trading_env.py in __init__(self)
    185   def __init__(self):
    186     self.days = 252
--> 187     self.src = QuandlEnvSrc(days=self.days)
    188     self.sim = TradingSim(steps=self.days, trading_cost_bps=1e-3,
    189                           time_cost_bps=1e-4)

c:\users\root\documents\upwork\anton\gitlab\notebooks\lime\gym-trading-master\gym_trading\envs\trading_env.py in __init__(self, days, name, auth, scale)
     45     self.days = days+1
     46     log.info('getting data for %s from quandl...',QuandlEnvSrc.Name)
---> 47     df = quandl.get(self.name) if self.auth=='' else quandl.get(self.name, authtoken=self.auth)
     48     log.info('got data for %s from quandl...',QuandlEnvSrc.Name)
     49 

C:\Anaconda\envs\py353\lib\site-packages\quandl\get.py in get(dataset, **kwargs)
     46         if dataset_args['column_index'] is not None:
     47             kwargs.update({'column_index': dataset_args['column_index']})
---> 48         data = Dataset(dataset_args['code']).data(params=kwargs, handle_column_not_found=True)
     49     # Array
     50     elif isinstance(dataset, list):

C:\Anaconda\envs\py353\lib\site-packages\quandl\model\dataset.py in data(self, **options)
     45         updated_options = Util.merge_options('params', params, **options)
     46         try:
---> 47             return Data.all(**updated_options)
     48         except NotFoundError:
     49             if handle_not_found_error:

C:\Anaconda\envs\py353\lib\site-packages\quandl\operations\list.py in all(cls, **options)
     12             options['params'] = {}
     13         path = Util.constructed_path(cls.list_path(), options['params'])
---> 14         r = Connection.request('get', path, **options)
     15         response_data = r.json()
     16         Util.convert_to_dates(response_data)

C:\Anaconda\envs\py353\lib\site-packages\quandl\connection.py in request(cls, http_verb, url, **options)
     34         abs_url = '%s/%s' % (ApiConfig.api_base, url)
     35 
---> 36         return cls.execute_request(http_verb, abs_url, **options)
     37 
     38     @classmethod

C:\Anaconda\envs\py353\lib\site-packages\quandl\connection.py in execute_request(cls, http_verb, url, **options)
     42             response = func(url, **options)
     43             if response.status_code < 200 or response.status_code >= 300:
---> 44                 cls.handle_api_error(response)
     45             else:
     46                 return response

C:\Anaconda\envs\py353\lib\site-packages\quandl\connection.py in handle_api_error(cls, resp)
     83         klass = d_klass.get(code_letter, QuandlError)
     84 
---> 85         raise klass(message, resp.status_code, resp.text, resp.headers, code)

NotFoundError: (Status 404) (Quandl Error QECx02) You have submitted an incorrect Quandl code. Please check your Quandl codes and try again.

Do you have any ideas how to fix it?

Potential bug in the trading_env.py?

If I understand the code correctly, there is one bug:
Line 123 of the code trading_env.py:
self.posns[self.step] = action - 1
self.trades[self.step] = self.posns[self.step] - bod_posn

Should be
self.posns[self.step] = bod_posn + action - 1
self.trades[self.step] = action - 1

Does the variable self.trade represent the trades, and posns represent the position after the trades are executed?

No registered env with id: trading-v0

Traceback (most recent call last):
File "/home/binu/.local/lib/python3.6/site-packages/gym/envs/registration.py", line 143, in spec
return self.env_specs[id]
KeyError: 'trading-v0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "trade.py", line 3, in
env = gym.make('trading-v0')
File "/home/binu/.local/lib/python3.6/site-packages/gym/envs/registration.py", line 167, in make
return registry.make(id)
File "/home/binu/.local/lib/python3.6/site-packages/gym/envs/registration.py", line 118, in make
spec = self.spec(id)
File "/home/binu/.local/lib/python3.6/site-packages/gym/envs/registration.py", line 153, in spec
raise error.UnregisteredEnv('No registered env with id: {}'.format(id))
gym.error.UnregisteredEnv: No registered env with id: trading-v0

i have done pip3 install -e . to install the dependencies but i cannot run the agent .
please need help..

self.reset() NotImplementedError

After I installed the gym and it got registered, all I did was to run the following:

import gym
import gym_trading
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import quandl
from matplotlib import interactive

interactive(True)
quandl.ApiConfig.api_key = 'my quandl api key here'
env = gym.make('trading-v0')

And got

WARN: gym.spaces.Box autodetected dtype as <type 'numpy.float32'>. Please provide explicit dtype.
Traceback (most recent call last):
  File "trading.py", line 12, in <module>
    env = gym.make('trading-v0')
  File "/usr/local/lib/python2.7/site-packages/gym/envs/registration.py", line 167, in make
    return registry.make(id)
  File "/usr/local/lib/python2.7/site-packages/gym/envs/registration.py", line 119, in make
    env = spec.make()
  File "/usr/local/lib/python2.7/site-packages/gym/envs/registration.py", line 86, in make
    env = cls(**self._kwargs)
  File "/Users/simradu/reinforcement-learning-an-introduction/my_gyms/gym-trading/gym_trading/envs/trading_env.py", line 193, in __init__
    self.reset()
  File "/usr/local/lib/python2.7/site-packages/gym/core.py", line 71, in reset
    raise NotImplementedError

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.