AI4Finance-Foundation / FinRL-Tutorials

Tutorials. Please star.
https://ai4finance.org
MIT License
819 stars 343 forks source link

Please solve this error: Could not infer dtype of dict #80

Closed Anupa-123 closed 6 months ago

Anupa-123 commented 6 months ago

RuntimeError Traceback (most recent call last) in <cell line: 1>() ----> 1 account_value_erl=test(start_date = '2022-08-25', 2 end_date = '2022-08-31', 3 ticker_list = ticker_list, 4 data_source = 'alpaca', 5 time_interval= '1Min',

1 frames in DRL_prediction(model_name, cwd, net_dimension, environment) 102 with _torch.no_grad(): 103 for i in range(environment.max_step): --> 104 s_tensor = _torch.as_tensor((state,), device=device) 105 a_tensor = act(s_tensor) # action_tanh = act.forward() 106 action = (

RuntimeError: Could not infer dtype of dict

TheStoneMX commented 6 months ago

but what file are you running and what line number ?

Anupa-123 commented 6 months ago

https://github.com/AI4Finance-Foundation/FinRL-Tutorials/blob/master/3-Practical/FinRL_PaperTrading_Demo.ipynb I am using this file and while testing line number 1151, s_tensor = _torch.as_tensor((state,), device=device) this line creates an error.

TheStoneMX commented 6 months ago
        with _torch.no_grad():
            for i in range(environment.max_step):
                # state =     torch.as_tensor(ary_state, dtype=torch.float32, device=self.device)
                s_tensor = _torch.as_tensor((state,), dtype=torch.float32, device=device)
                a_tensor = act(s_tensor)  # action_tanh = act.forward()
                action = (
                    a_tensor.detach().cpu().numpy()[0]
                )  # not need detach(), because with torch.no_grad() outside
                state, reward, done, extra, _ = environment.step(action)

                total_asset = (
                    environment.amount
                    + (
                        environment.price_ary[environment.day] * environment.stocks
                    ).sum()
                )
                episode_total_assets.append(total_asset)
                episode_return = total_asset / environment.initial_total_asset
                episode_returns.append(episode_return)
                if done:
                    break
TheStoneMX commented 6 months ago

There are a couple of other things you need to fix on that loop....

I sometimes wonder why they have uploaded a broken d=code....

Anupa-123 commented 6 months ago

Thanks a lot.