Futures price prediction method based on time sequence attention and future variety dynamic graph

By introducing time-series attention and dynamic charts of futures contracts as predictive methods, the shortcomings of time scale and commodity relationships are addressed, achieving high-precision prediction of futures prices and improving the model's sensitivity and adaptability.

CN120996932APending Publication Date: 2025-11-21ANSTEEL GROUP MINING CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510975538.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-15
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

Existing futures price forecasting methods are insufficient in terms of single time scale and lack of dynamic relationship modeling. They are unable to capture both short-term fluctuations and long-term trends simultaneously, and cannot make full use of information from multiple time scales and the complex relationships between futures products, resulting in insufficient forecast accuracy and stability.

Method used

A prediction method based on time-series attention and dynamic graphs of futures contracts is adopted. By constructing an embedding module, an encoder module, and a prediction module, the method captures multi-timescale features and dynamic relationships between futures contracts, and uses a multi-head attention mechanism and a dynamic graph neural network for modeling.

Benefits of technology

It improves the accuracy and stability of futures price forecasts, enabling a more comprehensive capture of market dynamics and enhancing the model's ability to represent complex time-series signals and adapt to changes in market structure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120996932A_ABST
    Figure CN120996932A_ABST
Patent Text Reader

Abstract

The invention provides a future price prediction method based on time sequence attention and a dynamic graph of future varieties, and the method comprises the following steps: obtaining historical market data of the future varieties, constructing a technical index library, stacking the data into a three-dimensional matrix according to the future varieties, and forming future time sequence data; based on the futures time series data, dividing a training set, a verification set and a test set, carrying out standardization processing on the futures time series data, and constructing a reference data set for futures prediction; constructing a future price prediction model based on the time sequence attention and future variety dynamic graph; and inputting test set data in the reference data set for futures prediction into the trained futures price prediction model to realize prediction of futures prices. According to the method, a plurality of technical indexes are introduced to improve the precision of future price prediction, a multi-time scale aggregation operation is utilized to improve the time sequence sensitivity of a model, the relevance among future varieties is captured by means of a dynamic graph, and finally more accurate future price prediction is provided.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of artificial neural networks, big data processing and data prediction, and particularly relates to a futures price prediction method based on time series attention and futures variety dynamic graph. BACKGROUND

[0002] With the development of artificial intelligence, deep learning methods are widely used in the field of futures price prediction, and certain achievements have been made. Traditional methods mostly rely on historical price data of a single variety, and use models such as recurrent neural networks, convolutional networks, and self-attention mechanisms to model price trends. However, in practical applications, there are still two key problems that need to be solved: On the one hand, existing methods mostly use fixed time windows for feature extraction, with a single time scale that cannot fully utilize information at different time scales, making it difficult to capture both short-term fluctuations and long-term trend signals, resulting in weak model responsiveness to market changes. In the futures market, short-term fluctuation information is crucial for capturing immediate price changes, while long-term trend information helps to grasp the overall market trend. Focusing on a single time scale can result in the model failing to fully reflect the time series characteristics of futures prices, reducing the model's sensitivity to market changes. Especially in the high-volatility, high-frequency trading futures market, information at different time granularities has different importance for price prediction, and a single time scale modeling approach cannot meet the needs of refined prediction. Although some studies have attempted to incorporate multi-time scale information, such as through multi-window extraction or multi-time scale modeling, these methods often only perform shallow concatenation or simple parallel processing, lack deep fusion mechanisms, and cannot fully exploit the complementarity and synergy between different scales. In addition, the design of multi-scale models often lacks theoretical basis for scale selection, has redundant parameters, and has rough fusion strategies, resulting in increased model complexity but limited performance improvement, and even the risk of overfitting.

[0003] On the other hand, existing methods lack dynamic relationship modeling. In the futures market, there are complex relationships between different varieties, such as upstream and downstream, substitution, and linkage, for example, iron ore is the main raw material for threaded steel, and the price of iron ore futures may be affected by the price of threaded steel futures, and there is a convergence phenomenon in the price trend of the two. However, existing technologies mostly ignore or only handle the transmission relationship between varieties in a static way, lacking the ability to dynamically model changes over time. This deficiency limits the model's understanding of the overall market structure, making it difficult to adapt to the complex dynamics of the market, limiting the model's ability to capture overall market changes, and affecting the accuracy and stability of the prediction results.

[0004] Therefore, there is an urgent need for a prediction method that can simultaneously integrate multi-time scale feature information and dynamically model complex relationships between futures varieties to improve the model's ability to capture market dynamics and overall modeling effectiveness. SUMMARY

[0005] The application provides a futures price prediction method based on time sequence attention and dynamic graph of futures varieties, to solve the lack of attention to the spatial relationship and multi-time granularity of futures prices in the prior art, and improve the accuracy of futures price prediction. The application provides the following technical scheme: a futures price prediction method based on time sequence attention and dynamic graph of futures varieties, characterized in that the method comprises the following steps: S1, acquiring historical market data of a plurality of futures varieties with long listing time; S2, constructing a technical index library, processing technical index data in the technical index library, and constituting futures time sequence data; S3, dividing a training set, a validation set and a test set based on the futures time sequence data in the technical index library, and performing standardization processing on the futures time sequence data to construct a benchmark data set for futures prediction; S4, constructing a futures price prediction model based on time sequence attention and dynamic graph of futures varieties, for predicting futures prices; S5, training the futures price prediction model based on training set data in the benchmark data set for futures prediction, to obtain a trained futures price prediction model; S6, inputting test set data in the benchmark data set for futures prediction into the trained futures price prediction model, to realize prediction of futures prices.

[0006] Further, the historical market data comprises opening price, highest price, lowest price, closing price, trading volume, trading amount, amplitude, price fluctuation range and price fluctuation amount.

