Within the R Neural Network page, I am using the neural network function to attempt to predict stock price.
Training data contains columns High,Low,Open,Close.
myformula <- close ~ High+Low+Open
neuralnet(myformula,data=train_,hidden=c(5,3),linear.output=T)
My question, Given the below data example could you tell me what the formula would look like.
I have a table with columns "High","Low","Open","Close" it has two rows of values, each row represents a candle stick for the day. So the two rows in the data are candle sticks for the previous two days.My aim is tp predict what the next candle stick is i.e. "Open","High","Low","Close" given the previous two candlesticks.
My neural network will be presented with the previous dtata 1 candle stick at a time. I want to know what the next candlestick is, so what would my R formula look like.
Thanks Let me know
In a Feed-Forward Neural Network*, you have to specify the features you want to use for the prediction and the targets to predict. In your example above the feature is e.g.
prev_close
, and the target isclose
. As you can see in your training data you don't haveprev_close
yet, that was the whole point of my answer, you need to formulate the problem correctly first.If all you have is
close
, there cannot be a formula to train a FF NN for this. You need to createprev_close
then the formula would beclose ~ prev_close
.*A Recurrent Neural Network (RNN) can be trained on sequences, and output a prediction based on an input sequence, but that's a whole 'nother can of worms
Simple example: predict close based on last 2 close values
I cooked up this ridiculously-simplistic* example just to illustrate the problem formulation, that predicts the
close
, based one the last twoclose
values. I chose a single hidden layer with 1 neuron in it. I've setlinear.output=TRUE
since we are predicting continuous values (regression problem as discussed before, and in theneuralnet
documentation it is stated that there will be no activation functionact.fct
if that value is TRUE)*If you trade with this you will certainly lose your shirt. This is just to show how to structure such a prediction problem in a Neural Network. Don't use this for real.
Problem formulation
The point I wanted to make clear is this, if you have prices in a column you have to create the features for the prediction
The problem posed to the NN is to predict
close
based onprev_close_1
andprev_close_2
, hence the formulaclose ~ prev_close_1 + prev_close_2
Here's the network architecture
Notice the inputs that are the previous close values, and the output: the predicted close value.
What the dummy prices look like
This is what you have, it's just the historical stock prices
What the NN was trained on
This is what you need, the features and the target, try to form the rows in the training dataframe below to understand the shift/lag.
What the NN predicts