Close Navigation
Learn more about IBKR accounts
Convolutional Neural Networks – Part II

Convolutional Neural Networks – Part II

Posted September 20, 2023
Chainika Thakar
QuantInsti

See Part I for an overview of convolutional neural networks.

Using convolutional neural networks in trading

Let us see how CNN works in the trading domain with this image below-

Briefly, following are the steps for using CNNs in trading domain-

  • Fetching the data and labelling the same
  • The image creation takes place
  • The image goes through CNN andIt eventually leads to the financial evaluation result with the help of Keras in TensorFlow.

Working of convolutional neural networks in trading

Let us see a step-by-step approach in the case of trading with a CNN.

The working of a convolutional neural networks (CNN) in trading involves several steps, including data preprocessing, model architecture design, training, evaluation with validation and prediction. Here’s a general overview of how a CNN can be applied in trading:

Step 1 – Data preprocessing

The first step is to gather relevant financial data, such as historical price and volume data which is used for future price predictions and for making trading decisions.

This data needs to be preprocessed and transformed into a suitable format for inputting into the CNN model. For example, the time series data may be organised into input matrices or image pixels as shown in the image above.

Convolutional neural networks help to apply filters to the input data, allowing the network to automatically learn features and patterns from the data.

Step 2 – Model architecture design

This step consists of all the architectural layers through which the CNN model goes before training. These are-

  1. Input layer

Specifies the dimensions of the input data, such as the image width, height, and number of channels (e.g., RGB or grayscale).

2. Convolutional layers

  • Decides on the number of convolutional layers and their parameters, including the number of filters/kernels, filter size, stride, padding, and activation functions (e.g., ReLU).
  • Determine the architecture of each convolutional layer, including the number of filters and their sizes.
  • Consider using techniques like batch normalisation or dropout for regularisation and improving generalisation.

3. Pooling layers

  • Select the pooling strategy (e.g., max pooling, average pooling) and the pooling size.
  • Determine the stride and padding parameters for the pooling operation.

4. Fully connected layers

  • Decides on the number of fully connected (dense) layers and their sizes. Choose the activation functions for the fully connected layers.
  • Considers regularisation techniques like dropout or L2 regularisation.

5. Output Layer

  • Determine the number of output units, which depends on the specific task (e.g., binary classification, multi-class classification, regression).
  • Choose the appropriate activation function for the output layer (e.g., sigmoid, softmax for classification; linear for regression).

6. Loss Function

Select the appropriate loss function based on the task (e.g., binary cross-entropy, categorical cross-entropy, mean squared error).

7. Optimization Algorithm

Choose an optimization algorithm to update the model’s parameters during training, such as stochastic gradient descent (SGD), Adam, or RMSprop.

Step 3 – Training

Next, the CNN needs to be trained using labelled training data. The training data typically consists of historical data with corresponding labels, such as price movements or trading signals.

During training, the CNN learns to optimise its internal parameters (weights and biases) to minimise a loss function, which measures the difference between predicted and actual labels. This process includes forward propagation, backpropagation, and gradient descent.

Step 4 -Evaluation and validation

After training, the performance of the CNN is evaluated using validation data. This helps assess how well the model generalises to unseen data and can guide the selection of hyperparameters or adjustments to the model architecture if necessary. Various evaluation metrics, such as accuracy, precision, recall, or profit/loss measures, can be used depending on the trading strategy and objectives.

Step 5 – Prediction

Once the CNN is trained and evaluated, it can be used for making price predictions for creating the trading strategy. The trained model takes the input data, applies the learned features and patterns, and generates predictions or trading signals.

These predictions can be used to make trading decisions or the strategies, such as whether to buy, sell, or hold an asset.

Stay tuned for the next installment for steps to use convolutional neural networks in trading with Python.

Originally posted on QuantInsti Blog.

Join The Conversation

If you have a general question, it may already be covered in our FAQs. If you have an account-specific question or concern, please reach out to Client Services.

Leave a Reply

Your email address will not be published. Required fields are marked *

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from QuantInsti and is being posted with its permission. The views expressed in this material are solely those of the author and/or QuantInsti and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.