Abstract

The Internet of Things (IoT) play an important role in the financial sector in recent decades since several stock prediction models can be performed accurately according to IoT-based services. In real-time applications, the accuracy of the stock price fluctuation forecast is very important to investors, and it helps investors better manage their funds when formulating trading strategies. It has always been a goal and difficult problem for financial researchers to use predictive tools to obtain predicted values closer to actual values from a given financial data set. Leading indicators such as futures and options can reflect changes in many markets, such as the industry’s prosperity. Adding the data set of leading indicators can predict the trend of stock prices well. In this research, a trading strategy for finding stock trading signals is proposed that combines long short-term memory neural networks with genetic algorithms. This new framework is called long short-term memory neural network with leading index, or LSTMLI for short. We thus take the stock markets of the United States and Taiwan as the research objects and use historical data, futures, and options as data sets to predict the stock prices of these two markets. After that, we use genetic algorithms to find trading signals for the designed stock trading system. The experimental results show that the stock trading system proposed in this research can help investors obtain certain returns.

1. Introduction

The Internet of Things (IoT) model plays an important role in recent years since many applications and services rely on IoT-based services. In the financial sector, the IoT-based services [1] include banking, insurance, and investments. Forecasting or prediction [2] is the most interesting thing in the financial market, and many studies [3, 4] deploy IoT-based services to achieve higher accuracy. Li et al. [5] studied the development of IoTs and used deep learning to predict stock price trends. Yang et al. [6] proposed a new data mining algorithm to study the multimedia Internet of Things and the stability of stocks. The financial market is a mechanism for determining the price of financial funds and trading financial assets. It is a market that enables the financing of securities and the trading of securities. The capital market is also called the “long-term financial market,” which mainly includes the stock market, fund market, and bond market. Its volatility can reflect the degree of risk of assets. The fluctuation of stock prices plays a considerable role in the appropriate timing of buying and selling stocks [7]. For investors, the true meaning of investing in the stock market is to obtain extraordinary returns by buying low and selling high, so the prediction of stock price fluctuations has become a special focus of private investors and investment companies [8]. Due to a large amount of data in stocks, the low data correlation, and many factors that affect stock prices, financial markets are full of uncertainty, which also makes predicting stock price fluctuations a significant problem for stock researchers. Initially, people had predicted the fluctuations of stock prices several times [9, 10], but the results were unsatisfactory.

Investors are not completely rational. For example, people may have positive or negative emotions at certain moments [1115]. Therefore, after this hypothesis was raised, there were both support and opposition, thus becoming one of the most controversial investment theories [16, 17]. Some researchers believe that if the trading signals [18] of the stocks can be found, the stocks can be bought and sold at the appropriate time to obtain relatively high profits. Finding accurate stock trading signals is the key to obtaining huge returns, that is, in stock trading, when a buy signal appears, the stock is bought, and when a sell signal appears, the stock is sold. In other words, the stocks should be purchased at a lower price but sold out at a higher price if you would like to obtain good profit value during the trading. Stock trading signals have always been the main research objects of investors and investment companies. Researchers have also tried many times to predict the best buying and selling signals, but because many factors affect stock prices, the prediction results are not satisfactory.

Support vector machine (SVM) is a binary classification model [19] and has good classification performance in the field of machine learning. Huang et al. [20] found in 2005 that SVM has better prediction results than traditional statistical methods. Nayak et al. [21] proposed a hybrid model for the prediction of Indian stock indexes. This model mainly uses two machine learning algorithms, namely SVM and k-nearest neighbor (KNN). Studies have shown that the hybrid model they proposed has good scalability and predictability for high-dimensional data. Although the prediction results of SVM are significantly improved compared to other models [22, 23], it is still not satisfactory for stock prediction. The neural network model has received particular attention. Because neural network models can identify nonlinear relationships in data sets, many researchers have analyzed, and predicted stock price fluctuations based on various neural networks have also obtained relatively good results. For the stocks of the Tokyo Stock Exchange, Kimoto et al. [24] conducted a systematic study. They proposed a stock prediction system based on neural networks, and the system achieved relatively good profits in training.

