Home

Awesome

"Buy Me A Coffee"

CryptoEnvironment

CryptoEnvironment is a gym environment for cryptocurrency trading. It provides a simulation environment for training and evaluating reinforcement learning agents.

Features

Installation

Clone the repository:

git clone https://github.com/your-username/crypto-trading-gym.git

To use the CryptoEnvironment, you need to have the following dependencies installed:

You can install these dependencies using pip:

pip install -r requirements.txt

Usage

See more detailed examples in /examples/.

Here's an example of how to use the CryptoEnvironment:

# Imports
import requests
import pandas as pd
import matplotlib.pyplot as plt 
from stable_baselines3.common.vec_env import DummyVecEnv
from stable_baselines3 import PPO
from tradinggym import CryptoEnvironment

# Load the data
data = pd.read_pickle('./data/measurement.pickle')

# Create the CryptoEnvironment
environment = CryptoEnvironment(observations=data, initial_value = 10000, 
                                window_size=5, order_fraction=0.66, trade_fee=0.003375)

# Wrap the training environment in a vectorized form
environment = DummyVecEnv([lambda: environment])

# Create a model
model = PPO('MlpPolicy',env=environment)

# Train the model
model.learn(1000)

# Create an evaluation environment
testenv = CryptoEnvironment(observations=data, initial_value = 10000, 
                            window_size=5, order_fraction=0.66, trade_fee=0.003375)

# Evaluate the model
testenv.evaluate(frame_length=50, render=True, model=model, marker_size=25, verbose=1)

4acc439c-7742-4282-a167-9c19d234ab7c

Evaluation Metrics:  
Initial value:       9999.00
Initial balance:     8728.51
Initial shares:      0.04
Initial split:       0.87
Final value:         10109.60
Profit:              110.60
Return Rate:         1.11%
Avg reward:          -0.00
Max reward:          0.00
Min reward:          -0.00
Cumulative reward:   -0.13

License

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for more details.