I'm trying to develop a stock predictor.

I'm using LSTM but I am unsure about the structure of the Neural Network. For example, I'm assuming that the Neural Network is a many-to-one since we have many inputs (i.e Open, Close etc) and one output (stock price).

By misunderstanding is coming with how to construct the nodes. For example, what input goes into the "Cell" (or node)? I.e does say 60 timestep mean 60 days of 'Open Price' are fed into the Neural Network at t and then 60 days of 'Close' into t + 1 until we use all input to produce an output?

If someone could explain the process of how LSTM are used with stock predictions that would be appreciated.


I can't say for all cases, but I can certainly give you an example of how an LSTM could be used to predict stock prices.

An LSTM is temporal, meaning you can feed in one input, get an output and the network will remember this interaction (if it's important), which will effect the outcome of future predictions. As such, it is reasonable to feed in all the data for the day (Open, Close etc), obtain an output for the predicted stock price of the following day (or a prediction for all the inputs you feed in, the output can be as large or small as you want), then repeat for as long as you want, each time only feeding in the data for that particular day as the network will remember previous days.

In your example, 60 timesteps would mean doing a forward pass of the LSTM 60 times, for 60 days. Each of these forward passes will produce an output, which you can compare to the next actual stock price for verification, until you reach the current day, where the prediction is for the future.

  • $\begingroup$ @Reccessice I was thinking feed in 0-59 days first, get an output for day 60, then feed in days 1-60 get output day 61 and hope it remembers certain patterns. This is for training the model. So the result of day 0-59 input will be passed onto the next loop of day 1-60. Would this be correct? $\endgroup$ – user33121 Jan 30 '20 at 4:38
  • $\begingroup$ @user33121 If you trained your data on time periods of 60 days, then yes this is definitely the way to go. Just as a warning, don't extend the LSTM past the maximum temporal depth of training and expect coherent results $\endgroup$ – Recessive Jan 30 '20 at 4:54
  • $\begingroup$ What is the depth? Do you mean as in over-training the data? $\endgroup$ – user33121 Jan 30 '20 at 5:17
  • $\begingroup$ @user33121 No by temporal depth I mean the number of times you feed input into the LSTM. So if you feed in 60 days in training, then do weight updates and repeat, don't then feed in 80 days in testing and expect reasonable outputs past day 60 as the LSTM was never trained to go that far $\endgroup$ – Recessive Jan 30 '20 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.