With the rise of machine learning, deep learning [25] has attracted the attention of various stock researchers. It stimulates the mechanism of the human brain to process data and can detect nonlinear relationships in the data. In this document [26], the application of machine learning in financial markets is explained in detail. A recurrent neural network [27, 28] is a kind of deep learning based on nonlinear prediction. In 2017, Fischer and Krauss [29] did a large-scale study. They used daily 500 data to measure the prediction performance of LSTM compared to other neural networks. The research results show that the prediction performance of the LSTM model is the best. This paper [30] uses LSTM’s RNN to predict stocks and calculate returns based on closing prices. Experimental results show that the performance of the LSTM model is better than the feedforward artificial neural network.

Before the emergence of recurrent neural networks, both artificial neural networks and convolutional neural networks (CNNs) achieved good prediction results [31, 32]. For example, by entering a picture, the convolutional neural network can accurately predict whether the image is a cat or a dog. However, since the inputs of the convolutional neural network are independent of each other and cannot be predicted based on the data of the previous moment, the prediction effect of the CNN is not very good on the problem of time series. Therefore, people have developed a recurrent neural network with a memory function. The input of the RNN consists of the input of the current moment and the output of the previous moment, so it has a simple memory function. Through multiple iterations, the input layer and hidden layer, the hidden layer at the previous moment and the hidden layer at the current moment, and the weight between the hidden layer and the output layer are repeatedly modified to obtain the optimal weight parameters and achieve better prediction results. In 2018, Chen et al. [33] used the RNN-boost model to study the Shanghai-Shenzhen 300 Stock Index (HS300). They select official accounts from Sina Weibo and analyze the content grabbed from these accounts by extracting emotional features. Next, they input the extracted features and technical indicators into the RNN-boost model to predict the stock price fluctuations.

At present, there have been many applications implemented with RNNs, such as speech recognition [34], text generation [35], machine translation [36], and so on. But at the same time, RNN has two significant shortcomings: one is that the learning ability of RNN is limited; somehow the performance for prediction will have a negative effect if the size of the sequence is relevantly long and the other is that the gradient of RNN will disappear, resulting in long-term memory failure. Later, people improved the RNN, mainly adding a forget gate, input gate, and output gate to retain and control information. The improved RNN has a better prediction effect on both short and long sequences, so researchers define it as long short-term memory, or LSTM for short.

This research [37] combines the technical indicator-moving average with the globe best-guide quantum-inspired tabu search algorithm to propose a new dynamic trading system. Among them, the moving average is used to find stock trading signals. In this paper, the proposed method is compared with the buy-and-hold strategy, and the experimental results show that this method significantly improves investment returns. This article mainly studies how to use deep learning algorithms and intelligent optimization algorithms to find the best trading signals. The framework extracts useful features from different data and then trains a predictive model based on these features. In this study, the output obtained by the predictive model is combined with the intelligent optimization algorithm to obtain a buying and selling signal. In stock trading, finding the best buying and selling signals is the key to gaining income. In this work, a new long short-term memory neural network framework is used. It integrates the collected data into the form of images, inputs them in the form of images, and uses these images to train neural networks. This research combines the LSTMLI framework and GA to form a stock trading system. From the extensive experiments, it can be observed that the proposed stock trading system is superior to other trading strategies. The key significances of this article are described as follows:(1)This research combines the LSTMLI framework with genetic algorithms and proposes a stock trading system. This system can find a stock trading signal relatively well so that investors can get a certain amount of income.(2)In this study, we have added two data sets: futures and options. Leading indicators are indicators that change first before economic growth or recession. This article only uses two leading indicators, namely, futures and options. Extensive experiments indicated that after adding futures and options data sets, the prediction accuracy is higher.(3)An LSTMLI framework with a two-dimensional tensor as input is proposed. This research is improved based on LSTM, and the output is divided into three categories: rising, falling, and unchanged. Experimental results show that the improved framework has better performance.