[0007] Further, the technical indexes comprise price index, trading volume index, popularity momentum index, fund flow index and value scale index.

[0008] Further, the process of processing the technical index data in the technical index library to constitute the futures time sequence data is as follows: The technical index data and the historical market data are aligned in time sequence according to the futures varieties, and missing values are processed by filling strategy; The historical daily market data after filling the missing values is combined with the technical index data to form price feature data, and the data is stacked into a three-dimensional matrix according to the futures varieties to constitute the futures time sequence data.

[0009] Further, the futures price prediction model based on time sequence attention and dynamic graph of futures varieties comprises: an embedding module for capturing local features and global features of time sequence data; The construction encoder module is configured to describe the relationship between futures varieties and capture long-term trends and short-term fluctuation characteristics of futures price sequences based on local features and global features of time series data output by the embedding module, and learn dynamic relationships between futures price features. The prediction module is configured to map data after feature learning to a prediction space based on dynamic relationships between futures price features output by the construction encoder module, so as to realize accurate futures price prediction.

[0010] Further, the embedding module comprises: A normalization unit is configured to perform standardization processing on price feature data in input futures time series data, the price features including historical market quotations and technical indicators, so as to ensure that all price features of each sample have zero mean and unit variance. A first feature mapping unit is configured to divide data processed by the normalization unit into multiple time blocks through a sliding window operation, and map time step information and price feature information of each time block to a high-dimensional space to generate embedding representation; position encoding of the same dimension is added to each time block to capture the relative position of each time block in the input data, so as to retain the time sequence and spatial information of the data. A global label adding unit is configured to generate a learnable global label based on the time dimension of data processed by the first feature mapping unit; and the global label is concatenated with along the time dimension to form a complete embedding feature sequence containing the global label.

[0011] Further, the encoder module comprises: A graph construction unit is configured to generate a graph adjacency matrix according to embedding of input futures nodes, describe the relationship between futures nodes, and provide graph structure information for subsequent operations, the futures nodes being price feature representations of each futures variety, and the embedding of the futures nodes being embedding initialized by trainable neural network parameters. The multi-level cascading attention unit comprises sequentially connected multi-scale feature encoding layers, graph learning layers and normalization layers, wherein: The multi-scale feature encoding layer is configured to extract long-term trends and short-term fluctuation characteristics of the complete embedding feature sequence containing the global label. The graph learning layer is configured to first perform normalization processing on the adjacency matrix; then perform multiple graph convolution operations on the global label in the output of the multi-scale time encoding layer, concatenate the original global label and the global label after convolution in the feature dimension, and perform linear transformation on the concatenated result; finally, update the global label through residual connection, concatenate the updated global label and time block features in the output of the multi-scale time encoding layer except the global label, and form a complete feature sequence. The normalization layer is used for layer normalization processing of the learned data of the graph, to ensure that the feature distribution of each sample is consistent.

[0012] Further, the process of generating an adjacency matrix of the graph according to the input futures node embedding to describe the relationship between the futures nodes and to provide the graph structure information for subsequent operations is as follows: The learnable futures node embedding matrix is generated through trainable neural network parameters; The transformed futures node feature vector is obtained through the futures node embedding

[0013] Based on The similarity between the futures nodes is calculated through the dot product to obtain the adjacency matrix; If the number of futures nodes is greater than the predetermined number of most relevant neighbors per futures node parameter , the nearest neighbor mask method of the number of most relevant neighbors is applied to retain the top k largest similarity values of each futures node, and the rest is set to zero to obtain a sparse adjacency matrix.

[0014] Further, the long-term trend and short-term fluctuation features of the complete embedding feature sequence containing the global mark are extracted in the following specific manner: The learnable position encoding is applied to the complete embedding feature sequence to generate enhanced time sequence features; In the complete embedding feature sequence after the enhanced time sequence features, the part other than the global mark is divided into multiple local time windows, the information of multiple time blocks is aggregated, and then the global mark is spliced to form a multi-scale price feature sequence

[0015] The query matrix , the key matrix and the value matrix are obtained after linear transformation of the multi-scale price feature sequence; The , and are divided into h attention heads, the features of a single attention head are calculated through self-attention, and multi-head attention features are generated through linear transformation; The is restored from the multi-time window sequence structure to the original time block sequence structure, and sequentially passes through residual connection, convolution layer, activation function and layer normalization to obtain the output of the multi-scale time encoding layer.

[0016] Further, the prediction module comprises: The second feature mapping unit is configured to combine the features of the input data and the time dimension into a composite feature dimension, and map the composite feature dimension to the prediction length through linear transformation to obtain a prediction output; The denormalization unit is configured to perform inverse normalization processing on the prediction output of the second feature mapping unit, and restore the prediction output to the same numerical scale as the original data by multiplying the prediction output by the standard deviation and adding the mean.

[0017] To solve the above problems, the application provides a futures price prediction method fusing a time sequence attention mechanism and dynamic graph relationship modeling, which can effectively improve the prediction accuracy, fully utilize multi-time scale information and model the dynamic relationship between futures varieties, and has important practical significance.

[0018] On the one hand, the time sequence modeling structure based on the multi-head attention mechanism is introduced, which can capture the time sequence dependence under different time scales, effectively model the long-term trend and short-term fluctuation, and improve the representation ability of the model for complex time sequence signals.

[0019] On the other hand, the dynamic graph neural network is introduced, which dynamically constructs the correlation between futures varieties according to market data, models the non-static structure evolving over time, and enhances the adaptability of the model to market structure changes.

[0020] The application breaks through the deficiencies of the prior art in time scale, variety relationship and nonlinear modeling, and can more comprehensively capture the complex dynamic changes of futures prices, improving the prediction accuracy, robustness and applicability.

