huseinzol05 / Stock-Prediction-Models

Gathers machine learning and deep learning models for Stock forecasting including trading bots and simulations
Apache License 2.0
7.96k stars 2.81k forks source link

Question on evolution-strategy-bayesian-agent.ipynb #37

Closed edantes1984 closed 5 years ago

edantes1984 commented 5 years ago

Thanks for the sharing great research I have been going through the code and one part that seems to be an issue is that the state variable determining action may include the the trade price itself.

action, buy = self.act(state) ... total_buy = buy_units * close[t]

close[t] seems to be part of the data in the state used to determine action. isn't that including information not available when trading if the trade price is included in the state to determine action?

Thanks for the clarification in advance.

soulaw-mkii commented 5 years ago

When you train the model , you use the historical close price to converge the weighting matrix to the optimum.

When you predict for live trading, you get the latest price from market and you have had historical price on hand. They make you available to construct a current time series and of course you have the previous time series. Then you pass the delta into the model for predicting hold/buy/sell. The actual dealt price is dependent on market status after you placed the order and it is not the input.

edantes1984 commented 5 years ago

Thank you very much for the response. When i see the code for the 'trade' function in realtime trader: def trade(self, data): """ you need to make sure the data is [close, volume] """ scaled_data = self.minmax.transform([data])[0] real_close = data[0] close = scaled_data[0] if len(self._queue) >= window_size: self._queue.pop(0) self._queue.append(scaled_data) if len(self._queue) < window_size: return { 'status': 'data not enough to trade', 'action': 'fail', 'balance': self._capital, 'timestamp': str(datetime.now()), } state = self.get_state( window_size - 1, self._inventory, self._scaled_capital, timeseries = np.array(self._queue).T.tolist(), ) action, prob = self.act_softmax(state) print(prob) if action == 1 and self._scaled_capital >= close: self._inventory.append(close) self._scaled_capital -= close self._capital -= real_close return { 'status': 'buy 1 unit, cost %f' % (real_close), 'action': 'buy', 'balance': self._capital, 'timestamp': str(datetime.now()), } ....

the incoming data is added to the queue, which is then used to determine the state and the action. that same data is then used to determine the action. Then the buy price is the same last data point that went into the state (since real_close = data[0]).

Thanks

huseinzol05 commented 5 years ago

The question is?

johnjscaife commented 5 years ago

Thanks for your contribution!

The agent action space is limited to long-only positions, rather than initiating net short-positions as well. So in each strategy here the agent action space needs to be adapted if you want to investigate this in a real-world setting. Otherwise, you are just going long and then eventually scaling out of the position every time.