This article mainly includes the following parts. Section 2 introduces related works. Section 3 introduces the methods used in this article. Section 4 mainly describes the framework proposed in this research. Section 5 is the experimental results of this research. Finally, a detailed summary of this research is made in the conclusion section.

The prediction of stock prices is mainly the analysis of historical behaviors, such as people’s historical emotions, historical market information, etc., and then useful features are extracted from them to train better predictive models. The value of stock prices is a time series. Revealing the development and changes in stock prices is an objective record of stock historical behavior. In the early days of the stock market, a host of investors relied on their own experience to judge stock price movements, which seemed very subjective and lacked a scientific basis. Besides, stock prices are also affected by many other factors. For instance, Zheng et al. [38] studied the relationship between exchange rates and stock prices on the Hong Kong stock market. They built a model to analyze the correlation between Hong Kong company stocks, mainland company stocks, and exchange rates. The experimental results show that the exchange rate is negatively correlated with the stocks of local companies in Hong Kong and positively correlated with the stocks of mainland companies. The price of stocks is also affected by external information and human emotions [39]. Many researchers have studied human emotions by analyzing the content on the forums or Weibo to more accurately predict stock price volatility. We can also find that many factors can affect stock price volatility, so we need some tools to analyze and predict stock. Several studies [40, 41] were then developed to investigate the deep learning models used in stock trading.

Intelligent optimization algorithms are used to find the optimal solution. In recent years, researchers have been more enthusiastic about using genetic algorithms to solve problems. In the financial market, many researchers also use genetic algorithms (GAs) to find stock trading signals. Allen et al. [42] utilized GAs for discovering the technical trading rule according to the S&P 500 index of the collected daily records (prices) in a range of 1928 to 1995. In this research [43], based on a series of technical indicators that generate buying and selling signals, GA is used to propose a trading strategy. Hirabayashi et al. [44] proposed a GA-based system to find suitable trading signals and automatically generate trading rules based on technical indicators. The focus of this system is not to predict the price of the transaction but to find the right trading opportunity. Lin et al. [45] used a GA-based model to set optimal values for the parameters of the problem and bought or sold stocks at the appropriate trading time.

The price of stocks changes with time, and the phenomenon of rising or falling occurs, so the data of stock prices is a typical time series. When we use the model to predict the price of stocks, the input of the model can be not only digital data but also image data. At this time, we thought that the CNN model could be used to predict the price of the stock. Research has proved that CNN is outstanding in image recognition, and its accuracy is higher than other models. Di Persio et al. [46] proposed a model that uses wavelet and CNN methods to predict stock trends based on data from the past few days. Experimental results show that the proposed new method is superior to other models and basic neural networks.

The stock price is usually a time series data. For this kind of data, the LSTM neural network model has a better effect than other models. The LSTM model is an improvement of RNN. LSTM adds a forget gate, input gate, output gate, and memory unit to solve the problem of disappearing the RNN gradient. Because the LSTM model has better performance in terms of time series, many researchers use LSTM to predict stock price fluctuations. This document [17] proposes an integrated LSTM for detecting stock prices within a day, using technical indicators as input to the network. They evaluated the predictive power of the proposed model on several US stocks, and the experimental results showed that the proposed integrated LSTM model performed better than the benchmark model. Nelson et al. [47] established a model that uses the LSTM neural network to predict stock price trends based on technical indicators and historical price data. Through a series of experiments to evaluate the performance of the proposed model and other machine learning algorithms, experimental results show that the prediction accuracy of the proposed model is relatively high, and the average accuracy is 55.9%.

3. Methodology

In the first part of this section, the SSACNN framework [48], LSTM, and the genetic algorithm will be introduced and integrated as a newly designed framework. This SSACNN framework was proposed in our previous research. The second part will introduce the basic LSTM neural network. In the third part of this section, we will introduce the genetic algorithm used in this research. This algorithm is used to find the optimal solution of stock trading signals to maximize returns.

3.1. Stock Sequence Array Convolutional Neural Network

