Skip to main content

Reinforcement Learning OpenAI Gym environment for crypto-currency trading.

Project description

gym-crypto

OpenAI Gym compatible environment for crypto-currency trading. The environment allows to change the currency the bot trades, the granularity of trading and starting capital of the agent. More configurability to come in the future.

Observation Space

The observation space is a tuple structured as follows:

(OCHLV, Current Capital, Weight of the capital invested)

OCHLV represents Open, Close, High, Low prices and Volume respectively. So the total capital invested into a coin at any time is:

(Current Capital)*(Weight of the capital invested)

Action Space

Action space is a single scalar between -1 and 1, which represents the percentage of the capital that the agent has invested into the currency at the last time step.

-1 representing a full short position and 1 representing a full long position.

Rewards

The reward is defined as the total amount of capital that has been gained/lost for that time-step. This number includes the return on the investment as well as the transaction costs.

Usage

In order to train the agent, the enviroment first has to be configured. This example shows how to handle the training and testing of the agents:

import gym
from gym_crypto import configs

env = gym.make("gym-crypto-v0")
env.configure_env(**configs.DEFAULT_CONFIG)

### Train an agent on the environment

test_config = configs.DEFAULT_CONFIG.update({'start_date':'2019-01-01', 'end_date':'2019-06-01'})
env.configure_env(**test_config)

done = False
observation = env.reset()

while not done:
    action = agent.predict(observation)
    observation, _, done, _ = env.step(action)

returns, weights = env.render()

To get some results from the agent, a env.render() needs to be called, which will return the capital returns as the first variable and weight allocation as the second variable. More detailed results will be coming in the future.

Data

To futher inspect the data two methods can be called from the data_utils module.

from gym_crypto.data_utils.data_utils import *

currencies = get_avaliable_currencies()
full_data = read_data('BTC')

All data was obtained from the Bitfinex API.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gym-crypto-0.0.4.tar.gz (3.8 MB view hashes)

Uploaded Source

Built Distribution

gym_crypto-0.0.4-py3-none-any.whl (3.8 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page