AI4Finance-Foundation / FinRL

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

TypeError: got an unexpected keyword argument 'index' #842

Open szd5654125 opened 1 year ago

szd5654125 commented 1 year ago

I got this error after run "FinRL_Ensemble_StockTrading_ICAIF_2020"

To Reproduce Steps to reproduce the behavior:

  1. restart and run all

    | time/ | | | fps | 68 | | iterations | 2000 | | time_elapsed | 146 | | total_timesteps | 10000 | | train/ | | | entropy_loss | -41.2 | | explained_variance | 0.0993 | | learning_rate | 0.0007 | | n_updates | 1999 | | policy_loss | 62.5 | | reward | 1.2670404 | | std | 1 | | value_loss | 3.2 |

    ======A2C Validation from: 2021-01-04 to 2021-04-06

    TypeError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_16232\3594883500.py in ----> 1 df_summary = ensemble_agent.run_ensemble_strategy(A2C_model_kwargs, 2 PPO_model_kwargs, 3 DDPG_model_kwargs, 4 timesteps_dict)

F:\anaconda3\lib\site-packages\finrl\agents\stablebaselines3\models.py in run_ensemble_strategy(self, A2C_model_kwargs, PPO_model_kwargs, DDPG_model_kwargs, timesteps_dict) 506 ) 507 val_obs_a2c = val_env_a2c.reset() --> 508 self.DRL_validation( 509 model=model_a2c, 510 test_data=validation,

F:\anaconda3\lib\site-packages\finrl\agents\stablebaselines3\models.py in DRL_validation(self, model, test_data, test_env, testobs) 274 for in range(len(test_data.index.unique())): 275 action, _states = model.predict(test_obs) --> 276 test_obs, rewards, dones, info = test_env.step(action) 277 278 def DRL_prediction(

F:\anaconda3\lib\site-packages\stable_baselines3\common\vec_env\base_vec_env.py in step(self, actions) 160 """ 161 self.step_async(actions) --> 162 return self.step_wait() 163 164 def get_images(self) -> Sequence[np.ndarray]:

F:\anaconda3\lib\site-packages\stable_baselines3\common\vec_env\dummy_vec_env.py in step_wait(self) 41 def step_wait(self) -> VecEnvStepReturn: 42 for env_idx in range(self.num_envs): ---> 43 obs, self.buf_rews[env_idx], self.buf_dones[env_idx], self.buf_infos[env_idx] = self.envs[env_idx].step( 44 self.actions[env_idx] 45 )

F:\anaconda3\lib\site-packages\finrl\meta\env_stock_trading\env_stocktrading.py in step(self, actions) 284 ) 285 plt.plot(self.asset_memory, "r") --> 286 plt.savefig( 287 "results/accountvalue{}{}{}.png".format( 288 self.mode, self.model_name, self.iteration

F:\anaconda3\lib\site-packages\matplotlib\pyplot.py in savefig(*args, kwargs) 952 def savefig(*args, *kwargs): 953 fig = gcf() --> 954 res = fig.savefig(args, kwargs) 955 fig.canvas.draw_idle() # Need this if 'transparent=True', to reset colors. 956 return res

F:\anaconda3\lib\site-packages\matplotlib\figure.py in savefig(self, fname, transparent, kwargs) 3272 ax.patch._cm_set(facecolor='none', edgecolor='none')) 3273 -> 3274 self.canvas.print_figure(fname, kwargs) 3275 3276 def ginput(self, n=1, timeout=30, show_clicks=True,

F:\anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs) 2336 # force the figure dpi to 72), so we need to set it again here. 2337 with cbook._setattr_cm(self.figure, dpi=dpi): -> 2338 result = print_method( 2339 filename, 2340 facecolor=facecolor,

F:\anaconda3\lib\site-packages\matplotlib\backend_bases.py in (*args, kwargs) 2202 "bbox_inches_restore"} 2203 skip = optional_kws - {inspect.signature(meth).parameters} -> 2204 print_method = functools.wraps(meth)(lambda args, kwargs: meth( 2205 *args, **{k: v for k, v in kwargs.items() if k not in skip})) 2206 else: # Let third-parties do as they see fit.

F:\anaconda3\lib\site-packages\matplotlib_api\deprecation.py in wrapper(*inner_args, inner_kwargs) 383 # calling bind()). 384 return func(*inner_args, *inner_kwargs) --> 385 arguments = signature.bind(inner_args, inner_kwargs).arguments 386 if is_varargs and arguments.get(name): 387 warn_deprecated(

F:\anaconda3\lib\inspect.py in bind(self, *args, *kwargs) 3023 if the passed arguments can not be bound. 3024 """ -> 3025 return self._bind(args, kwargs) 3026 3027 def bind_partial(self, /, args, **kwargs):

F:\anaconda3\lib\inspect.py in _bind(self, args, kwargs, partial) 3012 arguments[kwargs_param.name] = kwargs 3013 else: -> 3014 raise TypeError( 3015 'got an unexpected keyword argument {arg!r}'.format( 3016 arg=next(iter(kwargs))))

TypeError: got an unexpected keyword argument 'index'

Desktop (please complete the following information):

skhonsha commented 1 year ago

Do you know def _buy_stock(self, index, action): def _do_buy(): if ( self.state[index + 2 * self.stock_dim + 1] != True ): # check if the stock is able to buy

what does this condition mean?

tobias-stein commented 1 year ago

Running into the same issue.

Macbook Air M1, python version 3.8.16

tobias-stein commented 1 year ago

Hi, I did a little debugging and it seems the following line in the stock trading environment is causing the error

https://github.com/AI4Finance-Foundation/FinRL/blob/master/finrl/meta/env_stock_trading/env_stocktrading.py#L290

After commenting that line out the code seems working. Also I had a quick check in the pyplot docs and couldn't find that parameter. Maybe some weird code merge artifact.