AI4Finance-Foundation / FinRL

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

Ensemble StockTrading ICAIF 2020 notebook not working #1000

Open poysh opened 1 year ago

poysh commented 1 year ago

Describe the bug A clear and concise description of what the bug is. When running the ensemble trading strategy, the code raises a ValueError: "If using all scalar values, you must pass an index". This error occurs during the DataFrame construction in the last part of the code.

`ValueError Traceback (most recent call last)

in () ----> 1 df_summary = ensemble_agent.run_ensemble_strategy(A2C_model_kwargs, 2 PPO_model_kwargs, 3 DDPG_model_kwargs, 4 timesteps_dict) 5 frames /usr/local/lib/python3.10/site-packages/finrl/agents/stablebaselines3/models.py in run_ensemble_strategy(self, A2C_model_kwargs, PPO_model_kwargs, DDPG_model_kwargs, timesteps_dict) 666 ) 667 # print("Used Model: ", model_ensemble) --> 668 last_state_ensemble = self.DRL_prediction( 669 model=model_ensemble, 670 name="ensemble", /usr/local/lib/python3.10/site-packages/finrl/agents/stablebaselines3/models.py in DRL_prediction(self, model, name, last_state, iter_num, turbulence_threshold, initial) 319 last_state = trade_env.render() 320 --> 321 df_last_state = pd.DataFrame({"last_state": last_state}) 322 df_last_state.to_csv(f"results/last_state_{name}_{i}.csv", index=False) 323 return last_state /usr/local/lib/python3.10/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy) 707 elif isinstance(data, dict): 708 # GH#38939 de facto copy defaults to False only in non-dict cases --> 709 mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager) 710 elif isinstance(data, ma.MaskedArray): 711 from numpy.ma import mrecords /usr/local/lib/python3.10/site-packages/pandas/core/internals/construction.py in dict_to_mgr(data, index, columns, dtype, typ, copy) 479 arrays = [x.copy() if hasattr(x, "dtype") else x for x in arrays] 480 --> 481 return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy) 482 483 /usr/local/lib/python3.10/site-packages/pandas/core/internals/construction.py in arrays_to_mgr(arrays, columns, index, dtype, verify_integrity, typ, consolidate) 113 # figure out the index, if necessary 114 if index is None: --> 115 index = _extract_index(arrays) 116 else: 117 index = ensure_index(index) /usr/local/lib/python3.10/site-packages/pandas/core/internals/construction.py in _extract_index(data) 643 644 if not indexes and not raw_lengths: --> 645 raise ValueError("If using all scalar values, you must pass an index") 646 647 if have_series: ValueError: If using all scalar values, you must pass an index` `df_summary = ensemble_agent.run_ensemble_strategy(A2C_model_kwargs, PPO_model_kwargs, DDPG_model_kwargs, timesteps_dict)` **To Reproduce** Steps to reproduce the behavior: 1. Open the FinRL_Ensemble_StockTrading_ICAIF_2020.ipynb 2. Run in Colab 3. Proceed to Part 6: Implement DRL Algorithms 4. Observe the ValueError during the execution. **Expected behavior** A clear and concise description of what you expected to happen. The expected behavior is for the code to run without raising a ValueError and return a summary DataFrame containing information about the ensemble strategy's performance. **Screenshots** **Additional context**
manav-iitj commented 1 year ago

I am receiving the same error

ccssyyy commented 1 year ago

I run this notebook successful one month ago,but today I receive this error when I run.

POde97 commented 1 year ago

me too. Same Error

sebnapi commented 1 year ago

See https://github.com/AI4Finance-Foundation/FinRL/issues/1002#issuecomment-1542871478