Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'float' object is not subscriptable #540

Closed
futureofworld opened this issue Mar 27, 2022 · 4 comments
Closed

'float' object is not subscriptable #540

futureofworld opened this issue Mar 27, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@futureofworld
Copy link

I got this error while training a model, error look like this, please help to fix this issue
TypeError Traceback (most recent call last)
in ()
1 trained_sac = agent.train_model(model=model_sac,
2 tb_log_name='sac',
----> 3 total_timesteps=60000)

8 frames
/usr/local/lib/python3.7/dist-packages/finrl/finrl_meta/env_stock_trading/env_stocktrading.py in _do_buy()
156 # if self.state[index + 1] >0:
157 # Buy only if the price is > 0 (no missing data in this particular date)
--> 158 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
159 # print('available_amount:{}'.format(available_amount))
160

TypeError: 'float' object is not subscriptable

@YangletLiu YangletLiu added the bug Something isn't working label Mar 27, 2022
@duwf2003
Copy link

My God! It haven't been resolved yet.

@YangletLiu
Copy link
Contributor

Well, would you like to help out? Be a God to this particular bug, :) Thx!

@zhumingpassional zhumingpassional self-assigned this Mar 29, 2022
@zhumingpassional
Copy link
Collaborator

Did you initialize "initial_amount" a float number?

Please see the issue: #518. It can help you. Recently we revised the code.

The following code may help you:

buy_cost_list = sell_cost_list = [0.001] * stock_dimension
num_stock_shares = [0] * stock_dimension

env_kwargs = {
"hmax": 100,
"initial_amount": 1000000,
"num_stock_shares": num_stock_shares,
"buy_cost_pct": buy_cost_list,
"sell_cost_pct": sell_cost_list,
"state_space": state_space,
"stock_dim": stock_dimension,
"tech_indicator_list": config.INDICATORS,
"action_space": stock_dimension,
"reward_scaling": 1e-4
}
e_train_gym = StockTradingEnv(df = train, **env_kwargs)

@zhumingpassional
Copy link
Collaborator

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants