AI4Finance-Foundation / FinRL

FinRL: Financial Reinforcement Learning. 🔥
https://ai4finance.org
MIT License
9.72k stars 2.36k forks source link

FinRL_Compare_ElegantRL_RLlib_Stablebaseline3 BUGs! #751

Open julianzero opened 1 year ago

julianzero commented 1 year ago

ElegantRL and RLlib Training:

ValueError Traceback (most recent call last) Cell In [28], line 4 1 #demo for rllib 2 ray.shutdown() #always shutdown previous session if any ----> 4 train(start_date = TRAIN_START_DATE, 5 end_date = TRAIN_END_DATE, 6 ticker_list = config_tickers.DOW_30_TICKER, 7 data_source = 'yahoofinance', 8 time_interval= '1D', 9 technical_indicator_list= INDICATORS, 10 drl_lib='rllib', 11 env=env, 12 model_name='ppo', 13 cwd='./test_ppo', 14 rllib_params = RLlib_PARAMS, 15 total_episodes=30)

Cell In [10], line 12, in train(start_date, end_date, ticker_list, data_source, time_interval, technical_indicator_list, drl_lib, env, model_name, if_vix, **kwargs) 10 if if_vix: 11 data = DP.add_vix(data) ---> 12 price_array, tech_array, turbulence_array = DP.df_to_array(data, if_vix) 13 env_config = {'price_array':price_array, 14 'tech_array':tech_array, 15 'turbulence_array':turbulence_array, 16 'if_train':True} 17 env_instance = env(config=env_config)

File /usr/local/lib/python3.10/site-packages/finrl/meta/data_processor.py:68, in DataProcessor.df_to_array(self, df, if_vix) 67 def df_to_array(self, df, if_vix) -> np.array: ---> 68 price_array, tech_array, turbulence_array = self.processor.df_to_array( 69 df, self.tech_indicator_list, if_vix 70 ) 71 # fill nan and inf values with 0 for technical indicators 72 tech_nan_positions = np.isnan(tech_array)

File /usr/local/lib/python3.10/site-packages/finrl/meta/data_processors/processor_yahoofinance.py:311, in YahooFinanceProcessor.df_to_array(self, df, tech_indicator_list, if_vix) 309 if_first_time = False 310 else: --> 311 price_array = np.hstack( 312 [price_array, df[df.tic == tic][["adjcp"]].values] 313 ) 314 tech_array = np.hstack( 315 [tech_array, df[df.tic == tic][tech_indicator_list].values] 316 ) 317 assert price_array.shape[0] == tech_array.shape[0]

File <__array_function__ internals>:180, in hstack(*args, **kwargs)

File /usr/local/lib/python3.10/site-packages/numpy/core/shape_base.py:345, in hstack(tup) 343 return _nx.concatenate(arrs, 0) 344 else: --> 345 return _nx.concatenate(arrs, 1)

File <__array_function__ internals>:180, in concatenate(*args, **kwargs)

ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 1657 and the array at index 1 has size 1656

RLlib Testing:

AttributeError Traceback (most recent call last) Cell In [29], line 3 1 ray.shutdown() #always shutdown previous session if any ----> 3 account_value_rllib = test(start_date = TEST_START_DATE, 4 end_date = TEST_END_DATE, 5 ticker_list = config_tickers.DOW_30_TICKER, 6 data_source = 'yahoofinance', 7 time_interval= '1D', 8 technical_indicator_list= INDICATORS, 9 drl_lib='rllib', 10 env=env, 11 model_name='ppo', 12 cwd='./test_ppo/checkpoint_000030/checkpoint-30', 13 rllib_params = RLlib_PARAMS)

Cell In [11], line 35, in test(start_date, end_date, ticker_list, data_source, time_interval, technical_indicator_list, drl_lib, env, model_name, if_vix, **kwargs) 31 return episode_total_assets 33 elif drl_lib == 'rllib': 34 #load agent ---> 35 episode_total_assets = DRLAgent_rllib.DRL_prediction( 36 model_name=model_name, 37 env = env, 38 price_array=price_array, 39 tech_array=tech_array, 40 turbulence_array=turbulence_array, 41 agent_path = cwd) 43 return episode_total_assets 45 elif drl_lib == 'stable_baselines3':

File /usr/local/lib/python3.10/site-packages/finrl/agents/rllib/models.py:148, in DRLAgent.DRL_prediction(model_name, env, price_array, tech_array, turbulence_array, agent_path) 146 # ray.init() # Other Ray APIs will not work until ray.init() is called. 147 if model_name == "ppo": --> 148 trainer = MODELS[model_name].PPOTrainer(env=env, config=model_config) 149 elif model_name == "a2c": 150 trainer = MODELS[model_name].A2CTrainer(env=env, config=model_config)

AttributeError: module 'ray.rllib.algorithms.ppo.ppo' has no attribute 'PPOTrainer'

Athe-kunal commented 1 year ago

Hi @julian-z There was some update with the ray package recently, so these are not working. Give me some time to modify these errors.

zhumingpassional commented 1 year ago

@Athe-kunal can we only revise the installing commands by pointing out the version?