AI4Finance-Foundation / FinRL-Meta

FinRL­-Meta: Dynamic datasets and market environments for FinRL.
https://ai4finance.org
MIT License
1.28k stars 583 forks source link

"ValueError: cannot convert float NaN to integer" error from agent #170

Closed dev590t closed 2 years ago

dev590t commented 2 years ago

This issue is related a problem I have in #169. I need some help for the PR, but the PR have been merged, it is still WIP, so I open a issue.

In the notebook /tutorials/4-Optimization/Vectorbt_benchmark/connectToAgent.ipynb, I get this error:

run:
trained_a2c = agent.train_model(model=model_a2c, 
                             tb_log_name='a2c',
                             total_timesteps=50000)
output:
/mnt/recoverData/linuxProgram/workspace/Finrl_python3.9/finrl/finrl_meta/env_stock_trading/env_stocktrading.py:158: RuntimeWarning: divide by zero encountered in double_scalars
  available_amount = self.state[0] / (self.state[index + 1]*(1 + self.buy_cost_pct[index])) # when buying stocks, we should consider the cost of trading when calculating available_amount, or we may be have cash<0
/mnt/recoverData/linuxProgram/workspace/Finrl_python3.9/finrl/finrl_meta/env_stock_trading/env_stocktrading.py:158: RuntimeWarning: invalid value encountered in double_scalars
  available_amount = self.state[0] / (self.state[index + 1]*(1 + self.buy_cost_pct[index])) # when buying stocks, we should consider the cost of trading when calculating available_amount, or we may be have cash<0

ValueError: cannot convert float NaN to integer

But the training data doesn't contain any NaN:

processed_full.isnull().sum().sum()
# return 0

I have tried to replace processed_full = processed_full.fillna(0) by processed_full = processed_full.fillna(100). But that does't solve the problem.

How I can avoid the error?