[0021] Through the above technical design, the application realizes unified modeling of the dynamic linkage relationship between futures varieties and the multi-time scale characteristics, can more accurately restore the complex interaction and structure evolution process between heterogeneous assets in the actual market, thereby improving the accuracy and stability of futures price prediction, and has good practical application value and expansion ability.

[0022] Compared with the prior art, the technical scheme provided by the application has at least the following beneficial effects: On the one hand, the application introduces multiple technical indicators to effectively improve the accuracy of futures price prediction. On this basis, the application aggregates information of different time scales to capture the long-term trend of futures prices and accurately reflect the short-term fluctuation characteristics, further improving the time sequence sensitivity of the model. On the other hand, the application also proposes an innovative dynamic relationship modeling method between futures varieties, which systematically excavates the correlation between different futures varieties, and enhances the modeling ability of the model for complex market dynamics. Finally, by combining multi-scale information and the correlation between futures varieties, the application can provide more accurate futures price prediction results, and has significant technical advantages. Attached Figure Description

[0023] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0024] Figure 1 A flowchart of the futures price prediction method provided by the present invention; Figure 2 This is a diagram of the futures price prediction model architecture involved in this invention; Figure 3 This is a schematic diagram of the embedded module involved in the present invention; Figure 4 This is a schematic diagram of the graph construction unit involved in the present invention; Figure 5 This is a schematic diagram of the multi-scale feature coding layer involved in the present invention; Figure 6 This is a schematic diagram of the graph learning layer involved in this invention; Figure 7 This is a visualization of the prediction results of the model involved in this invention on iron ore futures data. Detailed Implementation

[0025] The present invention will be further illustrated below with reference to the accompanying drawings and specific embodiments. It should be understood that the described embodiments are only a part of the embodiments of the present invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.

[0026] Those skilled in the art should understand that the following specific embodiments or implementation methods are a series of optimized configurations listed to further explain the specific content of the invention. These configuration methods can be combined or used in conjunction with each other, unless the invention explicitly states that some or a specific embodiment or implementation method cannot be associated with or used in conjunction with other embodiments or implementation methods. Furthermore, the following specific embodiments or implementation methods are only considered as optimized configurations and are not intended to limit the scope of protection of the invention.

[0027] A futures price prediction method based on temporal attention and dynamic graphs of futures products includes the following steps: S1: Obtain historical market data for multiple futures contracts with a sufficiently long listing period; S2, construct a technical indicator library, process the technical indicator data in the technical indicator library, and form futures time series data; S3, based on the futures time series data in the technical indicator library, divide the training set, the validation set and the test set, and standardize the futures time series data to construct a benchmark data set for futures prediction; The non-date data in the training set is standardized by calculating the mean and standard deviation of each column, and the data is converted into a standard normal distribution with a mean of zero and a standard deviation of one. The mean and standard deviation calculated in the training set are used to standardize the corresponding feature columns of the validation set and test set data, ensuring that the distribution of the validation set and test set data is consistent with the training set.

[0028] S4, construct a futures price prediction model based on time series attention and futures variety dynamic graph for predicting futures prices; S5, train the futures price prediction model based on the training set data in the benchmark data set for futures prediction to obtain a trained futures price prediction model; S6, input the test set data in the benchmark data set for futures prediction into the trained futures price prediction model to realize the prediction of futures prices.

[0029] Further, the historical market data includes opening price, highest price, lowest price, closing price, trading volume, trading volume, amplitude, price range and price range. Based on the historical market data, the technical indicators are calculated through the technical indicator library; Further, the technical indicators include: price indicators, trading volume indicators, popularity momentum indicators, capital flow indicators and value scale indicators.

[0030] The technical indicator library is used for technical analysis and contains the calculation methods of price indicators, trading volume indicators, popularity momentum indicators, capital flow indicators and value scale indicators; Further, the process of processing the technical indicator data in the technical indicator library to form futures time series data is as follows: The technical indicator data and historical market data are aligned in time series according to the futures variety, and the missing values are handled by filling strategy; The historical daily market data and technical indicator data after filling the missing values are combined into price feature data, and the data is stacked into a three-dimensional matrix according to the futures variety to form the futures time series data.

[0031] Further, the futures price prediction model based on time series attention and futures variety dynamic graph includes: Embedding module for capturing local features and global features of time series data; The construction encoder module is configured to describe the relationship between futures varieties based on the local features and global features of the time series data output by the embedding module, capture long-term trends and short-term fluctuation characteristics of the futures price sequence, and learn the dynamic relationship between the futures price features. The prediction module is configured to map the data after feature learning to a prediction space based on the dynamic relationship between the futures price features output by the construction encoder module, so as to realize accurate futures price prediction.

[0032] Further, the embedding module comprises: A normalization unit is configured to perform standardization processing on price feature data in the input futures time series data, the price features including historical market quotations and technical indicators, so as to ensure that all price features of each sample have zero mean and unit variance, and eliminate non-stationarity of the time series data. A first feature mapping unit is configured to divide the data processed by the normalization unit into a plurality of time blocks through a sliding window operation, and map time step information and price feature information of each time block to a high-dimensional space to generate an embedding representation; position encoding of the same dimension is added to each time block to capture the relative position of each time block in the input data, so as to retain the time sequence and spatial information of the data. The data processed by the feature mapping unit can be represented as wherein N is the number of futures varieties, t is the number of time blocks, and d is the embedding feature dimension; wherein the position encoding calculation formula is as follows: , ; wherein is the position, is the index of the feature dimension, and PE represents the position encoding. A global marker adding unit is configured to generate a learnable global marker based on the data processed by the first feature mapping unit in the time dimension, the dimension being consistent with the embedding feature dimension of , which can be represented as , for capturing global information of the embedding features; the global marker is spliced with along the time dimension to form a complete embedding feature sequence containing the global marker, which can be represented as .

