Answers.Body: <p>Given a model that takes in a price and a second value, such as a moving average of the price, the following configuration is my recommendation.  This is based on training on a history of 45 input time steps and forecasting out 10 steps in the future.  I have assumed that your 'num_steps' is a stride through the training data.  Note that I have not tested this and you will most likely need to tweak a parameter or two:</p>
  
  <pre><code>{
      "data": {
          "sequence_length": 55,
          "train_test_split": 0.85,
          "normalise": true,
          "num_steps": 5
      },
      "training": {
          "epochs":200,
          "batch_size": 64
      },
      "model": {
          "loss": "mse",
          "optimizer": "adam",
          "layers": [
              {
                  "type": "lstm",
                  "neurons": 100,
                  "input_timesteps": 45,
                  "input_dim": 2,
                  "return_seq": true,
                  "activation": "relu"
              },
              {
                  "type": "dropout",
                  "rate": 0.2
              },
              {
                  "type": "lstm",
                  "neurons": 100,
                  "activation": "relu",
                  "return_seq": false
              },
              {
                  "type": "dropout",
                  "rate": 0.2
              },
              {
                  "type": "dense",
                  "neurons": 1,
                  "activation": "linear"
              }
          ]
      }
  }
  </code></pre>
  
  <p>Try this out and plot your model's loss and accuracy by epoch.  See <a href="https://machinelearningmastery.com/display-deep-learning-model-training-history-in-keras/" rel="nofollow noreferrer">Display Deep Learning Model Training History in Keras</a> for some information and code in this area.  Let me know if you are not using Keras and I will point you to another article/code solution.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-04T16:32:09.710Z
Answers.Text: I was wondering something a minute ago. Maybe there is a mistake in the code, but it is unclear to me. If we had applied regression on the price difference than the "Plot of differences" plot would be better, right?
Answers.UserDisplayName: user1050421
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-04T16:42:37.053Z
Answers.Text: If you mean using the regression line instead of the price differences my thought is that the performance would not be as good.  It is a good idea to test out.  Maybe also feed the regression line as a third value (i.e. price, difference, regression line).  It is always good to try different data.
Answers.UserDisplayName: Brian O'Donnell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-04T17:22:52.873Z
Answers.Text: {
                  "type": "dense",
                  "neurons": 1,
                  "activation": "linear"
              } I noticed you changed that part, but we wanted to predict the price as well as the features for t+2. So at time t+2, I reused the predicted features and the prices from time t+1 to predict the price for time t+2 and predict the features  to be used again at time t+3.
Answers.UserDisplayName: user1050421
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-04T16:08:58.183Z
Answers.LastActivityDate: 2018-11-04T16:08:58.183Z
Answers.UserDisplayName: Brian O'Donnell
Answers.Body: <p>Remember that any machine learning model works good only when there is a "rule" or a correlation between modeling data and modeled data. When there is not, even the best algorithm will not predict/classify correctly. I am not saying that this must be the case, but probably you have come pretty close to the physical limit of what can be achieved using this data. </p>
  
  <p>Maybe you should consider adding or extracting new features to your model.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-05T18:22:42.810Z