Convolutional neural networks have good results in image recognition, such as handwritten digit recognition, input several pictures of handwritten digits, and repeatedly modify the weight parameters through multiple training of CNN. The resulting neural network model can accurately recognize handwritten digits. CNN includes a convolutional layer, pooling layer, and fully connected layer. The convolution layer mainly extracts local features of the input data. The researcher defines a convolution kernel inside the convolution layer. Its shape is a square matrix that is used to extract a certain feature. The convolution kernel is multiplied by the corresponding bits of the digital input matrix and then added to obtain the output value of a convolution layer. The higher the output value, the higher the degree of matching between the two. Because one convolution kernel recognizes one feature and the input data may have multiple features, there may be numerous convolution kernels in one convolution layer to extract multiple features. The output of the obtained convolution layer should be used as the input of the pooling layer.

However, before entering the value into the pooling layer, an activation function is usually added to solve the nonlinear problem. At present, the activation function ReLU (Rectified Linear Unit) is commonly used. The pooling layer is mainly used to reduce the number of training parameters and reduce the dimension of the feature vector output by the convolution layer. The most common pooling layers are maximum pooling and mean pooling. In this article, we choose maximum pooling, that is, the maximum value in a specified area is selected to represent the entire area. The output value of the pooling layer is then expanded as the input of the fully connected layer to generate the final output. After several times of convolution, excitation, and pooling, the model will learn a high-quality feature map, and then the feature map is used as the input to the fully connected layer to get the final output.

In this study, the stock data for some time is converted into an image, and this image is used as the input of the CNN framework. The input here is 30-day stock data, and the generated “input image” is input to the convolutional layer, pooling layer, dropout layer, and norm layer. Then, this process is looped three times. After a series of experiments, it is concluded that when the convolutional neural network is used for image recognition, the size of the convolution kernel is , and the size of the pooling layer is , the experimental effect obtained is the best. Therefore, to achieve better results for this research, the size of the convolutional layer and pooling layer is set to and , respectively.

3.2. Long Short-Term Memory Neural Network

If we want to predict the events that will happen in the future, we need to call our memory to review it, select useful information from it, and predict the development of events based on this useful information. RNN is a neural network with a memory function. Unlike the traditional neural network, there is a loop inside the RNN. It can pass the information retained at the current moment to the next moment and use it to maintain the continuity of the information. LSTM is an improved neural network based on RNN, which solves the problem that the RNN gradient disappears [27] and cannot be long-term dependent. LSTM adds three gates (forget gate, input gate, and output gate) and a cell state based on RNN to forget and retain information. The internal structure of LSTM is shown in Figure 1. Several status information of LSTM is shown as follows:

where represents the activation function, which is used to decide what information is allowed to pass. The range of is from 0 to 1. When is set to 1, it means that all information is allowed to pass. When is set to 0, it means that no information is allowed to pass. stands for hyperbolic tangent function, which is used to control new information, that is, how much new information is reflected, and the range is set as −1 to +1. and are the weight matrix, and b stands for bias. represents the output at the previous moment, and represents the input at the current moment. Among them, the forget gate is marked as ; the input gate is marked as ; and the output gate is marked as . and are input to the three gates labeled , , and . One of the differences between RNN and LSTM is that there is an extra conveyor belt named “cell state” at the top of LSTM, which is marked as in Figure 1 and used to memorize information.

The long short-term memory neural network is a special recurrent neural network. As a network with memory, LSTM’s memory function is in a sequence, not between sequences. For example, we decompose an article, and each sentence is a training object. represents the -th sentence, and each word in each sentence represents a time step. means the first word in the -th sentence. The information of this word can be memorized and passed to the fifth word . It can be seen that the memory function of LSTM works in one sentence.

3.3. A Proposed LSTM Framework with Leading Indicator, LSTMLI

In this section, the process proposed by the LSTMLI framework is specifically introduced.

3.3.1. LSTMLI Framework

