FinRL
FinRL copied to clipboard
TypeError: 'NoneType' object is not subscriptable
Describe the bug
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_32384/3594883500.py in
~\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
~\FinRL\finrl\agents\stablebaselines3\models.py in
~\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:
- Go to 'FinRL_Ensemble_StockTrading_ICAIF_2020'
- run 'df_summary = ensemble_agent.run_ensemble_strategy(A2C_model_kwargs, PPO_model_kwargs, DDPG_model_kwargs, timesteps_dict)'
- 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.
I think it's not a package install error, but a coding mistake.
I'm not familiar to finrl, how can I fix it?
I ran the code on Google Colab and encountered no issues. Please provide additional information regarding your code's execution.