Closed prowgrammmer closed 1 year ago
You found a bug, self.start_idx should be calculated like this.
self.start_idx = np.random.randint(self.window_size - 1, len(self.df) - self._cfg.eps_length)
I will fix it later.
But regarding “len(self.df)”, my test result shows it equals 20. Could you paste the content of “STOCKS_GOOGL_deploy.csv” here?
And if you want window_size = 20
and eps_length = 1
, then it must have at least 21 data points because timestamp needs one step forward.
ok so now with a dataframe of 21 rows I get self.window_size - 1 = 20 and len(self.df) - self._cfg.eps_length = 20 but np.random.randint(20, 20) still gives me the same error.
and I still wonder if there's a better way of doing what I'm trying to do so that I can feed single windows and get the corresponding actions without having to reload the whole model?
Is it supposed to be window_size = 21 this time? I think what you need here is example like below: window_size = 20, eps_length = 1, len(self.df) = 21 so, self.window_size - 1 = 19 and len(self.df) - self._cfg.eps_length = 20, and start_index = np.random.randint(19, 20)
Ah there was a debugging issue on my end, I got it working now.
So then is there a better way of feeding single windows to get the corresponding actions without having to reload the whole model like I'm doing currently?
Maybe you need to modify the TradingEnv class so that it can handle a single window. You can write a function and I think most of the logic in it should be consistent with env.step. Besides a nonzero reward will be given If and only if the following situations occur: So the env will step at least twice.
You can learn more from here.
So I have the following script:
I've put eps_length to 1 because I only want to process a single window to get the corresponding trade action and I've limited 'STOCKS_GOOGL_deploy' to 20 rows since the window_size is 20.
I get the following error:
The issue presents itself in the following line
self.start_idx = np.random.randint(self.window_size, len(self.df) - self._cfg.eps_length)
I've debugged the values and they are as follows:But so the issue is that window size will always be larger than window_size - eps_length, hence the error. I'm not sure what exactly the logic is behind this, but what would be the proper way of processing a single window to get its corresponding action? Preferably without having to load in the model each time but giving me the ability to feed windows to be processed as my price data comes in.