This paper divides the data into two parts according to the ratio, which is used for training and testing. This experiment integrates 30-day stock data into a matrix, inputs it into the LSTMLI framework, and outputs 3 nodes, as shown in Figure 2. An example of an input matrix is shown in Table 1. The study defines the stock’s ups and downs as a label for comparison with the predicted value. The model is then trained by the developed LSTMLI to predict the stock price fluctuations for the next day, and improve the prediction accuracy by repeatedly modifying the weights. Besides, this study defines labels as three types: +1, 0, and −1. The actual meaning is that the price of the stock has risen, fallen, and has not changed significantly, as shown in the following equation:

This experiment operates on the data of the column where the historical data is rising and falling. When l is greater than or equal to 1, the label is defined as 1. When l is less than −1, the label is defined as −1. In other cases, the label is defined as 0. Thus, the LSTMLI model will give a qualitative output based on the input data. This experiment sets the learning rate to 0.001; the weight is to take the specified number of values randomly from the sequence that obeys the specified normal distribution and offset to a two-dimensional tensor. All elements of the tensor are filled with 0.1. The pseudocode of the specific process is shown in Algorithm 1.

Input: is the data of training; is the data of testing; is the number of the maximum iteration as the terminal condition.
Output: the optimal weights ; evaluation result .
(1)initialize the input data to . \(⊳\) is an input array for the information generated by historical prices, futures, and options and assume it consists of input images.
(2)label each individual in and generate the label array .
(3)generate the initial weights randomly for the LSTM network.
(4)for each round 1 to do
(5)  for each round t = 1 to do
(6)   input to the proposed LSTM network and generate class label vector .
(7)   compare and to update by Adam method [49].
(8)  end for
(9)end for
(10)evaluate using the optimal weights for testing data .
(11)output and .
3.3.2. Detailed Architectures of Input Images

In the proposed LSTMLI architecture, its input image is very complicated. Therefore, this section describes the detailed architecture of the input image used in the experiments. First, the futures, options, and historical prices generated images are explained below. It is to be noted that this section focuses on the data structure of the architecture; all values will be standardized using the methods presented above.

(1) Historical Price Image. From the above definition, the image includes opening price, lowest price, highest price, closing price, and volume of stock within 30 days. We only need to put these values in a column with a certain order and expand them for 30 days as 30 columns to build an image. An example is shown in Figure 3 in which is the opening price, is the highest price, is the lowest price, is the closing price, and is the volume at n-th day.

(2) Futures Image. It shows opening price, highest value, lowest value, closing price, and volume, which are similar to historical prices. In addition, the futures products of a particular underlying asset (stock) can have several different expiry dates. In the developed model, we choose a future whose three expirations are closest to the current date. The relevant attributes is put within one day of the futures in one column, and 30 days is expanded as a matrix. Figure 4 shows an example, and we can indicate the following parameters such as is the opening price, , is the highest price, is the lowest price, is the closing price, and is the volume at n-th day.

(3) Options Image. Compared to futures and historical prices, the situation with options is more complicated. There are two types of options (call options and put options) in the options market. In this study, we only select the near-month option data of stocks. In this method, 10 different options (10 call rights and 10 put rights) are selected, and its settlement price is closest to the current price of the stock, and attributes are extracted from these options to construct an image. Attributes include volume, open interest, closing price, and settlement price. Its composition is similar to the previous two images, and the 30-day data is also expanded into a matrix. Figure 5 shows an illustrated example, and we can find that is the settlement price, is the closing price, is the volume at n-th day, and is the open interest at n-th day.

(4) Combination Image. The final input form for the system is the combined image. In this structure, the first three images are then used to produce an image by combing the information such as prices, futures, and options, and Figure 6 shows an illustrated example for this combination image.

3.4. Genetic Algorithm

Darwin’s theory of evolution is the root of a genetic algorithm. The genetic algorithm was first proposed by John Holland. This algorithm converts the process of solving actual problems into a process similar to biological evolution and finds the optimal solution by simulating biological evolution. In this section, the components of the method are described. The specific process is as follows.

3.4.1. Chromosome Representation