[0033] Further, the encoder module comprises: The graph construction unit is used to generate a graph adjacency matrix based on the embedding of the input futures node, describe the relationship between the futures nodes, and thus provide graph structure information for subsequent operations. The futures node refers to the price feature representation of each futures product, and the embedding of the futures node refers to the embedding initialized by the parameters of a trainable neural network. The multi-layered cascaded attention unit comprises a multi-scale feature encoding layer, a graph learning layer, and a normalization layer connected in sequence, wherein: The multi-scale feature encoding layer is used to extract long-term trend and short-term fluctuation features of the complete embedded feature sequence containing global labels: In the graph learning layer, if the current layer is not the last attention layer, it is not added to the graph learning layer; otherwise, the adjacency matrix is ​​first processed. Normalization The normalization formula is as follows:

[0034] in, It is the number of nodes in the graph. and These represent the row and column indices of the adjacency matrix, respectively.

[0035] Subsequently, the global markers in the output of the multi-scale temporal coding layer are... Perform multiple graph convolution operations, each graph convolution operation is represented as:

[0036] in, It is an adjacency matrix. Indicates the number of samples. and Indicates the node index. Representing feature dimension, It represents the number of nodes.

[0037] Remove the original global flag With the Global label output after convolution The feature dimension is concatenated, the concatenated result undergoes a linear transformation, and finally, the global label is updated through residual connections. Specifically, it can be expressed as: =concat )

[0038] in, The number of convolution operations. The dimension size is The learnable weight matrix.

[0039] Updated global token Concatenate the time block features in the multi-scale time encoding layer output except the global token to form a complete feature sequence.

[0040] The normalization layer is used to perform layer normalization processing on the data learned by the graph, ensuring that the feature distribution of each sample is consistent, thereby improving the training stability of the model.

[0041] Further, the process of generating the adjacency matrix of the graph according to the input futures node embedding to describe the relationship between the futures nodes and provide graph structure information for subsequent operations is as follows: Generate a learnable futures node embedding matrix through trainable neural network parameters , wherein is the number of futures varieties, is the dimension of the embedding, and E represents the futures node embedding matrix; the transformed futures node feature vector is obtained through the futures node embedding and , which is specifically represented as: , ; wherein, and are trainable weight matrices, and are bias terms, is an activation function; The similarity between the futures nodes is calculated based on the dot product of and to obtain the adjacency matrix , which is specifically represented as: ; wherein, is an activation function; If the number of futures nodes in the graph is greater than the predetermined number of most relevant neighbors per futures node parameter , then the k-nearest neighbor mask method is applied to retain the top k largest similarity values for each futures node, and the remaining values are set to zero to obtain a sparse adjacency matrix. Further, the long-term trend and short-term fluctuation features of the complete embedding feature sequence containing the global token are extracted in the following specific manner: Apply a learnable position encoding to the complete embedding feature sequence to generate enhanced time sequence features; In the complete embedding feature sequence after the enhanced time sequence features, the part other than the global token is divided into multiple local time windows, the information of multiple time blocks is aggregated, and then the global token is concatenated to form a multi-scale price feature sequence , wherein, is the number of futures varieties, p is the number of local time windows, is the number of feature dimensions, and the size of the local time window is calculated according to the following formula: ; wherein, is the number of time blocks, is the number of multi-layer cascaded stacked attention units, is the number of layers of the current multi-layer cascaded stacked attention unit; is obtained by linear transformation , the query matrix , the key matrix and the value matrix , which is specifically represented as: ; wherein, is a trainable weight matrix with a dimension size of , and X represents a multi-scale price feature sequence; is divided into , and attention heads, and the input of a single attention head is h , , , The feature representation of a single attention head is calculated by self-attention , and the multi-head attention feature representation is generated by linear transformation, which is specifically represented as: , ; wherein, represents a trainable weight matrix, is an upper triangular matrix used for mask operation of future time steps, to maintain the causality of time series data, (·) is a softmax normalization operation; is restored from the multi-time window sequence structure to the original time block sequence structure, and sequentially passes through a residual connection, a convolution layer, an activation function and layer normalization to obtain the output of the multi-scale time encoding layer , which is specifically represented as:

[0042]

[0043]

[0044] in, (·) represents a one-dimensional convolutional layer. (·) represents the activation function. (·) indicates layer normalization; Furthermore, the prediction module includes: The second feature mapping unit is used to merge the features and time dimension of the input data into a composite feature dimension, and to map the composite feature dimension to the prediction length through a linear transformation to obtain the prediction output. The denormalization unit is used to perform inverse standardization on the predicted output of the second feature mapping unit. By multiplying the predicted output by the standard deviation and adding the mean, the predicted output is restored to the same numerical scale as the original data.

[0045] Furthermore, the training set data in the benchmark dataset based on futures prediction is used to train the futures price prediction model to obtain a trained futures price prediction model. In each training round, the training set data is input into the futures price prediction model in batches. The error between the predicted output and the actual data is calculated and used as the training loss of the futures price prediction model. The futures price prediction model iteratively updates its parameters based on the training loss. After completing one round of training on the training set data, the validation set is input into the futures price model. The convergence of the model is determined by calculating the trend of the loss function on the validation set. If the validation set loss fails to decrease significantly in five consecutive training rounds (i.e., the decrease in the loss function is below a preset threshold, or the loss continues to rise), the model is considered to have converged and training is stopped. If training continues, the above process is used; otherwise, the following process is executed. After the training process converges, the trained futures price prediction model is used to predict the test set, and the prediction error is evaluated and analyzed based on the prediction output and the real data.

[0046] The formula for calculating the mean square error (MSE) is as follows: ; in, The number of input samples for each batch. For the first The predicted output value for each sample. For the first The true value of each sample.

