AI4Finance-Foundation / FinRL

FinRL: Financial Reinforcement Learning. šŸ”„
https://ai4finance.org
MIT License
9.66k stars 2.34k forks source link

Single stock prediction not working when using turbulence threshold #277

Closed rektosaure closed 3 years ago

rektosaure commented 3 years ago

Hi,

Stocks models, including ensemble method, don't work with single stock in StockTradingEnv. It fails when running prediction and using turbulence_threshold: e_trade_gym = StockTradingEnv(df = trade, turbulence_threshold = 70, risk_indicator_col='vix', **env_kwargs) df_account_value, df_actions = DRLAgent.DRL_prediction( model=trained_agent, environment = e_trade_gym)


AttributeError Traceback (most recent call last)

in () 1 df_account_value, df_actions = DRLAgent.DRL_prediction( 2 model=trained_agent, ----> 3 environment = e_trade_gym) 3 frames /usr/local/lib/python3.7/dist-packages/finrl/neo_finrl/env_stock_trading/env_stocktrading.py in step(self, actions) 250 self.data = self.df.loc[self.day,:] 251 if self.turbulence_threshold is not None: --> 252 self.turbulence = self.data[self.risk_indicator_col].values[0] 253 self.state = self._update_state() 254 AttributeError: 'numpy.float64' object has no attribute 'values'
Athe-kunal commented 3 years ago

Yes, it is expecting a data frame and it is possible with more than one stock. Probably you can navigate to /usr/local/lib/python3.7/dist-packages/finrl/neo_finrl/env_stock_trading/env_stocktrading.py and substitute this if self.turbulence_threshold is not None:
if len(self.df.tic.unique()) == 1: self.turbulence = self.data[self.risk_indicator_col] elif len(self.df.tic.unique()) > 1: self.turbulence = self.data[self.risk_indicator_col].values[0] self.state = self._update_state()

rektosaure commented 3 years ago

Thank you