AminHP / gym-anytrading

The most simple, flexible, and comprehensive OpenAI Gym trading environment (Approved by OpenAI Gym)
MIT License
2.1k stars 465 forks source link

Clarification: Position Prediction #48

Closed QuantumCrazy closed 3 years ago

QuantumCrazy commented 3 years ago

I would like to clarify something. So I imported the standard environment 'stocks-v0' but then overlayed a custom environment on top of that with extra features beyond just OHVLC. I split my dataframe into training and testing. Lets say the shape[0] of my df is 100,000 with row 100,000 as the latest trade data row. If I train on the first X rows, then test on X+1 rows up to row 99,999, is the position that the model spits out, 1 or 0, for the 100,000 row?

AminHP commented 3 years ago

Unfortunately, I don't understand your question, but I try to give a bit of information that might help. Generally in machine learning, a dataset should be split into three consequent parts: training, validation, test.

Firstly, you train your model using the training set, then validate your model on the validation set and try to tune the model's hyperparameters. Finally, check how much profit the model makes on the test set, and this is the set that should be used for comparing different models.

The best model is the one that makes the highest profit on the test set. After finding this model, you can use it to trade on future data.

QuantumCrazy commented 3 years ago

Hi AminHP, OK to better explain, I only have training and testing splits, I do not have a validation set. I am doing a sort of validation analysis by running different instances of the model with various hyperparameter settings and comparing which one(s) perform better. So that's pretty much my own in-house version of "hyperparameter tuning".

My question refers to the trade position that the model produces, either 1 or 0 based on the test set. Is that the signal used to make trades on the latest data? That's what I am currently doing. My test set is unseen by the model's training and includes the latest data.

When we can use the "best model" to trade in the future, does it still need to do training every time it runs or not? If not, is the best practice to save the model and load it on only the new data?

AminHP commented 3 years ago

You are doing it right.

I think the best model needs to be trained and updated by new data, but not every time. Maybe once a week or month would be enough.

QuantumCrazy commented 3 years ago

Thanks.....that makes sense as I think about it. I guess it depends on how big your test set is and this will be a judgement call on the developer's side.