FinRL icon indicating copy to clipboard operation
FinRL copied to clipboard

Help with ElegantRL! Reconstructing an Env for Testing after Training?

Open julianzero opened this issue 1 year ago • 4 comments

Hi everyone,

After going through the code carefully, with ElegantRL, I believe it is necessary to reconstruct a new env for testing/trading after training with an old env.

Training via Elegantrl demands a price array, a tech array, and an turbulence array, three arrays as inputs, while testing/trading demands an instance of env, which already includes env configs that contains the three arrays above. So I believe the three arrays should be different for training and testing.

The tutorial is incorrect! Please confirm or comment if you happen to read this post!

Thanx.

julianzero avatar Mar 04 '23 09:03 julianzero

yeah, I have noticed that issue for quite a long time.

valleysprings avatar Mar 04 '23 11:03 valleysprings

The issue here is tha there is not a strict rule about how to implement a env or a DRL agent, so it will be super confusing to know where to begin using this project. You can use SB3, I think it's correct at this moment.

valleysprings avatar Mar 04 '23 11:03 valleysprings

I would like to fix the "tutorial is incorrect" you mentioned. Could you please put the link to the code that might be wrong in this issue?

the three arrays should be different for training and testing.

I also agree with you on this - during the training phase as well as the testing phase , env should load arrays for different time periods

So the parameters start_date=TEST_START_DATE and end_date=TEST_END_DATE are passed into the function test():

https://github.com/AI4Finance-Foundation/FinRL/blob/3db015dec04f0eb97d6af589a43bcb75adf82cfb/finrl/test.py#L91-L93

Then we fetch the data from TEST_START_DATE to TEST_END_DATE:

https://github.com/AI4Finance-Foundation/FinRL/blob/3db015dec04f0eb97d6af589a43bcb75adf82cfb/finrl/test.py#L27-L35

And we build the env_instance:

https://github.com/AI4Finance-Foundation/FinRL/blob/3db015dec04f0eb97d6af589a43bcb75adf82cfb/finrl/test.py#L37-L43

Finally, the env_instance for testing is passed into the function DRLAgent_erl.DRL_prediction()

https://github.com/AI4Finance-Foundation/FinRL/blob/3db015dec04f0eb97d6af589a43bcb75adf82cfb/finrl/test.py#L50-L58


The policy network maps state to action in:

https://github.com/AI4Finance-Foundation/FinRL/blob/3db015dec04f0eb97d6af589a43bcb75adf82cfb/finrl/agents/elegantrl/models.py#L110-L115

Yonv1943 avatar Mar 05 '23 07:03 Yonv1943

env_config = { "price_array": price_array, "tech_array": tech_array, "turbulence_array": turbulence_array, "if_train": False, } env_instance = env(config=env_config)

if drl_lib == "elegantrl": from finrl.agents.elegantrl.models import DRLAgent as DRLAgent_erl episode_total_assets = DRLAgent_erl.DRL_prediction( model_name=model_name, cwd=cwd, net_dimension=net_dimension, environment=env_instance, )

The three arrays passed into training and testing/prediction functions must be different three arrays, three arrays for training and three other ones for testing or prediction... It will take quite significant effort to rewrite this part.

Good luck!

julianzero avatar Mar 06 '23 07:03 julianzero