AminHP/gym-anytrading

Examples for RLLIB

javimontero opened this issue · 2 comments

I am struggling on how to use this environment with Ray's RLLIB.

Any idea or sample?

This code should work.

# pip install gym-anytrading ray 'ray[rllib]'

import gym
from gym_anytrading.envs import ForexEnv
from gym_anytrading.datasets import FOREX_EURUSD_1H_ASK

import ray
from ray.rllib.agents import ppo
from ray.tune.registry import register_env


def env_creator(env_config):
    return ForexEnv(
        df=FOREX_EURUSD_1H_ASK,
        window_size=12,
        frame_bound=(12, len(FOREX_EURUSD_1H_ASK))
    )


ray.init()
register_env('my_env', env_creator)
trainer = ppo.PPOTrainer(env='my_env')

while True:
    print(trainer.train())