[0047] The prediction error includes Mean Absolute Error (MAE), Mean Square Error (MSE), and Root Mean Square Error (RMSE). The smaller the value, the higher the prediction accuracy of the model. The formulas for calculating the Mean Absolute Error (MAE) and Root Mean Square Error (RMSE) are as follows: ; ; wherein, is the number of input samples of each batch, is the predicted output value of the th sample, is the true value of the th sample.

[0048] Embodiment 1: The present application provides a futures price prediction method based on time sequence attention and futures variety dynamic graph, which combines Figure 1 As shown in the figure, the method of the present embodiment comprises the following steps: S1, obtaining historical market data of a plurality of futures varieties with long listing time, wherein the historical market data comprises opening price, highest price, lowest price, closing price, trading volume, trading volume, amplitude, price range and price range; It should be noted that in the present embodiment, the above S1 is specifically: obtaining historical market data of futures varieties listed before 2014 from the RESSET database, wherein the obtained futures varieties include, for example, white sugar main connection, Shanghai lead main connection, Shanghai aluminum main connection, Shanghai copper main connection, plywood main connection, strong wheat main connection, early indica rice main connection, japonica rice main connection, rapeseed main connection, cotton main connection, egg main connection, plastic main connection, screw thread steel main connection, palm oil main connection, iron ore main connection, Shanghai zinc main connection, PTA main connection, Shanghai gold main connection, PVC main connection, coke main connection, corn main connection, vegetable oil main connection, bean one main connection, rapeseed meal main connection, soybean meal main connection, soybean oil main connection, methanol main connection, rubber main connection, asphalt main connection, Shanghai silver main connection, glass main connection, etc.; the historical market data includes opening price, highest price, lowest price, closing price, trading volume, trading volume, amplitude, price range and price range data from January 1, 2014 to January 1, 2024.

[0049] S2, constructing a technical index library, calculating technical index data based on the obtained above market data, and filling missing values of the technical index data and historical market data, stacking data into a three-dimensional matrix according to futures varieties, and constructing futures time sequence data.

[0050] Specifically, in the present embodiment, the implementation process of the above S2 is as follows: S21, constructing a technical index library, calculating technical index data based on the market data.

[0051] Specifically, in the present embodiment, the implementation process of the above S21 is as follows: S211, a technical indicator library is constructed, which is used for technical analysis, and is selected from Stock Classic Technology Weekly and Joinquant Quantitative Investment and Research Platform (https: / / www.joinquant.com) and the like, and contains the calculation methods of price, trading volume, momentum, fund flow and value size indicators. The specific calculation methods of the technical indicators are obtained by using the existing public indicator calculation methods, which are not described herein. In a more specific embodiment, the specific technical indicators are shown in Table 1: Table 1 Technical Indicator Table

[0052] S212, based on the historical market data, the corresponding technical indicator data is calculated by the calculation method in the technical indicator library. For the missing value, the zero value filling method is used for supplement.

[0053] S22, the technical indicator data and the historical market data are filled with missing values.

[0054] The process of filling the missing values is to unify the dates of the historical market data and the technical indicator data of all futures varieties, and ensure that the dates of each data source are aligned. For the data corresponding to the missing dates, the filling strategy is adopted, including: the missing values of the opening price, the highest price, the lowest price and the closing price in the historical market are filled with the corresponding data of the previous trading day; the missing values of the historical market and the technical indicators are filled with zero values.

[0055] S23, the historical market data and the technical indicator data after filling the missing values are merged into price feature data, and the data is stacked into a three-dimensional matrix according to the futures varieties, to form futures time series data.

[0056] S3, based on the futures time series data, the training set, the validation set and the test set are divided, and the data is standardized, to construct a benchmark data set for futures prediction.

[0057] In the embodiment, the implementation process of S3 is as follows: S31, the time series data is divided into training set, validation set and test set according to the year in the ratio of 8:1:1.

[0058] S32, the non-date data in the training set is standardized by calculating the mean and standard deviation of each column, and the data is converted into a standard normal distribution with a mean of zero and a standard deviation of one.

[0059] S32, the mean and standard deviation calculated in the training set are used to standardize the corresponding feature columns of the validation set and the test set data, to ensure that the distribution of the validation set and the test set data is consistent with the training set.

[0060] S4, constructing a futures price prediction model based on the time-series attention and futures variety dynamic graph, wherein the futures price prediction model comprises an embedding module, an encoder module, and a prediction module. The model architecture is as shown in Figure 2 .

[0061] The specific construction process of the futures price prediction model based on the time-series attention and futures variety dynamic graph is as follows: first, an embedding module is constructed to capture local and global features of time-series data; second, an encoder module is constructed, which comprises a graph construction unit and a multi-layer cascading attention unit. The graph construction unit is used to describe the relationship between futures varieties. The multi-layer cascading attention unit captures long-term trends and short-term fluctuation features of futures price sequences through a multi-layer multi-scale feature encoding layer, and further learns the dynamic relationship between futures price features through a graph learning layer to enhance the learning ability of spatial features; finally, a prediction module is constructed to map the data after feature learning to a prediction space, thereby realizing accurate futures price prediction.

[0062] In the present embodiment, the implementation process of S4 is as follows: S41, constructing an embedding module to capture local and global features of time-series data. The embedding module is as shown in Figure 3 .

[0063] Specifically, in the present embodiment, S41 comprises the following steps: S411, constructing a normalization unit to perform standardization processing on the price feature data in the input futures time-series data, wherein the price features include historical market quotations and technical indicators, to ensure that all price features of each sample have zero mean and unit variance, and to eliminate the non-stationarity of time-series data; S412, constructing a first feature mapping unit to divide the normalized data into multiple time blocks through a sliding window operation, and to map the time step information and price feature information of each time block to a high-dimensional space to generate an embedding representation. A position encoding of the same dimension is added to each time block to capture the relative position of each time block in the input data, thereby preserving the time sequence and spatial information of the data. The data processed by the feature mapping unit can be represented as , wherein N is the number of futures varieties, t is the number of time blocks, and d is the feature dimension of the embedding representation and the position encoding; wherein the position encoding calculation formula is as follows:

