Closed zhipentian closed 3 weeks ago
Have you modified the dizoo.gym_anytrading.envs.StocksEnv? The 'pq' needs to pass the parameter 'stocks_data_filename'='STOCKS_GOOGL' instead of "df"
There is a tutorial for gym-anytrading.
Yes, I made the changes to dizoo. gym anytrading. envs The content of the data section obtained by StocksEnv has not been modified in other locations, but even if the original 'stocks_data_file name'='STORKS_GOOGL' is used to pass parameters, this problem still occurs.
And thank you for providing the tutorial link, thank you very much!!
Sorry I can't reproduce your error because I'm not sure about your development environment. And our repo has not yet tried to adapt gym-anytrading to stable-baseline.
source code:
import pandas as pd df = pd.read_csv('datasets/STOCKS_GOOGL.csv', parse_dates=True, index_col='Date') from easydict import EasyDict from dizoo.gym_anytrading.envs import StocksEnv pq=EasyDict({"env_id": 'stocks-v0', "eps_length": 300, "train_range": None, "test_range": None, "window_size": 20,"df": df}) env = StocksEnv(pq) from stable_baselines3 import PPO model = PPO('MlpPolicy', env, verbose=1) model.learn(total_timesteps=1000)
Run Error
Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1\plugins\python-ce\helpers\pydev\pydevd.py", line 1535, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\per\AI\chinaA\dingenvtest.py", line 17, in
model.learn(total_timesteps=1000)
File "C:\ProgramData\miniconda3\envs\mypy39\lib\site-packages\stable_baselines3\ppo\ppo.py", line 315, in learn
return super().learn(
File "C:\ProgramData\miniconda3\envs\mypy39\lib\site-packages\stable_baselines3\common\on_policy_algorithm.py", line 287, in learn
total_timesteps, callback = self._setup_learn(
File "C:\ProgramData\miniconda3\envs\mypy39\lib\site-packages\stable_baselines3\common\base_class.py", line 423, in _setup_learn
self._last_obs = self.env.reset() # type: ignore[assignment]
File "C:\ProgramData\miniconda3\envs\mypy39\lib\site-packages\stable_baselines3\common\vec_env\dummy_vec_env.py", line 78, in reset
self._save_obs(env_idx, obs)
File "C:\ProgramData\miniconda3\envs\mypy39\lib\site-packages\stable_baselines3\common\vec_env\dummy_vec_env.py", line 108, in _save_obs
self.buf_obs[key][env_idx] = obs
ValueError: could not broadcast input array from shape (62,) into shape (20,3)
Off topic suggestions
gym_anytrading, Please add this tutorial!!!