AI4Finance-Foundation / FinRL

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

Multiple Stock Ticker (stocks belonging to different indexes/exchanges) #62

Closed serdjo64 closed 3 years ago

serdjo64 commented 3 years ago

Everything is fine when stocks belong to the same index, for instance, MULTIPLE_STOCK_TICKER = ["AAPL", "MSFT", "IBM"]. However, using your own configuration (MULTIPLE_STOCK_TICKER = ["AAPL", "MSFT", "FB"]) and the latest code, crashes are being experienced depending on the value of the use_turbulence parameter (FeatureEngineer ctor):

Case 1: use_turbulence = True

~/qargo/argo/FinRL-Library$ python3 main.py --mode=train /home/srdjan/.local/lib/python3.8/site-packages/pyfolio/pos.py:26: UserWarning: Module "zipline.assets" not found; multipliers will not be applied to position notionals. warnings.warn( ==============Start Fetching Data=========== [*100%***] 1 of 1 completed [*100%***] 1 of 1 completed [*100%***] 1 of 1 completed Shape of DataFrame: (8146, 8) ==============Start Feature Engineering=========== Successfully added technical indicators Traceback (most recent call last): File "main.py", line 53, in main() File "main.py", line 38, in main finrl.autotrain.training.train_one() File "/home/srdjan/qargo/argo/FinRL-Library/finrl/autotrain/training.py", line 36, in train_one processed = fe.preprocess_data(df) File "/home/srdjan/qargo/argo/FinRL-Library/finrl/preprocessing/preprocessors.py", line 53, in preprocess_data df = self.add_turbulence(df) File "/home/srdjan/qargo/argo/FinRL-Library/finrl/preprocessing/preprocessors.py", line 111, in add_turbulence turbulence_index = self.calculate_turbulence(df) File "/home/srdjan/qargo/argo/FinRL-Library/finrl/preprocessing/preprocessors.py", line 137, in calculate_turbulence temp = current_temp.values.dot(np.linalg.pinv(cov_temp)).dot( File "<__array_function__ internals>", line 5, in pinv File "/home/srdjan/.local/lib/python3.8/site-packages/numpy/linalg/linalg.py", line 2003, in pinv u, s, vt = svd(a, full_matrices=False, hermitian=hermitian) File "<__array_function__ internals>", line 5, in svd File "/home/srdjan/.local/lib/python3.8/site-packages/numpy/linalg/linalg.py", line 1661, in svd u, s, vh = gufunc(a, signature=signature, extobj=extobj) File "/home/srdjan/.local/lib/python3.8/site-packages/numpy/linalg/linalg.py", line 97, in _raise_linalgerror_svd_nonconvergence raise LinAlgError("SVD did not converge") numpy.linalg.LinAlgError: SVD did not converge ~/qargo/argo/FinRL-Library$

Case 2: use_turbulence=False

~/qargo/argo/FinRL-Library$ python3 main.py --mode=train /home/srdjan/.local/lib/python3.8/site-packages/pyfolio/pos.py:26: UserWarning: Module "zipline.assets" not found; multipliers will not be applied to position notionals. warnings.warn( ==============Start Fetching Data=========== [*100%***] 1 of 1 completed [*100%***] 1 of 1 completed [*100%***] 1 of 1 completed Shape of DataFrame: (8146, 8) ==============Start Feature Engineering=========== Successfully added technical indicators Traceback (most recent call last): File "main.py", line 53, in main() File "main.py", line 38, in main finrl.autotrain.training.train_one() File "/home/srdjan/qargo/argo/FinRL-Library/finrl/autotrain/training.py", line 75, in train_one envtrain, = e_train_gym.get_sb_env() File "/home/srdjan/qargo/argo/FinRL-Library/finrl/env/env_stocktrading.py", line 297, in get_sb_env obs = e.reset() File "/home/srdjan/.local/lib/python3.8/site-packages/stable_baselines3/common/vec_env/dummy_vec_env.py", line 62, in reset self._save_obs(env_idx, obs) File "/home/srdjan/.local/lib/python3.8/site-packages/stable_baselines3/common/vec_env/dummy_vec_env.py", line 92, in _save_obs self.buf_obs[key][env_idx] = obs ValueError: cannot copy sequence with size 14 to array axis with dimension 19 ~/qargo/argo/FinRL-Library$

BruceYanghy commented 3 years ago

For ["AAPL", "MSFT", "FB"], the time series data range for FB is different than AAPL and MSFT. Let me adjust time series data shape accordingly.