[0064]

[0065] , wherein is the position, is the index of feature dimension, PE represents position encoding; S413, performing a global label adding operation to generate a learnable global label in the time dimension of , which is consistent with the embedding feature dimension of , and can be expressed as , which is used to capture the global information of the embedding feature; and splicing the global label along the time dimension to form a complete embedding feature sequence containing the global label, which can be expressed as .

[0066] S42, constructing an encoder module including a graph construction unit and a multi-layer cascaded attention unit, wherein the multi-layer cascaded attention unit comprises sequentially connected multi-scale feature encoding layers, graph learning layers and normalization layers.

[0067] Specifically, in the embodiment, the above S42 comprises the following steps: S421, constructing a graph construction unit for generating an adjacency matrix of a graph according to an input futures node embedding to describe the relationship between the futures nodes, thereby providing graph structure information for subsequent operations, wherein the futures node refers to the price feature representation of each futures variety, and the futures node embedding is an embedding initialized by trainable neural network parameters. The schematic diagram of the graph construction unit is shown in Figure 4 .

[0068] Specifically, the construction process of the graph construction unit is as follows: generate a learnable futures node embedding matrix , wherein is the number of futures varieties, is the node embedding dimension, and E represents the futures node embedding matrix; the transformed futures node feature vector and are obtained through the futures node embedding, and are specifically expressed as:

[0069]

[0070] wherein, and are trainable weight matrices, and are bias terms, is an activation function; based on the dot product of and , the similarity between nodes is calculated to obtain an adjacency matrix , which is specifically expressed as:

[0071] wherein, is an activation function; if the number of future nodes in the graph is greater than a predetermined number of most relevant neighbors per future node parameter , then a k-neighborhood mask is applied to retain the top k most similar values for each future node, and the rest are set to zero to obtain a sparse adjacency matrix; S422, a multi-scale feature encoding layer in the multi-layer cascaded stack attention unit is constructed to extract long-term trends and short-term fluctuations of complete embedding feature sequences containing global labels. The multi-scale feature encoding layer is shown in the schematic diagram as Figure 5 .

[0072] Specifically, the construction process of the multi-scale feature encoding layer is as follows: A learnable position encoding is applied to the complete embedding feature sequence to generate enhanced time sequence features; In the complete embedding feature sequence after the enhanced time sequence features, the part other than the global label is segmented into multiple local time windows, the information of multiple time blocks is aggregated, and the global label is spliced to form a multi-scale price feature sequence , wherein N is the number of futures varieties, p is the number of local time windows, d is the feature dimension, and the size of the local time window is According to the following formula:

[0073] wherein, is the number of time blocks in the complete embedding feature sequence other than the global label, is the number of multi-layer cascaded stack attention units, is the number of layers of the current multi-layer cascaded stack attention unit; After linear transformation, the query matrix , the key matrix and the value matrix are obtained, which are specifically represented as:

[0074] wherein, is a trainable weight matrix with dimension , and X represents the multi-scale price feature sequence; , and are divided into h attention heads, and the input of a single attention head is , , ​​​, the feature representation of a single attention head is calculated by self-attention , and a multi-head attention feature representation is generated by linear transformation , which is specifically represented as:

[0075]

[0076] wherein, represents a trainable weight matrix, is an upper triangular matrix, used for mask operation of future time steps, to maintain the causality of time series data, (·) is a softmax normalization operation; is restored from the multiple time window sequence structure to the original time block sequence structure, and sequentially passes through a residual connection, a convolution layer, an activation function and a layer normalization operation to obtain the output of the multi-scale time encoding layer , which is specifically represented as:

[0077]

[0078]

[0079] wherein, (·) represents a one-dimensional convolution layer, (·) represents an activation function, (·) represents layer normalization. S423, a graph learning layer in the multi-layer cascaded stacked attention unit is constructed. The graph learning layer is shown in Figure 6 .

[0080] Specifically, the construction process of the graph learning layer is as follows: If the current layer is the last attention layer, the graph learning layer is not added, otherwise the adjacency matrix is first normalized to , and the normalization formula is as follows:

[0081] wherein, is the number of nodes in the graph, and represent the row and column indices of the adjacency matrix, respectively.

[0082] Subsequently, the global label in the multi-scale time encoding layer output is subjected to multiple graph convolution operations, and each graph convolution operation is represented as: ​

[0083] wherein, is an adjacency matrix, denotes the number of samples, and denotes the node index, denotes the feature dimension, is the number of nodes.

[0084] The original global label is updated to after the first convolution, and the global label output after the first convolution is spliced in the feature dimension, the spliced result is linearly transformed, and finally the global label is updated through residual connection to , which can be specifically represented as: =concat )

[0085] wherein, is the number of convolution operations, is a learnable weight matrix with a dimension size of .

[0086] The updated global label is spliced with the time block features in the multi-scale time encoding layer output except for the global label to form a complete feature sequence.

[0087] S424, a normalization layer in the multi-layer cascaded stack attention unit is constructed to perform layer normalization processing on the data learned by the graph, so as to ensure that the feature distribution of each sample is consistent, thereby improving the training stability of the model.

[0088] S43, a prediction module is constructed to map the data learned through feature learning to a prediction space, thereby realizing accurate futures price prediction.

[0089] Specifically, in the embodiment, the above S43 includes the following steps: S431, a second feature mapping unit is constructed to combine the features and time dimensions of the input data of the prediction module into a composite feature dimension, and map the composite feature dimension to the prediction length through linear transformation to obtain the prediction output.