The main goal of this method is to find trading signals for stocks, namely, buy and sell signals. Therefore, in this method, the chromosome is composed of two parts, as shown in Figure 7.

The first part represents the threshold when the stock has a buy signal, and the second part represents the threshold when the stock has a sell signal.

3.4.2. Initial Population

It is very important to design a strategy for generating population initialization, which will affect the final profit. In this study, two floating-point numbers were randomly generated within a specific range as the threshold for the initial buying and selling signals. The sum of the values of the nodes obtained by the neural network is approximately equal to 1. So during initialization, two floating-point numbers between 0 and 1 are randomly generated each time. An example is given below to explain in detail. Assume that the thresholds of two randomly generated buying and selling signals are 0.76848 and 0.82843, respectively (because this is just an example, not all decimal points have 5 digits), as shown in Figure 8. SSACNN is used to generate the values of 3 nodes, and an example is given to illustrate the generated values, as shown in Figure 9.

It can be seen from Figure 9 that the value of the position of the first node on the first day is 0.85551; because 0.85551  0.76848, the stock is bought at this time. After that, we then start to observe the third node of each day. It can be from Figure 9 that the value of the third node on the second day is 0.79545, which does not meet the condition of greater than 0.82843. Therefore, the stock will continue to be held on the second day, and neither buy nor sell will be performed. The value of the third node on the third day is 0.83419; because 0.83419  0.82843, the stock is sold on the third day. After that, the buying and selling operations are performed on the stocks following the above rules. In this research, buying operation of stocks refers to buying with all funds, and the selling operation of stocks refers to selling all the stocks.

3.4.3. Fitness Evaluation

The fitness function is used to evaluate the quality of chromosomes, that is, to evaluate whether the threshold value of the generated buying and selling signals is the optimal solution. In this method, the fitness function is defined as the cumulative return over a period of time, which can be seen in the following equations:

where represents the closing price of the stock when the -th sell signal appears, represents the closing price of the stock when the -th buy signal appears, is the share of the stock, is the total amount before the -th transaction, and is the total amount after the -th transaction is completed.

3.4.4. Population Selection

In each evolution, to retain good chromosomes, chromosomes need to be selected. The method of selecting chromosomes in the experiment is as follows. We randomly select chromosomes, with every two chromosomes as a group, and compare the size of the result obtained by using each chromosome and then select the chromosome corresponding to the larger value of the result that is, a chromosome will be selected in each group. For example, if there are 8 chromosomes in total, 4 chromosomes will be selected.

3.4.5. Crossover

The genetic algorithm performs crossover and mutation operations to generate new solutions. The crossover operation needs to find two chromosomes from the previous generation and set them by the condition as one chromosome is treated a father and another one is considered a mother. Then the two chromosomes are cut and spliced together at a certain position to generate a new chromosome. Part of the new chromosome is the father’s genes, and the remaining part is the mother’s genes. Not every iteration will perform crossover operations on genes. In this study, the crossover ratio was set to 0.8, and its specific process is shown in Figure 10.

3.4.6. Mutation

The crossover operation is only to operate on the original chromosomes and exchange their gene order. This can only guarantee a local optimal solution after multiple evolutions. To achieve the global optimal solution, a mutation operation is added. After that, we can introduce new genes into existing chromosomes by randomly modifying genes. In this study, a gene was selected for mutation. We then randomly generate a floating-point number between 0 and 0.1 and add the floating-point number and the value of the selected gene as the mutational gene value. The mutation process is shown in Figure 11. From the observed results, we can see that if the program chooses to mutate the second gene, it changes the value of 0.75602. Then a floating-point number 0.012 is randomly generated. The sum of these two values is taken as the value after the mutation, which is 0.76802. Not every iteration will perform mutation operations on genes. In this study, the mutation ratio was set to 0.2.

3.4.7. Iteration

We then set an integer value in the experiments. When the number of iterations reaches this value, the program stops running. The number of iterations set in the experiments is 1,000.

4. The Proposed Stock Trading System Combining LSTMLI Framework and GA