Answers.LastActivityDate: 2019-03-05T18:22:42.810Z
Answers.UserDisplayName: GKozinski
Body: <p>I am working on a project for price movement forecasting and I am stuck with poor quality predictions.</p>
  <p>At every time-step I am using an LSTM to predict the next 10 time-steps. The input is the sequence of the last 45-60 observations. I tested several different ideas, but they all seems to give similar results. The model is trained to minimize MSE.</p>
  <p>For each idea I tried a model predicting 1 step at a time where each prediction is fed back as an input for the next prediction, and a model directly predicting the next 10 steps(multiple outputs). For each idea I also tried using as input just the moving average of the previous prices, and extending the input to input the order book at those time-steps.
  Each time-step corresponds to a second.</p>
  <p>These are the results so far:</p>
  <p>1- The first attempt was using as input the moving average of the last N steps, and predict the moving average of the next 10.
  At time t, I use the ground truth value of the price and use the model to predict t+1....t+10</p>
  <p>This is the result:</p>
  <p>Predicting moving average:</p>
  <p><a href="https://i.sstatic.net/YOXxu.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YOXxu.png" alt="image" /></a></p>
  <p>On closer inspection we can see what's going wrong:</p>
  <p>Prediction seems to be a flat line. Does not care much about the input data:</p>
  <p><a href="https://i.sstatic.net/m4Xb5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/m4Xb5.png" alt="image" /></a></p>
  <ol start="2">
  <li>The second attempt was trying to predict differences, instead of simply the price movement. The input this time instead of simply being X[t] (where X is my input matrix) would be X[t]-X[t-1].
  This did not really help.
  The plot this time looks like this:</li>
  </ol>
  <p>Predicting differences:</p>
  <p><a href="https://i.sstatic.net/toFGz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/toFGz.png" alt="image" /></a></p>
  <p>But on close inspection, when plotting the differences, the predictions are always basically 0.</p>
  <p><a href="https://i.sstatic.net/eSqGU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eSqGU.png" alt="enter image description here" /></a></p>
  <p>At this point, I am stuck here and running our of ideas to try. I was hoping someone with more experience in this type of data could point me in the right direction.</p>
  <p>Am I using the right objective to train the model? Are there any details when dealing with this type of data that I am missing?
  Are there any &quot;tricks&quot; to prevent your model from always predicting similar values to what it last saw? (They do incur in low error, but they become meaningless at that point).</p>
  <p>At least just a hint on where to dig for further info would be highly appreciated.</p>
  <p><strong>UPDATE</strong></p>
  <p>Here is my config</p>
  <pre><code>{
      &quot;data&quot;: {
          &quot;sequence_length&quot;:30,
          &quot;train_test_split&quot;: 0.85,
          &quot;normalise&quot;: false,
          &quot;num_steps&quot;: 5
      },
      &quot;training&quot;: {
          &quot;epochs&quot;:200,
          &quot;batch_size&quot;: 64
      },
      &quot;model&quot;: {
          &quot;loss&quot;: &quot;mse&quot;,
          &quot;optimizer&quot;: &quot;adam&quot;,
          &quot;layers&quot;: [
              {
                  &quot;type&quot;: &quot;lstm&quot;,
                  &quot;neurons&quot;: 51,
                  &quot;input_timesteps&quot;: 30,
                  &quot;input_dim&quot;: 101,
                  &quot;return_seq&quot;: true,
                  &quot;activation&quot;: &quot;relu&quot;
              },
              {
                  &quot;type&quot;: &quot;dropout&quot;,
                  &quot;rate&quot;: 0.1
              },
              {
                  &quot;type&quot;: &quot;lstm&quot;,
                  &quot;neurons&quot;: 51,
                  &quot;activation&quot;: &quot;relu&quot;,
                  &quot;return_seq&quot;: false
              },
              {
                  &quot;type&quot;: &quot;dropout&quot;,
                  &quot;rate&quot;: 0.1
              },
              {
                  &quot;type&quot;: &quot;dense&quot;,
                  &quot;neurons&quot;: 101,
                  &quot;activation&quot;: &quot;relu&quot;
              },
              {
                  &quot;type&quot;: &quot;dense&quot;,
                  &quot;neurons&quot;: 101,
                  &quot;activation&quot;: &quot;linear&quot;
              }
          ]
      }
  }
  </code></pre>
  <p>Notice the last layer with 101 neurons. It is not an error. We just want to predict the features as well as the price. In other words, we want to predict the price for time t+1 and use the features predicted to predict the price and new features at time t+2, ...</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-03T23:48:38.940Z