[0090] S432, a denormalization unit is constructed to perform inverse standardization processing on the prediction output, and the prediction output is restored to the same numerical scale as the original data by multiplying the prediction output by the standard deviation and adding the mean.

[0091] S5, the futures price prediction model is trained based on the training set data in the benchmark data set of futures prediction, and a trained futures price prediction model is obtained. In each round of training, the data of the training set is input into the futures price prediction model in batches, the mean square error MSE of the predicted output and the true data is calculated, and it is taken as the training loss of the futures price prediction model, and the futures price prediction model is updated according to the training loss. After completing the training of the training set data, the validation set is input into the futures price prediction model, and the mean square error is calculated as the validation loss for judging whether the model converges. If the validation set loss does not decrease significantly (i.e. the loss function decreases by less than a preset threshold, or the loss continues to rise) in the last 5 rounds of training, it is considered that the model has converged and no longer continues to train. If it continues to train, the above process is used, otherwise the process after training convergence is executed.

[0092] Specifically, the mean square error MSE calculation formula is as follows:

[0093] Specifically, is the number of input samples for each batch, is the predicted output value of the i-th sample, is the true value of the i-th sample. Specifically, the implementation process of S5 is as follows: The training process of the futures price prediction model based on time sequence attention and futures variety dynamic graph is as follows: Input: Model parameters: benchmark data set for futures prediction ; data dimension X_dim of the benchmark data set for futures prediction; feature dimension D_dim of the benchmark data set; hidden layer node number h_dim; maximum number of training iterations ; learning rate ; is a random number; batch size batch_size; number of encoder layers layers; input futures price feature sequence length ; output futures price feature sequence length ; dimension of predicted features ; gradient penalty coefficient ; is a random number; maximum number of rounds triggering early stopping .

[0094] Output: Futures price feature sequence .

[0095] Step 1: initialize Adam optimizer; Step 2: according to and ​​, load training set and validation set data; Step 3: iterate according to the set of iteration numbers epoches; For in epoches: Import data of batch_size size in the training set; Input the data into the model to get the output of the futures price feature sequence, and select the first dimension in the feature dimension as the model futures price feature prediction sequence; Calculate the model training loss by the MSE loss function; Calculate the gradient of the training loss, and optimize the parameters using the Adam optimizer; Input the validation set data into the model to calculate the model validation loss; If the validation loss changes continuously rounds without reducing, trigger the early stopping mechanism; If the early stopping mechanism is triggered, then: Stop training and end the iteration loop; End if; Save the smallest validation loss and its corresponding model; End for; Step 4: output the best model trained, where the model with the smallest validation loss is the best model.

[0096] After the training process converges, use the trained futures price prediction model to predict the test set, and evaluate and analyze the prediction error based on the predicted output and the true data; the prediction error includes mean absolute error MAE, mean square error MSE, and root mean square error RMSE, and the smaller the value, the higher the prediction accuracy of the model.

[0097] Specifically, the mean absolute error MAE and root mean square error RMSE calculation formulas are as follows:

[0098]

[0099] Specifically, is the number of input samples for each batch, is the predicted output value of the th sample, is the true value of the th sample.

[0100] Further, in order to fully evaluate the effectiveness of the proposed model, the futures price prediction model and existing time series prediction methods are compared on the benchmark dataset of futures prediction, and the results are shown in Table 2.

[0101] Table 2 comparison results of each method

[0102] In Table 2, Ours is the model proposed in the embodiment, and it can be seen that compared with other prediction methods on the benchmark dataset of futures prediction, significant progress has been made, which shows that the model can more effectively model the spatio-temporal correlation of futures data and improve the prediction accuracy of futures price data.

[0103] In order to further verify the effectiveness of the technical indicators in the benchmark dataset, the historical market data is provided as input to the futures price prediction model, and the prediction results are compared with the prediction results of adding technical indicator data. The comparison results are shown in Table 3.

[0104] Table 3 comparison results of technical indicator methods

[0105] In Table 3, the dataset used by Ours is the benchmark dataset proposed in the embodiment, and Ours price The dataset used only contains historical market data in the benchmark dataset. The comparison results show that after adding technical indicators, the prediction accuracy of futures price data has been partially improved.

[0106] S6, input the test set data in the benchmark dataset of futures prediction into the trained futures price prediction model to realize the prediction of futures price.

[0107] Further, in order to illustrate the effectiveness of the proposed model, the output of the futures price prediction model on the test set is subjected to a reverse normalization operation, the main continuous futures of iron ore are selected, and the normalized prediction value and the true value are subjected to a visualization processing, and the results are shown in Figure 7 .

[0108] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program instructing related hardware. The program can be stored in a computer readable storage medium, and when the program is executed, it can include the processes of the above-mentioned embodiment methods. The storage medium can be a magnetic disc, an optical disc, a read-only memory (ROM) or a random access memory (RAM), etc.

[0109] The above merely illustrates the specific embodiments of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can easily think of the changes or replacements within the technical range disclosed by the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A futures price prediction method based on temporal attention and dynamic graphs of futures products, characterized in that, Includes the following steps: S1: Obtain historical market data for multiple futures contracts with a sufficiently long listing period; S2, construct a technical indicator library, process the technical indicator data in the technical indicator library to form futures time series data; S3. Based on the futures time series data in the technical indicator library, divide the data into training set, validation set and test set, and standardize the futures time series data to construct a benchmark dataset for futures prediction. S4. Construct a futures price prediction model based on time-series attention and dynamic graphs of futures products for predicting futures prices. S5. The futures price prediction model is trained based on the training set data in the benchmark dataset for futures prediction, and a trained futures price prediction model is obtained. S6 inputs the test set data from the benchmark dataset for futures prediction into the trained futures price prediction model to achieve futures price prediction.