This paper proposes a stock trading system based on LSTMLI and GA. In the first subsection of this chapter, the data set used in the experiment is briefly introduced. The second part is to initialize the data set and use the processed data as input to the framework. The third part introduces the proposed stock trading system.

4.1. Data Sets

The data sets used in the experiments are historical data, futures, and options because, in financial markets, stock prices are affected not only by historical behaviors but also by leading indicators. Leading indicators can reflect the state of future economic development and are also called predictive indicators, which can provide predictive information for future economic conditions. Using these indicators, researchers can know the turning point of the economy in advance to adopt appropriate trading strategies. For example, when the monetary authorities reduce the money supply, on the one hand, it shows the policy intentions of the authorities, implying the current trend of overheating in the economy. On the other hand, it will bring an increase in interest rates, which will increase the cost of enterprises and reduce profits, thereby reducing the attractiveness of investors. The increase in interest rates increases the opportunity cost of stock investment, which inevitably leads to a reduction in investment and a decline in stock prices. Therefore, this study focuses on the correlation between two leading indicators of futures and options in the stock market and uses leading indicators to predict the trend of stock prices.

Five important indicators of historical price are often used: opening price, lowest price, highest price, closing price, and volume for stock price analysis. The futures indicators used in our experiments include opening price, highest value, lowest value, closing price, and volume. The indicators used here include volume, open interest, closing price, and settlement price.

First, let’s look at a data set of five stocks in the Taiwan market. The five stocks are , , , , and. Tables 24 are the historical data, futures data, and option data of the five Taiwan stocks, respectively.

In Tables 24, , , and are the various factors that affect the stock price. represents the open, high, low, close, or volatility attributes of the stock. represents the current price, the opening price, the highest price, and the closing price of the futures. represents the attributes of open interest and settlement price of options. Among them, options include buy and sell options.

4.2. Data Initialization

Before the experiment, input data needs to be further processed, that is, to standardize the data because the experiments may be affected by the size of the data and the results are not ideal. Thus, the first priority thing to do is to standarize the original data to ensure the consistency in terms of the range of all collected data. The processed data conforms to the standard normal distribution and helps improve the accuracy of the prediction, which can be referred to the following equation:where is the average value of data samples within 120 days, is the maximum value of the data sample within 120 days, and is the minimum value of the data sample within 120 days. Because the stock price within 120 days will not fluctuate too much, the data within 120 years is used as a set of values to normalize. Taiwan’s stock data is taken as an example to standardize historical prices, and the standardized data is shown in Table 5.

4.3. The Proposed Stock Trading System

In this section, the proposed stock trading system will be introduced in detail. This system consists of the LSTMLI framework and GA. To make the predicted stock price closer to the actual value, this research uses three data sets, including historical prices, futures, and options. First, input three data sets into the LSTMLI framework to get the values of three nodes. These three nodes represent three meanings: the first node represents a buy signal, the second node represents a hold signal, and the third node represents a sell signal. Here, only the first and the third nodes are used. The reason is that in this paper, you only need to know the buy and sell signals of the stock. Next, two nodes are used to find the optimal threshold of stock trading signals. The nodes are considered as the input data in GA, and the thresholds of the two buying and selling signals can be obtained through operations such as crossover, mutation, and iteration. Finally, the value of the node obtained through the test data set is compared with the threshold to obtain a more correct buying and selling point, and this rule is used to calculate the cumulative income over a period of time. The flowchart of this stock trading system is shown in Figure 12.

5. Experimental Results

