ClementPerroud / Gym-Trading-Env

A simple, easy, customizable Gymnasium environment for trading.
https://gym-trading-env.readthedocs.io/
MIT License
304 stars 66 forks source link

Minor multi dataset bug in environments.py #8

Open varanova opened 1 year ago

varanova commented 1 year ago

In the MultiDatasetTradingEnv function, the randomization function of dataset selection has a strong bias towards earlier datasets in the list. (I noticed my first 10% of datasets getting selected far more often.)

The fix was to change line 387 From: random_int = np.random.randint(potential_dataset_pathes.size) To: random_int = np.random.choice(potential_dataset_pathes)

After this change the datasets get hit very equally.

MickyDowns commented 7 months ago

@varanova Your fix worked well.

There's a second, very minor, MultiDatasetTradingEnv issue. Both the vanilla env and the multi-dataset env use self.name. The former uses self.name first to label the environment (I use this to denote the experiment I'm running). The latter uses self.name to denote the pickle data file currently being used to feed the environment... overwriting the initial value.

The challenge comes when you use save_on_render() in the vanilla environment which rather than saving as "exp03a_2024-02-24_15-16-35.pkl", saves as "dat02.pkl_2024-02-24_15-16-35.pkl".

The fix is straightforward. Change references to "name" that refer to the data store to "db_name". If you want to be thorough, you can change references to the environment name to "env_name".