2. The futures price prediction method based on time-series attention and dynamic charts of futures products according to claim 1, characterized in that, The historical market data includes opening price, highest price, lowest price, closing price, trading volume, trading value, volatility, price change, and price change amount.

3. The futures price prediction method based on time-series attention and dynamic charts of futures products according to claim 1, characterized in that: The technical indicators include: price indicators, trading volume indicators, market sentiment momentum indicators, capital flow indicators, and value scale indicators.

4. The futures price prediction method based on time-series attention and dynamic charts of futures products according to claim 1, characterized in that: The process of processing the technical indicator data in the technical indicator library to form futures time series data is as follows: Technical indicator data and historical market data are aligned with the time series of futures contracts, and missing values ​​are handled using a filling strategy. The historical daily market data, after filling in the missing values, is combined with the technical indicator data to form price feature data. The data is then stacked into a three-dimensional matrix according to the futures contract to form futures time series data.

5. The futures price prediction method based on time-series attention and dynamic charts of futures products according to claim 1, characterized in that: The futures price prediction model based on time-series attention and futures product dynamic graphs includes: Embedded modules are used to capture local and global features of time-series data; Construct an encoder module: Based on the local and global features of the time series data output by the embedded module, describe the relationship between futures varieties, capture the long-term trend and short-term fluctuation features of futures price sequences, and learn the dynamic relationship between futures price features. Prediction module: Based on the dynamic relationship between the futures price features output by the encoder module, the data after feature learning is mapped to the prediction space, thereby achieving accurate futures price prediction.

6. The futures price prediction method based on time-series attention and dynamic charts of futures products according to claim 5, characterized in that: The embedded module includes: The normalization unit is used to standardize the price feature data in the input futures time series data, including historical market data and technical indicators, to ensure that all price features of each sample have zero mean and unit variance. The first feature mapping unit is used to divide the data processed by the normalization unit into multiple time blocks through a sliding window operation, and to map the time step information and price feature information of each time block to a high-dimensional space to generate an embedded representation; and to add position encoding of the same dimension to each time block to capture the relative position of each time block in the input data, thereby preserving the temporal and spatial information of the data. Global labeling unit: used to generate a learnable global label based on the time dimension of the data obtained after processing by the first feature mapping unit; and to associate the global label with... The sequences are concatenated along the time dimension to form a complete embedded feature sequence containing global labels.

7. The futures price prediction method based on time-series attention and dynamic charts of futures products according to claim 5, characterized in that: The encoder module includes: The graph construction unit is used to generate a graph adjacency matrix based on the embedding of the input futures node, describe the relationship between the futures nodes, and thus provide graph structure information for subsequent operations. The futures node refers to the price feature representation of each futures product, and the embedding of the futures node refers to the embedding initialized by the parameters of a trainable neural network. The multi-layered cascaded attention unit comprises a multi-scale feature encoding layer, a graph learning layer, and a normalization layer connected in sequence, wherein: The multi-scale feature encoding layer is used to extract long-term trend and short-term fluctuation features of the complete embedded feature sequence containing global labels: The graph learning layer first normalizes the adjacency matrix; then, it performs multiple graph convolution operations on the global labels in the output of the multi-scale temporal coding layer, and concatenates the original global labels with the convolutional global labels in the feature dimension, and performs a linear transformation on the concatenated result; finally, it updates the global labels through residual connections, and concatenates the updated global labels with the temporal block features in the output of the multi-scale temporal coding layer other than the global labels to form a complete feature sequence. The normalization layer is used to perform layer normalization processing on the data after graph learning to ensure that the feature distribution of each sample is consistent.

8. The futures price prediction method based on time-series attention and dynamic charts of futures products according to claim 7, characterized in that, Its features are: The process of generating an adjacency matrix of a graph based on the embedding of the input futures nodes, describing the relationships between futures nodes, and thus providing graph structure information for subsequent operations is as follows: A learnable futures node embedding matrix is ​​generated using trainable neural network parameters. The transformed futures node feature vector is obtained through futures node embedding. based on The similarity between futures nodes is calculated using the dot product, resulting in the adjacency matrix; If the number of futures nodes is greater than the predetermined parameter for the number of most relevant neighbors for each futures node. Then, the nearest neighbor mask method, which uses the number of most relevant neighbors as a parameter, is applied to retain the previous neighbors of each futures node. Find the maximum similarity value and set the rest to zero to obtain a sparse adjacency matrix.

9. The futures price prediction method based on time-series attention and dynamic charts of futures products according to claim 7, characterized in that: The method for extracting long-term trend and short-term fluctuation features of the complete embedded feature sequence containing global labels is as follows: Learnable positional encodings are applied to the complete embedded feature sequence to generate enhanced temporal features; In the complete embedded feature sequence after enhancing temporal features, the portion outside the global label is segmented into multiple local time windows. Information from multiple time blocks is aggregated and then concatenated with the global label to form a multi-scale price feature sequence. The query matrix is ​​obtained by performing a linear transformation on the multi-scale price feature sequence. Key matrix Sum matrix ; right , and conduct h The attention heads are divided into individual attention heads, and the features of a single attention head are calculated using a self-attention method. Multi-head attention features are then generated through a linear transformation. Will The original time block sequence structure is restored from multiple time window sequence structures, and the output of the multi-scale time coding layer is obtained by sequentially passing residual connections, convolutional layers, activation functions, and layer normalization.

10. The futures price prediction method based on time-series attention and dynamic charts of futures products according to claim 5, characterized in that, Its features are: The prediction module includes: The second feature mapping unit is used to merge the features and time dimension of the input data into a composite feature dimension, and to map the composite feature dimension to the prediction length through a linear transformation to obtain the prediction output. The denormalization unit is used to perform inverse standardization on the predicted output of the second feature mapping unit. By multiplying the predicted output by the standard deviation and adding the mean, the predicted output is restored to the same numerical scale as the original data.