Code Monkey home page Code Monkey logo

tradinggym's Introduction

TradingGym

Trading Gym (>Python 3.7)

Trading Gym is an open-source project for the development of deep reinforcement learning algorithms in the context of forex trading.

Highlight of the project

  1. customized gym.env for forex trading, with three actions (buy,sell, nothing). rewards is forex point based and realized by stop loss (SL) and profit taken (PT). The SL is fixed by passing parameter and PT is AI learning to maximize the rewards.
  2. multiply pairs with same time frame, time frame can setup from 1M, 5M, 30M, 1H, 4H. Both over night cash penalty, transaction fee, transaction overnight penalty (SWAP) can be configured.
  3. data process will split the data into daily, weekly or monthly time serial based. and will training in parallel by using Isaac or Ray (coming soon)
  4. file log, console print-out and live graph are available for render

Major Feature

  1. forex feature

    1.1. using Point (5 decimal forex ) for reward and balance calculation

    Basis point

    The last decimal place to which a particular exchange rate is usually quoted is referred to as a point.

Trading Plot

GBTUSD 1
GBTUSD 2 GBTUSD 3 2. data process: (./data/data_process.py)

2.1. processing csv (time, open, high, low, close), the source I used is MetaTrader.

2.2. adding a few required features, such as symbol, day, etc...

2.3. adding TA features by using finta

2.4. splitting data based on time serial into weekly or monthly

2.5 combining different trading pair (e.g GBPUSD, EURUSD...) into on csv for vector process. (so far manually)
  1. environment:

    3.1. action_space = spaces.Box(low=0, high=3, shape=(len(assets), ))

    3.2. _action = floor(action) {0:buy, 1:sell,2:nothing}

    3.3. action_price is the current candlestick close price.

    3.4. observation_space contains current balance, .. (draw down) * assets + (TA features)*assets

    3.5. using fix stop_loss (SL) parameter and fraction calculation for profit_taken (PT) as a part of action

    3.6. overnight cash penalty, transaction fee, transaction holding over night penalty

    3.7. rewards will be realized once SL or PT trigger at next step

    3.8. max holding

    3.9. done when balance <= x or step == len(df) [reach the weekend] if step == len(df) close all holding position at close price.

The trading environment:

Candle Trading is a trading environment with input ohlc (open, high,low,close candlestick/bar) data, it is very useful to forex (currency) trading. We use profit-taking (machine learning) and fixed stop-loss.

Create your own data_process

To create your own data, you can use data_process base class which can be found in the file 'data/data_process.py'.

Compatibility with OpenAI gym

The tgym (trading environment) is inherited from OpenAI Gym. We aim to entirely base it upon OpenAI Gym architecture and propose Trading Gym as an additional OpenAI environment.

Examples

ppo_test.ipynb

tradinggym's People

Contributors

0206pdh avatar cove9988 avatar gitter-badger avatar zbanga 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

tradinggym's Issues

Missing .csv file(s)

dqn_agent.py and data_reader.py reference "price_usdeur.csv" but this file does not exist. data_reader.py tries to read in "ue2.csv" but this file does not exist.

CSVStreamer.py is commented to indicate that the .csv file to be fed into _generator should have no index column, but it not quite clear what the initial .csv data should look like beyond this. Is it just two columns, one with the bid and the other with the ask price of an asset?

ModuleNotFoundError: No module named 'trading_spread'

hi
when I run this code "python C:\Users\jalal\TradingGym\examples\dqn_agent.py" I got below error
how can I fix it?
"C:\Anaconda3\lib\site-packages\h5py_init_.py:36: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as register_converters
Using TensorFlow backend.
Traceback (most recent call last):
File "C:\Users\jalal\TradingGym\examples\dqn_agent.py", line 15, in
from tgym.envs.trading_spread import SpreadTrading
File "C:\Anaconda3\lib\site-packages\tgym\envs_init
.py", line 1, in
from trading_spread import SpreadTrading
ModuleNotFoundError: No module named 'trading_spread'"

Possible collaboration?

Hi, we are working on a similar project. Would you like to collab on one project together?

Let me know

Not working when using .csv file as source of data

Not sure if this has to do with the format of the .csv file I created or not, but when I set "gen_type = 'C'" in "examples/dqn_agent.py" to get data from "./examples/price_2.csv" (which I created), it runs for 2 sessions and then I get the following error:

End of data reached, rewinding.
Traceback (most recent call last):
  File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\tgym-0.1.15-py3.6.egg\envs\trading_tick.py", line 130, in step
    self._tick_buy,self._tick_sell  = next(self._data_generator)
  File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\tgym-0.1.15-py3.6.egg\tgym\core.py", line 74, in __next__
    raise(e)
  File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\tgym-0.1.15-py3.6.egg\tgym\core.py", line 71, in __next__
    return next(self.generator)
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "examples/dqn_agent.py", line 189, in <module>
    next_state, reward, done, _ = environment.step(action)
  File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\tgym-0.1.15-py3.6.egg\envs\trading_tick.py", line 134, in step
    info['status'] = 'No more data.'
UnboundLocalError: local variable 'info' referenced before assignment

My .CSV, I have 4,699 rows in total. In column A, I have bid prices (3.4509...) and in column B I have ask prices (3.4511...). Does this have something to do with it? When I run dqn_agent.py using gen_type = 'R' for a random generator, it works fine.

I'm thinking it has something to do with the values in this section here:

` episodes = 50
episode_length = 10000
trading_fee = 0.05
time_fee = 0
history_length = 50

# history_length number of historical states in the observation vector.
profit_taken = 10
stop_loss = -5    # default -5
render_show = False
trading_type = 'T'
if trading_type == 'T':
    environment = TickTrading(data_generator=generator, trading_fee=trading_fee, time_fee=time_fee, history_length=history_length, episode_length=episode_length, profit_taken=profit_taken, stop_loss=stop_loss)
    action_size = len(TickTrading._actions)
else:
    environment = SpreadTrading(spread_coefficients=[1],
                                data_generator=generator,
                                trading_fee=trading_fee,
                                time_fee=time_fee,
                                history_length=history_length,
                                episode_length=episode_length)
    action_size = len(SpreadTrading._actions)
state = environment.reset()`

...but can't seem to find a working combination. Thoughts? Thanks!

Hi, I can't download on a mac

Hi, I can't download. I use a mac. I need your help. here is my error message:

Pauls-MacBook-Pro:~ paul$ pip3 install https://github.com/cove9988/TradingGym.git
Collecting https://github.com/cove9988/TradingGym.git
Downloading https://github.com/cove9988/TradingGym.git
/ 81kB 467kB/s
Cannot unpack file /private/var/folders/bd/d0vxwn3j5rnfjwnsgy0wp0300000gn/T/pip-wtngrslj-unpack/TradingGym.git (downloaded from /private/var/folders/bd/d0vxwn3j5rnfjwnsgy0wp0300000gn/T/pip-6v70569e-build, content-type: text/html; charset=utf-8); cannot detect archive format
Cannot determine archive format of /private/var/folders/bd/d0vxwn3j5rnfjwnsgy0wp0300000gn/T/pip-6v70569e-build

找不到csv数据

找不到csv数据,不知道数据的格式,能不能发一份数据上来.

ModuleNotFoundError: No module named 'trading'

Using TensorFlow backend.
Traceback (most recent call last):
File "dqn_agent.py", line 15, in
from tgym.envs.trading_spread import SpreadTrading
File "/home/smilewater/anaconda3/lib/python3.6/site-packages/tgym/envs/init.py", line 1, in
from trading import SpreadTrading
ModuleNotFoundError: No module named 'trading'

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.