AI4Finance-Foundation / FinRL

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

TypeError: 'NoneType' object is not subscriptable #1028

Open Meimao232 opened 1 year ago

Meimao232 commented 1 year ago

Describe the bug

TypeError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_32384/3594883500.py in 2 PPO_model_kwargs, 3 DDPG_model_kwargs, ----> 4 timesteps_dict)

~\FinRL\finrl\agents\stablebaselines3\models.py in run_ensemble_strategy(self, A2C_model_kwargs, PPO_model_kwargs, DDPG_model_kwargs, timesteps_dict) 672 iter_num=i, 673 turbulence_threshold=turbulence_threshold, --> 674 initial=initial, 675 ) 676 ############## Trading ends ##############

~\FinRL\finrl\agents\stablebaselines3\models.py in DRL_prediction(self, model, name, last_state, iter_num, turbulence_threshold, initial) 287 trade_env = DummyVecEnv( 288 [ --> 289 lambda: StockTradingEnv( 290 df=trade_data, 291 stock_dim=self.stock_dim,

D:\anaconda3\envs\tf1x\lib\site-packages\stable_baselines3\common\vec_env\dummy_vec_env.py in init(self, env_fns) 26 27 def init(self, env_fns: List[Callable[[], gym.Env]]): ---> 28 self.envs = [_patch_env(fn()) for fn in env_fns] 29 if len(set([id(env.unwrapped) for env in self.envs])) != len(self.envs): 30 raise ValueError(

D:\anaconda3\envs\tf1x\lib\site-packages\stable_baselines3\common\vec_env\dummy_vec_env.py in (.0) 26 27 def init(self, env_fns: List[Callable[[], gym.Env]]): ---> 28 self.envs = [_patch_env(fn()) for fn in env_fns] 29 if len(set([id(env.unwrapped) for env in self.envs])) != len(self.envs): 30 raise ValueError(

~\FinRL\finrl\agents\stablebaselines3\models.py in () 305 mode="trade", 306 iteration=iter_num, --> 307 print_verbosity=self.print_verbosity, 308 ) 309 ]

~\FinRL\finrl\meta\env_stock_trading\env_stocktrading.py in init(self, df, stock_dim, hmax, initial_amount, num_stock_shares, buy_cost_pct, sell_cost_pct, reward_scaling, state_space, action_space, tech_indicator_list, turbulence_threshold, risk_indicator_col, make_plots, print_verbosity, day, initial, previous_state, model_name, mode, iteration) 74 self.iteration = iteration 75 # initalize state ---> 76 self.state = self._initiate_state() 77 78 # initialize reward

~\FinRL\finrl\meta\env_stock_trading\env_stocktrading.py in _initiate_state(self) 426 state = ( ---> 427 [self.previous_state[0]] 428 + self.data.close.values.tolist() 429 + self.previous_state[ 430 (self.stock_dim + 1) : (self.stock_dim * 2 + 1) 431 ] 432 + sum( 433 ( 434 self.data[tech].values.tolist() 435 for tech in self.tech_indicator_list 436 ), 437 [], 438 ) 439 )

TypeError: 'NoneType' object is not subscriptable

To Reproduce Steps to reproduce the behavior:

  1. Go to 'FinRL_Ensemble_StockTrading_ICAIF_2020'
  2. run 'df_summary = ensemble_agent.run_ensemble_strategy(A2C_model_kwargs, PPO_model_kwargs, DDPG_model_kwargs, timesteps_dict)'
  3. See error

Expected behavior Obviously, according to the error, the self.previous_state is an empty list [], we can see it in the init function.

image

I think it's not a package install error, but a coding mistake. I'm not familiar to finrl, how can I fix it?

mmmarchetti commented 1 year ago

I ran the code on Google Colab and encountered no issues. Please provide additional information regarding your code's execution.

image

image