This experiment mainly uses leading indicators to study stock trading signals. For investors, finding accurate trading signals is crucial, that is, stock buy and sell signals. Because trading signals are not only affected by one factor, trading signals are difficult to be accurately predicted. In this research, a new LSTMLI framework is proposed based on leading indicators. Combining this framework with genetic algorithms, a pair of trading signals can be found. Using this trading signal for stock trading, a certain amount of income can be gained. The data used in the experiments are the Taiwan stock market data (https://www.twse.com.tw/en/) from September 28, 2018, to October 30, 2019, and the US stock market data (https://finance.yahoo.com/) from September 28, 2018, to August 30, 2019.

In the experiments, a total of 10 stocks were used: 5 stocks in the US market, including Microsoft Corporation (MSFT), International Business Machines, Facebook, Inc. (FB), Amazon.com, Inc. (AMZN), and Apple Inc. (AAPL), and 5 stocks in the Taiwan market, including MediaTek (DVO), Formosa Plastics (CFO), TSMC (CDA), Asustek (DJO), and Largan (IJO). In the experiments, three data sets are used, which are historical stock prices, futures, and options. The data set is divided into two parts: one part is used for training and the other part is used for testing. This research compares the proposed stock trading system with another trading strategy (SSACNN combined with GA). We assume that the initial funding is 100,000 USD in the designed trading system. When a buy signal appears, all funds are used to buy stocks, and when a sell signal appears, all stocks are sold. The specific experimental process is shown below.

First, a study has been conducted on five stocks in the US stock market, and the results are shown in Figures 13(a)13(e). Among them, the abscissa represents the data set; “HP” represents historical prices; “O” represents options; and “HP + O” represents historical prices and options. Because there is no leading indicator of futures in the US stock market, only two data sets such as historical prices and options are used. In addition, the two data sets of historical price and option rights are combined to form a third data set, namely, “HP + O”. The ordinate represents the cumulative income during the test period. Experimental results show that our proposed stock trading system is superior to the trading strategy composed of SSACNN and GA. It can be seen from these five figures that in general, the profit margin obtained by using LSTMLI is higher than that obtained by using SSACNN. On the AAPL stock option data set, the profit margin obtained by the LSTMLI model reached 31.7%, which is about 10% higher than the result obtained by the SSACNN model. Next, the experiments will compare a data set with leading indicators and a data set with only historical prices. In general, whether it is LSTMLI or SSACNN, the profit margin obtained by using the data set with the leading indicator is higher than the profit margin obtained by the data set with only historical prices.

Then, we conduct the experiments with the five stocks in the Taiwan stock market, and the results are then shown in Figures 14(a)14(e). In the experiments of five stocks in Taiwan, data sets such as historical price (HP), futures (F), and option (O) were used. Besides, the three data sets are combined to form the fourth data set “HP + O + F”. It can be seen from the figures that the stock trading system proposed in this study can obtain relatively good returns. The experimental results show that the profit margin obtained by the LSTMLI framework is much higher than that of SSACNN. Overall, the experimental results obtained using the leading indicator data set are higher than the experimental results obtained using only the historical price data set.

6. Conclusion

This paper mainly proposes a stock trading system, which is composed of a long short-term memory neural network with leading index (LSTMLI) and GA. We first propose a new architecture with leading indicators, LSTMLI, based on the LSTM model. Compared with SSACNN, this model can obtain higher benefits. Besides, genetic algorithms are used to find the optimal value of stock trading signals. In the input of LSTMLI architecture to reduce useless information, the designed model also integrates the data into a matrix and then uses the matrix as input instead of inputting it into the model one by one. In other words, the input to the model in the paper is an image. Besides, the output of the model adopts a classification method to divide the stock price into three categories: +0.01, 0, and −0.01, that is, the predicted stock price is no longer a specific value but a category. The output of the LSTMLI architecture is three nodes. In this study, only the first and the third nodes are used, that is, only the buy and the sell signals are used. The experimental results show that the proposed stock trading system can help investors obtain certain returns within a period of time. Leading indicators can help researchers predict stock trends more effectively. This study only uses the two leading indicators of futures and options, and many factors affect the stock market, which requires further research. After that, we will further study and improve this stock trading system for further extension.

Data Availability

The data used in the experiments are available at https://www.twse.com.tw/en/ for the Taiwan stock market and at https://finance.yahoo.com/ for the US stock market.

Conflicts of Interest

The authors declare that they have no conflicts of interest.

Acknowledgments

This research was partially supported by the Shandong Provincial Natural Science Foundation (ZR201911150391) and the Western Norway University of Applied Sciences, Norway.