AI4Finance-Foundation / FinRL

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

question about choose tickers #376

Closed showkeyjar closed 2 years ago

showkeyjar commented 2 years ago

I'm very glad that you develop this interesting framework.

and I found a problem:

your guide jupyter file mentioned: use last 13 years to train and back test

I think, if a stock or ticker can exists on market 13 years, it must be good stock or ticker.

so, the back test looks well.

I think you guys use little future prior knowledge to choose ticker.

I'm wondering if we random choose ticker, what's result could be?

rayrui312 commented 2 years ago

Thanks for pointing it out. You're right about it. We will give more tests and try to avoid future knowledge. You are also welcome to share your test results. Besides, we have connected to paper trading with real-time data. You may have a try.

showkeyjar commented 2 years ago

I follow your document to test multiple tickers:

https://finrl.readthedocs.io/en/latest/tutorial/finrl_multiple_stock.html

but when I use 2021 data to back test,

I find two errors:

1.turbulence can not be calculate, because in your code turbulence can be calculate after a year.

2.when I create a trade env, it cause error:

File "...\anaconda3\envs\money\lib\site-packages\finrl-0.3.3-py3.8.egg\finrl\finrl_meta\env_stock_trading\env_stocktrading.py", line 70, in __init__ File "...\anaconda3\envs\money\lib\site-packages\finrl-0.3.3-py3.8.egg\finrl\finrl_meta\env_stock_trading\env_stocktrading.py", line 366, in _initiate_state AttributeError: 'numpy.float64' object has no attribute 'values'

I found if I have a full year data, it's no problem.

rayrui312 commented 2 years ago

I follow your document to test multiple tickers:

https://finrl.readthedocs.io/en/latest/tutorial/finrl_multiple_stock.html

but when I use 2021 data to back test,

I find two errors:

1.turbulence can not be calculate, because in your code turbulence can be calculate after a year.

2.when I create a trade env, it cause error:

File "...\anaconda3\envs\money\lib\site-packages\finrl-0.3.3-py3.8.egg\finrl\finrl_meta\env_stock_trading\env_stocktrading.py", line 70, in __init__ File "...\anaconda3\envs\money\lib\site-packages\finrl-0.3.3-py3.8.egg\finrl\finrl_meta\env_stock_trading\env_stocktrading.py", line 366, in _initiate_state AttributeError: 'numpy.float64' object has no attribute 'values'

I found if I have a full year data, it's no problem.

You may try to follow the notebook https://github.com/AI4Finance-Foundation/FinRL/blob/master/FinRL_StockTrading_NeurIPS_2018.ipynb here to test multiple tickers. Some of the documents are not updated so perhaps there are some bugs. We are now updating our documents gradually. Sorry for any inconvenience caused.

showkeyjar commented 2 years ago

I find the problem. if one trade day there is only one ticker data, then error occurred:

File "...\anaconda3\envs\money\lib\site-packages\finrl-0.3.3-py3.8.egg\finrl\finrl_meta\env_stock_trading\env_stocktrading.py", line 70, in __init__ File "...\anaconda3\envs\money\lib\site-packages\finrl-0.3.3-py3.8.egg\finrl\finrl_meta\env_stock_trading\env_stocktrading.py", line 366, in _initiate_state AttributeError: 'numpy.float64' object has no attribute 'values'

your example

nether

https://finrl.readthedocs.io/en/latest/tutorial/finrl_multiple_stock.html

nor

https://github.com/AI4Finance-Foundation/FinRL/blob/master/FinRL_StockTrading_NeurIPS_2018.ipynb

consider this condition, so I think in 362 line of finrl\finrl_meta\env_stock_trading\env_stocktrading.py

I think it can not use this condition to check data: if len(self.df.tic.unique()) > 1: and can change this:

if type(self.data) == pd.DataFrame: would you please check if this modify is right?

showkeyjar commented 2 years ago

I find there is more problem if I change this condition, maybe I can wait next version or pull request?

Athe-kunal commented 2 years ago

That function is to grab state space for either multi-stock or single stock. So when you have multiple stocks then .values would work as you will work with a dataframe, but if you have a single stock then .values won't work as they are a list of numpy float values. So you re working with multi-stock or single stock?

showkeyjar commented 2 years ago

That function is to grab state space for either multi-stock or single stock. So when you have multiple stocks then .values would work as you will work with a dataframe, but if you have a single stock then .values won't work as they are a list of numpy float values. So you re working with multi-stock or single stock?

I have some noise data that some date only have one stock, but other date have multi stocks.

showkeyjar commented 2 years ago

I think I choose some tickers that may have suspension or fuse, so if I can ignore those exception days?

showkeyjar commented 2 years ago

when I fix those problems (remove there is only one tick trade days), I found another problem occurred:

env_train, _ = e_trade_gym.get_sb_env() File "...\anaconda3\envs\money\lib\site-packages\finrl-0.3.3-py3.8.egg\finrl\finrl_meta\env_stock_trading\env_stocktrading.py", line 484, in get_sb_env File "...\anaconda3\envs\money\lib\site-packages\stable_baselines3-1.3.0-py3.8.egg\stable_baselines3\common\vec_env\dummy_vec_env.py", line 62, in reset self._save_obs(env_idx, obs) File "...\anaconda3\envs\money\lib\site-packages\stable_baselines3-1.3.0-py3.8.egg\stable_baselines3\common\vec_env\dummy_vec_env.py", line 92, in _save_obs self.buf_obs[key][env_idx] = obs ValueError: could not broadcast input array from shape (20,) into shape (101,)

showkeyjar commented 2 years ago

It sames that you don't care this problem,

could you please tell me how to load trained model and predict one day data?

so that I can predict and backtest in my own data, no need use stable_baselines3

I found there is no doc to tell predict topic.

rayrui312 commented 2 years ago

Sorry for the late reply.

  1. For the 'ValueError: could not broadcast input array from shape (20,) into shape (101,)', it comes from the inconsistency between state input and the preset network input. As the state dimension and the action dimension have to be fixed, to deal with suspension or fuse, you need to remove the whole stock or drop any row with NaN data or fill them with some valid values. Our Alpaca data processor provides a data clean function that can solve this problem, you may have a try.

  2. For tutorials of loading trained models and predictions, you may see notebook here. It contains the training and testing process of three DRL libraries, ElegantRL, RLlib, and Stable-baselines3. You may also see this notebook here, it covers the deployment of DRL agents to paper trading.

We have extended our framework and developed many new supported trading tasks/functions in the past months. We are now cleaning our codes and updating the docs. The docs are of old versions and you may see notebooks on Github as tutorials for now. Sorry for any inconvenience caused.

showkeyjar commented 2 years ago

ok, thanks for your reply, I'll have a try.