Comments.Text: What is your architecture?  Knowing that it is an LSTM is not enough.  What values are you using for the hyperparameters (e.g. number of epochs, mini-batch, number of neurons, number of layers, etc.)?  Have you done a sanity check with simple data like a sine wave?  Are you normalizing the data?  If so, have you tried multiple methods?  Why are you looking at one second interval data?  Financial data is extremely noisy at that time scale even when averaged over 10 seconds.  Why not consider one minute interval data or higher to at least prove your approach?
Comments.UserDisplayName: Brian O'Donnell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-04T15:17:27.533Z
Comments.Text: With your update the most obvious thing I would change is to normalize the data.  You state that you are using price, moving average, and price difference but your configuration has 101 inputs.  Why is that?  Your input time steps is 30 but you state you are using 45-60 observations and the configuration says the sequence length is 30.  Your sequence length should be greater than your input time steps by the number of steps you are predicting ahead.  Why does your output layer have 101 neurons?  Another useful piece of information would be a plot of the model's loss versus epoch.
Comments.UserDisplayName: Brian O'Donnell
Tags: <neural-networks><long-short-term-memory><dropout>
Title: Price Movement Forecasting Issue
UserDisplayName: user1050421
ThreadText: # Price Movement Forecasting Issue
  
  (Asked by: username_0 on 2018-11-02)
  
  I am working on a project for price movement forecasting and I am stuck with poor quality predictions.
  At every time-step I am using an LSTM to predict the next 10 time-steps. The input is the sequence of the last 45-60 observations. I tested several different ideas, but they all seems to give similar results. The model is trained to minimize MSE.
  For each idea I tried a model predicting 1 step at a time where each prediction is fed back as an input for the next prediction, and a model directly predicting the next 10 steps(multiple outputs). For each idea I also tried using as input just the moving average of the previous prices, and extending the input to input the order book at those time-steps.
  Each time-step corresponds to a second.
  These are the results so far:
  1- The first attempt was using as input the moving average of the last N steps, and predict the moving average of the next 10.
  At time t, I use the ground truth value of the price and use the model to predict t+1....t+10
  This is the result:
  Predicting moving average:
  
  On closer inspection we can see what's going wrong:
  Prediction seems to be a flat line. Does not care much about the input data:
  
  
  The second attempt was trying to predict differences, instead of simply the price movement. The input this time instead of simply being X[t] (where X is my input matrix) would be X[t]-X[t-1].
  This did not really help.
  The plot this time looks like this:
  
  Predicting differences:
  
  But on close inspection, when plotting the differences, the predictions are always basically 0.
  
  At this point, I am stuck here and running our of ideas to try. I was hoping someone with more experience in this type of data could point me in the right direction.
  Am I using the right objective to train the model? Are there any details when dealing with this type of data that I am missing?
  Are there any "tricks" to prevent your model from always predicting similar values to what it last saw? (They do incur in low error, but they become meaningless at that point).
  At least just a hint on where to dig for further info would be highly appreciated.
  UPDATE
  Here is my config
  {
      "data": {
          "sequence_length":30,
          "train_test_split": 0.85,
          "normalise": false,
          "num_steps": 5
      },
      "training": {
          "epochs":200,
          "batch_size": 64
      },
      "model": {
          "loss": "mse",
          "optimizer": "adam",
          "layers": [
              {
                  "type": "lstm",
                  "neurons": 51,
                  "input_timesteps": 30,
                  "input_dim": 101,
                  "return_seq": true,
                  "activation": "relu"
              },
              {
                  "type": "dropout",
                  "rate": 0.1
              },
              {
                  "type": "lstm",
                  "neurons": 51,
                  "activation": "relu",
                  "return_seq": false
              },
              {
                  "type": "dropout",
                  "rate": 0.1
              },
              {
                  "type": "dense",
                  "neurons": 101,
                  "activation": "relu"
              },
              {
                  "type": "dense",
                  "neurons": 101,
                  "activation": "linear"
              }
          ]
      }
  }
  
  Notice the last layer with 101 neurons. It is not an error. We just want to predict the features as well as the price. In other words, we want to predict the price for time t+1 and use the features predicted to predict the price and new features at time t+2, ...
  
  **Tags:** neural-networks, long-short-term-memory, dropout
  > **Comments:**
  > **username_1**: What is your architecture?  Knowing that it is an LSTM is not enough.  What values are you using for the hyperparameters (e.g. number of epochs, mini-batch, number of neurons, number of layers, etc.)?  Have you done a sanity check with simple data like a sine wave?  Are you normalizing the data?  If so, have you tried multiple methods?  Why are you looking at one second interval data?  Financial data is extremely noisy at that time scale even when averaged over 10 seconds.  Why not consider one minute interval data or higher to at least prove your approach?  
  > **username_1**: With your update the most obvious thing I would change is to normalize the data.  You state that you are using price, moving average, and price difference but your configuration has 101 inputs.  Why is that?  Your input time steps is 30 but you state you are using 45-60 observations and the configuration says the sequence length is 30.  Your sequence length should be greater than your input time steps by the number of steps you are predicting ahead.  Why does your output layer have 101 neurons?  Another useful piece of information would be a plot of the model's loss versus epoch.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-11-04. Score: 3
  
  Given a model that takes in a price and a second value, such as a moving average of the price, the following configuration is my recommendation.  This is based on training on a history of 45 input time steps and forecasting out 10 steps in the future.  I have assumed that your 'num_steps' is a stride through the training data.  Note that I have not tested this and you will most likely need to tweak a parameter or two:
  {
      "data": {
          "sequence_length": 55,
          "train_test_split": 0.85,
          "normalise": true,
          "num_steps": 5
      },
      "training": {
          "epochs":200,
          "batch_size": 64
      },
      "model": {
          "loss": "mse",
          "optimizer": "adam",
          "layers": [
              {
                  "type": "lstm",
                  "neurons": 100,
                  "input_timesteps": 45,
                  "input_dim": 2,
                  "return_seq": true,
                  "activation": "relu"
              },
              {
                  "type": "dropout",
                  "rate": 0.2
              },
              {
                  "type": "lstm",
                  "neurons": 100,
                  "activation": "relu",
                  "return_seq": false
              },
              {
                  "type": "dropout",
                  "rate": 0.2
              },
              {
                  "type": "dense",
                  "neurons": 1,
                  "activation": "linear"
              }
          ]
      }
  }
  
  Try this out and plot your model's loss and accuracy by epoch.  See Display Deep Learning Model Training History in Keras for some information and code in this area.  Let me know if you are not using Keras and I will point you to another article/code solution.
  
  > **Comments:**
  > **username_0**: I was wondering something a minute ago. Maybe there is a mistake in the code, but it is unclear to me. If we had applied regression on the price difference than the "Plot of differences" plot would be better, right?  
  > **username_1**: If you mean using the regression line instead of the price differences my thought is that the performance would not be as good.  It is a good idea to test out.  Maybe also feed the regression line as a third value (i.e. price, difference, regression line).  It is always good to try different data.  
  > **username_0**: {                 "type": "dense",                 "neurons": 1,                 "activation": "linear"             } I noticed you changed that part, but we wanted to predict the price as well as the features for t+2. So at time t+2, I reused the predicted features and the prices from time t+1 to predict the price for time t+2 and predict the features  to be used again at time t+3.  
  
  ---
  
  ### Answer by username_2 on 2019-03-05. Score: 2
  
  Remember that any machine learning model works good only when there is a "rule" or a correlation between modeling data and modeled data. When there is not, even the best algorithm will not predict/classify correctly. I am not saying that this must be the case, but probably you have come pretty close to the physical limit of what can be achieved using this data.
  
  Maybe you should consider adding or extracting new features to your model.
  
  
  ---
  
  