Financial stock price prediction-oriented variable component calculation method and electronic device

Preprocessing and model optimization of stock price data through variational quantum computing methods solve the accuracy and computational efficiency problems of traditional prediction methods and achieve efficient and accurate stock price trend predictions.

CN118628240APending Publication Date: 2024-09-10CHINA GREATWALL TECH GRP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410662191.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-24
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

Traditional stock price prediction methods only consider the stock's own price and trading volume, resulting in inaccurate prediction results. With the large-scale growth of financial data volume, the training process of traditional machine learning methods has become difficult to calculate and prone to overfitting or underfitting. combined problem.

Method used

Using the variational quantum computing method, through high-dimensional stock price eigenfactor preprocessing, a quantum coding circuit and a parameterized quantum variation proposed circuit are built, and a variational quantum circuit model is obtained by combining the quantum coding circuit and the parameterized quantum variation proposed circuit. , perform training and parameter optimization, and optimize the model structure to improve prediction accuracy.

Benefits of technology

It achieves efficient and accurate stock price trend prediction, reduces the resource consumption of the model, and improves the ability to predict potential risks and returns in the financial market.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118628240A
    Figure CN118628240A
Patent Text Reader

Abstract

The invention provides a financial stock price prediction-oriented variable component calculation method and an electronic device. According to the method and the device, stock price data are preprocessed based on high-dimensional stock price characteristic factors, different quantum coding lines and parameterized quantum variational planned lines are constructed, and variable component sub-line models are obtained by combining the quantum coding lines and the parameterized quantum variational planned lines. According to the stock price trend prediction method based on the variable component sub-method, a prediction result of a stock price trend label is obtained by executing line end measurement on the model, line parameters are adjusted and optimized through a classical training method, the optimal structure of the model is obtained, and the efficient and accurate stock price trend prediction method based on the variable component sub-method is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of quantum computing technology, and in particular to a variational quantum computing method and electronic device for financial stock price prediction. Background Art

[0002] Stock price prediction can help investors and traders make more informed investment decisions, understand the potential risks and returns of the financial market, and develop more effective investment strategies. However, traditional prediction methods only consider factors such as the stock price and trading volume, which leads to the limitation that the prediction results are not accurate enough. With the development of artificial intelligence technology, machine learning algorithms can be used to discover patterns and rules from massive data and apply them to stock price prediction tasks. However, with the massive growth of financial data, the training process of traditional machine learning methods has become difficult to calculate, and problems such as overfitting or underfitting may occur. Therefore, how to effectively predict stock prices is an unresolved problem. Summary of the invention

[0003] The embodiments of the present application provide a variational quantum calculation method and an electronic device for financial stock price prediction.

[0004] In a first aspect, an embodiment of the present application provides a variational quantum computing method for stock price prediction, comprising:

[0005] Based on the high-dimensional stock price characteristic factor, the stock price data is preprocessed to obtain a training set and a test set. The high-dimensional stock price characteristic factor is obtained based on the characteristic index calculation of the stock price;

[0006] Use different quantum coding methods to map high-dimensional stock price characteristic factors into quantum states and build quantum coding circuits;

[0007] Constructing a parameterized quantum variational pseudo circuit, which includes a rotating gate with parameters and an entanglement gate without parameters;

[0008] Combining quantum coding circuit and parameterized quantum variational proposed circuit, we get variational quantum circuit model;

[0009] Based on the training set and the stock price trend labels, the variational quantum circuit model is trained and its parameters are optimized. The stock price trend labels are used to indicate whether the stock price is falling or rising.

[0010] Use the trained variational quantum circuit model to predict the stock price trend labels of the test set and obtain the prediction results;

[0011] The performance of the variational quantum circuit model is evaluated based on the prediction results;

[0012] Optimizing the variational quantum circuit model according to the results of the performance evaluation;

[0013] The optimized structure and parameters of the variational quantum circuit model are returned, and the variational quantum circuit model with the optimized structure has the smallest number of quantum bits and / or quantum gates.

[0014] Optionally, constructing a parameterized quantum variational proposed circuit includes:

[0015] According to the quantum coding method, determine the number of quantum bits required in the variational circuit;

[0016] Design a revolving gate layer structure of the quantum variable layer, which is based on RX(θ) gate, RY(θ) and RZ(θ) gates.

[0017] Construct the entangled gate layer organization structure of the variational quantum circuit, the entangled gate layer is based on CNOT gates and CZ gates;

[0018] Determines the depth of the variational quantum circuit.

[0019] Optionally, training and parameter optimization of the variational quantum circuit model includes:

[0020] By performing a measurement operation on the end of the variational quantum circuit, the predicted value of the stock price trend label of the training set data is obtained;

[0021] Construct a loss function, which is a function of the stock price trend label;

[0022] Design an optimization algorithm for the loss function;

[0023] According to the optimization algorithm, the variational quantum circuit model is iterated cyclically until the loss function reaches the convergence condition or the maximum number of iterations is reached, and the optimal model parameters are obtained.

[0024] Optionally, the stock price trend label is determined based on the relationship between the stock's closing price on the next day and the closing price on the current day.

[0025] Optionally, the high-dimensional stock price feature factor is a 15-dimensional feature factor.

[0026] Optionally, the quantum encoding method is as follows:

[0027] Amplitude coding;

[0028] Universal instantaneous quantum polynomial IQP coding;

[0029] Rotation angle encoding.

[0030] Optionally, stock price data is obtained based on the stock daily K-line of the securities market.

[0031] In a second aspect, an embodiment of the present application provides an electronic device, including:

[0032] A preprocessing module is used to preprocess the stock price data based on a high-dimensional stock price characteristic factor to obtain a training set and a test set. The high-dimensional stock price characteristic factor is obtained based on the characteristic index calculation of the stock price;

[0033] The mapping module is used to map high-dimensional stock price characteristic factors into quantum states using different quantum coding methods to build quantum coding circuits;

[0034] A construction module, used to construct a parameterized quantum variational pseudo circuit, wherein the parameterized quantum variational pseudo circuit includes a rotation gate with parameters and an entanglement gate without parameters;

[0035] A combination module is used to combine the quantum coding circuit and the parameterized quantum variational proposed circuit to obtain a variational quantum circuit model;

[0036] A training module, used to train and optimize parameters of the variational quantum circuit model based on a training set and a stock price trend label, where the stock price trend label is used to indicate whether the stock price is falling or rising;

[0037] The prediction module is used to predict the stock price trend labels of the test set using the trained variational quantum circuit model to obtain the prediction results;

[0038] An evaluation module, used for evaluating the performance of the variational quantum circuit model according to the prediction results;

[0039] An optimization module, used for optimizing the variational quantum circuit model according to the result of performance evaluation;

[0040] The return module is used to return the optimized structure and parameters of the variational quantum circuit model, and the variational quantum circuit model with the optimized structure has the smallest number of quantum bits and / or quantum gates.

[0041] Optionally, building blocks include:

[0042] A first determination module is used to determine the number of quantum bits required in the variational circuit according to the quantum coding method;

[0043] A design module is used to design the revolving gate layer structure of the quantum variable layer. The revolving gate layer structure is based on the RX(θ) gate, RY(θ) and RZ(θ) gates.

[0044] Construction module, used to construct the entangled gate layer organization structure of the variational quantum circuit. The entangled gate layer is based on CNOT gates and CZ gates.

[0045] The second determination module is used to determine the depth layer number of the variational quantum circuit.

[0046] Optional training modules include:

[0047] A measurement module, used for obtaining a predicted value of a stock price trend label of training set data by performing a measurement operation on an end of a variational quantum circuit;

[0048] The loss function building module is used to build a loss function, which is a function of the stock price trend label;

[0049] Loss function optimization module, used to design the optimization algorithm of loss function;

[0050] The iteration module is used to iterate the variational quantum circuit model according to the optimization algorithm until the loss function reaches a convergence condition or reaches a maximum number of iterations, thereby obtaining the optimal model parameters.

[0051] Optionally, the stock price trend label is determined based on the relationship between the stock's closing price on the next day and the closing price on the current day.

[0052] Optionally, the high-dimensional stock price feature factor is a 15-dimensional feature factor.

[0053] Optionally, the quantum coding method is as follows: amplitude coding; universal instantaneous quantum polynomial IQP coding; rotation angle coding.

[0054] Optionally, stock price data is obtained based on the stock daily K-line of the securities market.

[0055] In a third aspect, an embodiment of the present application provides an electronic device comprising a memory, at least one processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, a method as described in any one of the above-mentioned first aspects is implemented.

[0056] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method as described in any one of the above-mentioned first aspects is implemented.

[0057] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes any one of the methods described in the first aspect.

[0058] In this application, based on high-dimensional stock price characteristic factors, the stock price data is preprocessed, different quantum coding circuits and parameterized quantum variational pseudo-circuits are constructed, and the variational quantum circuit model is obtained by combining the quantum coding circuit and the parameterized quantum variational pseudo-circuits. The prediction result of the stock price trend label is obtained by performing circuit end measurement on the model, and the circuit parameters are adjusted and optimized by classical training methods to obtain the optimized structure of the model, thereby realizing an efficient and accurate stock price trend prediction method based on the variational quantum method. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for describing the embodiments are briefly introduced below.

[0060] Figure 1 It is a flow chart of a variational quantum calculation method for financial stock price prediction provided in an embodiment of the present application.

[0061] Figure 2 This is an example diagram of a variational quantum calculation method for financial stock price prediction provided in an embodiment of the present application.

[0062] Figure 3 It is a schematic diagram of the structure of the amplitude coded quantum circuit provided in the embodiment of the present application.

[0063] Figure 4 It is a schematic diagram of the structure of the IQP coded quantum circuit provided in an embodiment of the present application.

[0064] Figure 5 It is a schematic diagram of the structure of the rotation angle ZYZ encoding quantum circuit provided in an embodiment of the present application.

[0065] Figures 6A to 6E It is a schematic diagram of the structure of the revolving door layer array provided in an embodiment of the present application.

[0066] Figures 7A-7B It is a structural schematic diagram of the entanglement gate arrangement provided in an embodiment of the present application.

[0067] Figure 8 It is a schematic diagram of the structure of a variational quantum circuit provided in an embodiment of the present application.

[0068] Fig. 9 It is a schematic diagram of the structure of an electronic device provided in one embodiment of the present application.

[0069] Fig.10 It is a structural schematic diagram of an electronic device provided in another embodiment of the present application. DETAILED DESCRIPTION

[0070] The technical solution of the embodiment of the present invention will be described below in conjunction with the accompanying drawings in the embodiment of the present invention.

[0071] Stock price trend forecasting can help investors and traders make more informed investment decisions, understand the potential risks and returns of the financial market, and develop more effective investment strategies. Traditional quantitative mathematical modeling methods provide simple and intuitive solutions for stock price forecasting, such as moving average, linear regression, relative strength index and other models. However, traditional methods only consider factors such as the stock price and trading volume, resulting in inaccurate prediction results. With the development of artificial intelligence technology, machine learning algorithms are used to discover patterns and rules from massive data and apply them to stock price prediction tasks. However, with the massive growth of financial data, the training process of traditional machine learning methods has become difficult to calculate, and problems such as overfitting or underfitting may occur.

[0072] Quantum computing, which is completely different from the classical computing paradigm, provides new solutions and innovative research methods for complex and difficult problems in the field of financial technology, and has attracted more and more attention from researchers and the market. Variational quantum algorithms combine the advantages of classical optimization algorithms with quantum computing, use the parallel computing capabilities of quantum bits, and train and optimize circuit parameters through machine learning methods, playing an increasingly important role in solving practical problems.

[0073] Based on this, Figure 1 As shown, an embodiment of the present application provides a variational quantum calculation method for financial stock price prediction, which may include steps S110-S190.

[0074] In step S110, based on the high-dimensional stock price characteristic factor, the stock price data is preprocessed to obtain a training set and a test set. The high-dimensional stock price characteristic factor can be obtained based on the characteristic index calculation of the stock price. The stock price data can be a certain amount of stock market data, which is not specifically limited. Optionally, the stock price data can be obtained based on the stock daily K-line of the securities market, which is more convenient. For example, as shown in Table 1, the stock daily K-line data includes 5 basic characteristic quantity indicators.

[0075] Table 1 Stock price daily K-line data

[0076] Opening Price Highest price of the day Lowest price of the day Closing Price Total Transaction Volume 30.57 30.57 28.63 28.78 70997200 28.41 29.54 28.23 29.23 87498540 29.03 29.39 28.73 29.26 48012112 28.73 29.25 27.73 28.50 23647604 28.73 29.18 27.63 28.67 98239664

[0077] The characteristic index of stock price can be the basic characteristic quantity index of stock price data, such as opening price (open), highest price of the day (high), lowest price of the day (low), closing price (close), total volume of transactions (volume), etc. Different characteristic factors can be obtained by performing different operations on the characteristic indexes of different stock prices. For example, the rise and fall of the stock can be obtained as the stock price characteristic factor by (closing price - opening price) / opening price × 100%. For another example, the daily oscillation amplitude can be obtained as the stock price characteristic factor by the highest price of the day - the lowest price of the day. High-dimensional stock price characteristic factors can include multiple stock price characteristic factors, and the specific number is not limited.

[0078] Optionally, the high-dimensional stock price characteristic factor may be a 15-dimensional characteristic factor. For example, the high-dimensional stock price characteristic factor may include the stock's rise or fall, daily fluctuation amplitude, consecutive rising days, consecutive falling days, volume ratio, average price, price change rate, 2-day price change rate, 3-day price change rate, 5-day price change rate, etc. Among them, the number of consecutive rising days refers to the number of days with consecutive closing prices higher than the closing price of the previous day, and the number of consecutive falling days refers to the number of days with consecutive closing prices lower than the closing price of the previous day. The volume ratio can be obtained by dividing the trading volume of the day by the trading volume of the previous day, the average price can be obtained by (opening price + highest price + lowest price + closing price) / 4, the price change rate can be obtained by (closing price of the day - closing price of the previous day) / closing price of the previous day, the 2-day price change rate can be obtained by (closing price of the day - closing price of the previous 2 days) / closing price of the previous 2 days, the 3-day price change rate can be obtained by (closing price of the day - closing price of the previous 3 days) / closing price of the previous 3 days, and the 5-day price change rate can be obtained by (closing price of the day - closing price of the previous 5 days) / closing price of the previous 5 days.

[0079] Preprocessing of stock price data based on high-dimensional stock price characteristic factors can refer to calculating the high-dimensional stock price characteristic data corresponding to the stock price data. For example, for the several groups of data shown in Table 1, the corresponding increase or decrease, daily fluctuation amplitude, etc. of each group of data are calculated to form high-dimensional stock price characteristic data. Furthermore, the stock price data can be divided into a training set and a test set, and the proportion of the two parts is not limited, for example, the two parts account for 80% and 20% respectively. The training set can be used for model training and tuning, and the test set can be used to evaluate the training effect of the model.

[0080] In step S120, different quantum coding methods are used to map high-dimensional stock price characteristic factors into quantum states, and quantum coding circuits are constructed. The quantum coding circuit can map classical data into quantum states and quantum circuits according to a specific coding method, so as to use quantum algorithms to process tasks. There are many different coding methods that can realize the mapping of high-dimensional stock price characteristic factors, and different methods can be used for mapping, which helps to select the optimal coding method according to model performance. Optionally, the quantum coding method may include one or more of the following: amplitude coding; universal instantaneous quantum polynomial encoding (IQP) encoding; rotation angle encoding (taking rotation angle ZYZ encoding as an example). Among them, amplitude coding can use the amplitude of quantum bits to represent classical data. Universal IQP coding can complete the characteristic mapping of classical data by using a quantum coding circuit composed of a group of single-qubit H gates and a group of controlled Pauli Z rotation gates and CNOT gates. The IQP coding method uses a small number of quantum gates, so it is easy to implement on current quantum computers, and compared with other data coding methods, IQP coding has stronger interpretability. Rotation angle encoding can use the phase rotation angle of quantum bits to encode the information of input data.

[0081] In step S130, a parameterized quantum variational pseudo circuit (ansatz) is constructed. The parameterized quantum variational pseudo circuit may include a rotation gate with parameters and an entanglement gate without parameters; the quantum variational circuit usually contains a quantum gate circuit structure with parameters, so that it can be used to solve optimization problems and machine learning tasks. Unlike traditional quantum algorithms, the logic gate operation in the variational quantum circuit is controlled by adjustable parameters, which allows the circuit to flexibly adapt to different types of problems. The rotation gate with parameters in the parameterized quantum variational pseudo circuit can introduce parameter angle rotation operations on the quantum bit, change the superposition state and relative phase of the quantum bit, and achieve precise control of the circuit behavior. The entanglement gate without parameters in the parameterized quantum variational pseudo circuit can establish an entanglement relationship between multiple quantum bits, realizing the advantages of quantum parallelism and quantum computing. The specific types of the rotation gate with parameters and the entanglement gate without parameters are not limited. For example, the rotation gate with parameters can be RX, RY, RZ gates, and the entanglement gate without parameters can be CNOT, CZ gates.

[0082] Optionally, constructing a parameterized quantum variational hypothetical circuit may include steps S131-S134.

[0083] In step S131, the number of quantum bits required in the variational circuit is determined according to the quantum coding method. When the quantum coding method is different, the number of quantum bits required in the variational circuit is different.

[0084] In step S132, a revolving gate layer structure of the quantum variation layer is designed, and the revolving gate layer structure is based on RX(θ) gate, RY(θ) and RZ(θ) gate. The variation layer with trainable parameters in the quantum variation circuit is mainly composed of revolving gates that rotate around the coordinate axes on the Bloch sphere in the Hilbert space. Among them, the counterclockwise rotation of θ around the X-axis can be achieved by the RX(θ) gate, and its matrix form can be expressed as a 2×2 square matrix, as shown in the following formula:

[0085]

[0086] The RY(θ) gate can rotate the quantum state around the Y axis of the Bloch sphere by an angle of θ. The matrix is ​​represented as:

[0087]

[0088] The effect of the RZ(θ) gate is to rotate the quantum state around the Z axis by an angle of θ. The matrix form of the gate is:

[0089]

[0090] By alternately arranging arrays of RX(θ) gates, RY(θ) gates and RZ(θ) gates, a rotation gate array layer of a quantum variable layer can be formed, and the array composition form is not limited.

[0091] In step S133, an entanglement gate layer organization structure of a variational quantum circuit is constructed. The entanglement gate layer can be composed of CNOT gates and CZ gates. The entanglement operation between multiple quantum bits can enhance the connection between quantum bits and circuits through interaction. The matrix expressions of CNOT gates and CZ gates are:

[0092]

[0093]

[0094] Optionally, the arrangement of the entanglement gates is selected to be fully connected.

[0095] In step S134, the depth of the variational quantum circuit is determined. The rotation gate layer structure and the entanglement gate layer organization structure are arranged alternately to obtain a basic layer of the variational quantum circuit. The depth of the entire circuit can be selected according to the scale of the problem, that is, the number of times the variational basic layer is repeated. For example, the depth of the variational quantum circuit can be 3.

[0096] Continue to see Figure 1In step S140, the quantum coding circuit and the parameterized quantum variational pseudo circuit are combined to obtain a variational quantum circuit model. By embedding the high-dimensional stock price characteristic factors into the quantum circuit through the coding circuit layer, the classical data can be quantized, and the quantum variational pseudo circuit containing parameters can realize the variational evolution of the quantum circuit.

[0097] In step S150, the variational quantum circuit model is trained and parameter optimized based on the training set and the stock price trend label, and the stock price trend label is used to indicate whether the stock price falls or rises. As an example, when the value of the stock price trend label is equal to 1, it represents a rise in the stock price, and when the value of the stock price trend label is equal to 0, it represents a fall in the stock price or remains unchanged. The change in stock price can be determined based on the size relationship between the stock prices of two consecutive days. When the price of the next day is greater than the price of the day, it is an increase, otherwise it is a decrease. For example, the price of a stock can be determined based on the basic characteristic quantity index of the stock. Optionally, the stock price trend label can be determined based on the size relationship between the closing price of the stock the day after and the closing price of the day, which helps to efficiently calculate the stock price trend label. That is, when the closing price of the next day is greater than the closing price of the day, the price trend label represents an increase; when the closing price of the next day is less than or equal to the closing price of the day, the price trend label represents a decrease.

[0098] Optionally, training and parameter optimization of the variational quantum circuit model may include steps S151 - S154 .

[0099] In step S151, by performing a measurement operation on the end of the variational quantum circuit, the predicted value of the stock price trend label of the training set data is obtained. For example, the Pauli Z-basis measurement can be performed on the highest qubit and the lowest qubit of the variational quantum circuit. When the expected value of the measurement result of the highest qubit is greater than the expected value of the measurement result of the lowest qubit, it is predicted that the price will rise; when the expected value of the measurement result of the highest qubit is less than or equal to the expected value of the measurement result of the lowest qubit, it is predicted that the price will fall.

[0100] In step S152, a loss function is constructed, which is a function of the stock price trend label. The core of training a variational quantum circuit model is to construct a suitable loss function, so as to measure the difference between the model prediction results and the actual results, and then guide the optimization and adjustment of the model parameters. For example, the loss function can be a cross entropy loss function.

[0101] In step S153, an optimization algorithm for the loss function is designed. The optimization algorithm can be used to find the optimal parameters of the variational quantum circuit model to minimize the loss function. Optionally, a gradient descent method can be used to minimize the loss function, and the parameters of the circuit model can be updated in an iterative manner.

[0102] In step S154, according to the optimization algorithm, the variational quantum circuit model is iterated cyclically until the loss function reaches the convergence condition or reaches the maximum number of iterations, and the optimal model parameters are obtained. The parameters can be updated in the opposite direction of the gradient according to the derivative (i.e., gradient) of the loss function with respect to the parameters, until the convergence condition (e.g., the model reaches a given accuracy) or the maximum number of iterations is reached, and the training process of the variational quantum circuit is completed, and the optimal model parameters are obtained, so that the output of the circuit can obtain the solution to the stock price prediction problem.

[0103] Continue to see Figure 1 , in step S160, the trained variational quantum circuit model is used to predict the stock price trend label of the test set to obtain a prediction result.

[0104] In step S170, the performance of the variational quantum circuit model is evaluated based on the prediction results. For example, the prediction results can be compared with the actual rise and fall index results of the test set, and the accuracy rate, that is, the ratio between the number of correctly predicted samples and the total number of samples, can be calculated to measure the performance of the variational quantum circuit in the stock price trend prediction task.

[0105] In step S180, the variational quantum circuit model is optimized according to the results of the performance evaluation. For example, the parameter structure of the variational quantum circuit model can be adjusted and optimized according to the results of the performance evaluation to improve the performance of the model. Adjusting hyperparameters such as the learning rate, the number of variational circuit layers, and the number of quantum gates can find a better circuit model, increase the sample size of feature data to improve the generalization ability and robustness of the circuit model, and improve the overall performance of the stock price prediction method based on the variational quantum circuit.

[0106] In step S190, the optimized structure and parameters of the variational quantum circuit model are returned, and the variational quantum circuit model with the optimized structure has the smallest number of quantum bits and / or quantum gates. By comparing the variational quantum circuit models obtained by different optimized encoding methods, the circuit model with the smallest number of quantum bits and / or quantum gates can be selected as the optimized structure to predict the financial stock price trend, which helps to reduce resource consumption in the model prediction process.

[0107] In this application, based on high-dimensional stock price characteristic factors, the stock price data is preprocessed, different quantum coding circuits and parameterized quantum variational pseudo-circuits are constructed, and the variational quantum circuit model is obtained by combining the quantum coding circuit and the parameterized quantum variational pseudo-circuits. The prediction result of the stock price trend label is obtained by performing circuit end measurement on the model, and the circuit parameters are adjusted and optimized by classical training methods to obtain the optimized structure of the model, thereby realizing an efficient and accurate stock price trend prediction method based on the variational quantum method.

[0108] Combine the following Figure 2-Figure 8 , the variational quantum calculation method for financial stock price prediction in the embodiment of the present application is introduced by way of example, Figure 2 It is a simplified flow chart of the method. As an example, the stock price data of the stock daily K-line in the securities market for the past 500 days are selected as the stock price data set.

[0109] 1. Stock price data preprocessing.

[0110] In order to better process and predict the data, the five basic characteristic indicators of stock prices (opening price, daily highest price, daily lowest price, closing price and total trading volume) are calculated to obtain a 15-dimensional stock price characteristic factor These include the stock's rise and fall, daily fluctuation amplitude, consecutive rising days, consecutive falling days, volume ratio, average price, price change rate, 2-day price change rate, 3-day price change rate, 5-day price change rate, etc. Based on the 15-dimensional stock price feature factor C, the high-dimensional stock price feature data of the stock price data set can be calculated.

[0111] Furthermore, the processed stock price data set is divided into 80% (i.e., the data of the first 400 days) as a training set for parameter training and optimization of the variational quantum circuit, and the remaining 20% ​​(i.e., the data of the last 100 days) as a test data set for evaluating the training effect.

[0112] In addition, the stock price trend label y to be predicted can be set according to the stock closing price. When the closing price of the next day is greater than the closing price of the current day, that is, close[k+1]>close[k], the price trend label y {k} =1 represents an increase; when the closing price of the next day is less than or equal to the closing price of the day, that is, close[k+1≤close[k]], the price trend label y{k}=0 represents a decrease.

[0113] 2. Use quantum coding to map classical stock price data (i.e., 15-dimensional stock price characteristic factor X) into quantum states and build quantum coding circuits. There are many ways to achieve this mapping, which facilitates the subsequent optimization and selection of the best circuit structure.

[0114] ① Amplitude encoding: The characteristic factors in the stock price data set are normalized by squares to meet the amplitude requirements of the quantum state. For the 15-dimensional stock price characteristic factor X, 4 quantum bits are required to encode it. After encoding, the amplitude before each base state represents the classical feature, as shown in the following formula:

[0115]

[0116] The amplitude-encoded circuit consists of a controlled rotating Pauli Y gate and a Pauli X gate, which can be Figure 3 As shown in the figure, for the 15-dimensional stock price feature factor X of the stock price dataset, encoding it using an amplitude coding circuit to embed it into the quantum state requires a total of 4 quantum bits and 49 quantum gates, including 15 parameter gates, which are used to encode the 15 feature factors.

[0117] ② General IQP coding: For the 15-dimensional stock price feature factor X of the stock price data set, 8 quantum bits are required to encode. The IQP coding circuit can be as follows Figure 4 The entire IQP coding circuit contains 37 quantum gates, including 15 parameterized RZ gates, which are used to encode 15 characteristic factors.

[0118] ③ Rotation angle ZYZ encoding: The quantum circuit of rotation angle ZYZ encoding is composed of H gates, rotation Pauli Z gates and rotation Pauli Y gates arranged in a cross pattern. By embedding the 15-dimensional stock price feature factor X of the stock price data set into the rotation angle parameter of the rotation Pauli gate, the encoded quantum circuit can be obtained. In this rotation angle encoding scheme, a total of 5 quantum bits are required to encode 15 feature factors, which can be Figure 5 The entire rotation angle encoding circuit contains 20 quantum gates, including 5 H gates, 15 parameterized rotation Pauli Z gates and rotation Pauli Y gates, which are used to encode the 15-dimensional stock price feature factor X in the stock price dataset into the quantum circuit.

[0119] 3. Construct a parameterized quantum variational ansatz circuit and determine the circuit structure and the type of entanglement gate layer.

[0120] ① Determine the number of quantum bits required in the variational circuit: When amplitude coding is selected in the quantum coding circuit to embed the 15-dimensional stock price characteristic factor X into the quantum circuit, the variational circuit contains 4 quantum bits; when universal IQP is selected to encode the 15-dimensional stock price characteristic factor X, the number of quantum bits in the variational circuit is 8; when the 15-dimensional stock price characteristic factor X is encoded into the quantum circuit in the form of rotation angle encoding, the number of quantum bits in the variational circuit is 5.

[0121] ② Design the rotating gate layer structure of the quantum variational layer: The variational layer with trainable parameters in the quantum variational circuit is mainly composed of rotating gates that rotate around the coordinate axes on the Bloch sphere in the Hilbert space. The rotating gates of the X, Y, and Z axes can be implemented by RX(θ) gates, RY(θ) gates, and RZ(θ) gates, respectively. Their matrices are shown in equations (1), (2), and (3) above. The rotating gate array layer of the quantum variational layer is formed by alternating arrays of RX(θ) gates, RY(θ) gates, and RZ(θ) gates. As an example, the array structures of XY, XZ, YZ, XYZ, and ZYZ type variational ansatz structures can be as follows: Figures 6A to 6E shown.

[0122] ③ Construct the entanglement gate layer organization structure of the variational quantum circuit: The entanglement gate can be selected as a CNOT gate and a CZ gate, and their matrix expressions are shown in the above equations (4) and (5) respectively. The arrangement of the entanglement gates is selected as a fully connected type, for example Fig. 7A and Figure 7B shown.

[0123] ④ Determine the depth of the variational quantum circuit: The depth of the entire circuit can be selected according to the scale of the problem, for example Figure 8 The variational quantum circuit shown has a depth of 3.

[0124] 4. Construct a complete quantum circuit model.

[0125] The encoding circuit and the parametric variational ansatz circuit designed in the above steps 2 and 3 are combined to obtain a complete quantum circuit model.

[0126] 5. Train and optimize the parameters of the quantum circuit model. Use the characteristic data in the training set to complete the parameter training and optimization process of the variational quantum circuit model step by step to obtain the optimal parameters.

[0127] ① The predicted value of the data is obtained by performing a measurement operation on the end of the line: Pauli Z-basis measurement is performed on the highest qubit and the lowest qubit. When the expected value of the measurement result of the highest qubit is greater than the expected value of the measurement result of the lowest qubit, the prediction is that the price will rise. When the expected value of the highest measurement result is less than or equal to the expected value of the lowest measurement result, the prediction is that the price will fall.

[0128] ②Construct loss function: Select the cross entropy loss function, and its calculation method is shown in the following formula.

[0129]

[0130] Among them, y is the rise and fall category label (0 or 1) of the actual stock price data, It is the predicted probability value obtained after the line model is processed by the flexible maximum transfer function softmax.

[0131] ③ Design optimization algorithm: Use gradient descent method to minimize the loss function, update the parameters of the circuit model in an iterative manner, and update the parameters in the opposite direction of the gradient according to the derivative of the loss function to the parameter (i.e., gradient) until the convergence condition is reached or the maximum number of iterations is reached. The following formula is used to calculate the quantum circuit gradient:

[0132]

[0133] The line parameters are updated as follows:

[0134]

[0135] Among them, θ t represents the variational ansatz parameter in the line model, Loss(θ t ) is the loss function, It represents the derivative of the loss function with respect to the parameters, i.e., the gradient, and α is the learning rate, which is used to adjust the step size of each update.

[0136] ④ Iterate the loop to complete the training: The parameters are continuously updated iteratively until the given accuracy is reached, or the specified maximum number of cycles is reached. This completes the training process of the variational quantum circuit and obtains the optimal model parameters, so that the output of the circuit can be used to obtain the solution to the stock price prediction problem.

[0137] 5. Use the trained variational quantum circuit model to predict the sample data in the test set and obtain the prediction results.

[0138] 6. Based on the prediction results in the previous step, calculate the evaluation index to measure the performance of the line model.

[0139] We compare the prediction results obtained in step 5 with the actual rise and fall indicator results of the test set, and calculate the accuracy, that is, the ratio between the number of correctly predicted samples and the total number of samples, to measure the performance of the variational quantum circuit in the stock price trend prediction task.

[0140] 7. According to the results of the evaluation indicators, the variational quantum circuit model is adjusted and optimized.

[0141] According to the results of the model performance analysis in step 6, we adjust and optimize the parameter structure of the variational quantum circuit model to improve the performance of the model. We adjust the learning rate, the number of variational circuit layers, the number of quantum gates and other hyperparameters to find a better circuit model, increase the sample size of feature data to improve the generalization ability and robustness of the circuit model, and improve the performance of the stock price prediction method based on variational quantum circuits as a whole.

[0142] 8. Return the circuit optimization structure and parameters to obtain the variational quantum circuit and method for financial stock price trend prediction.

[0143] Furthermore, by comparing the variational quantum circuit models obtained by optimizing different encoding methods, the circuit model with the smallest number of quantum bits and / or quantum gates can be selected as the optimized structure to predict financial stock price trends, which helps to reduce resource consumption in the model prediction process.

[0144] In this method, different quantum coding circuits and variational ansatz circuits are constructed, and the circuit parameters are trained and optimized to minimize the number of quantum bits and quantum gates, so as to achieve efficient prediction of stock price trends. The variational quantum computing method is used to directly solve difficult and complex problems in the field of financial technology, which further demonstrates the advantages of quantum methods in solving practical problems.

[0145] The method provided in the embodiment of the present application is described in detail above. The device provided in the embodiment of the present application is described in detail below with reference to the accompanying drawings.

[0146] See also Fig. 9 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig. 9 The electronic device 900 shown may include a preprocessing module 910 , a mapping module 920 , a construction module 930 , a combination module 940 , a training module 950 , a prediction module 960 , an evaluation module 970 , an optimization module 980 and a return module 990 .

[0147] The preprocessing module 910 is used to preprocess the stock price data based on the high-dimensional stock price characteristic factor to obtain a training set and a test set. The high-dimensional stock price characteristic factor is obtained based on the characteristic index calculation of the stock price.

[0148] The mapping module 920 is used to map high-dimensional stock price characteristic factors into quantum states using different quantum coding methods to build a quantum coding circuit;

[0149] The construction module 930 is used to construct a parameterized quantum variational pseudo circuit, where the parameterized quantum variational pseudo circuit includes a rotation gate with parameters and an entanglement gate without parameters;

[0150] The combination module 940 is used to combine the quantum coding circuit and the parameterized quantum variational proposed circuit to obtain a variational quantum circuit model;

[0151] The training module 950 is used to train and optimize parameters of the variational quantum circuit model based on the training set and the stock price trend label, and the stock price trend label is used to indicate whether the stock price falls or rises;

[0152] The prediction module 960 is used to predict the stock price trend label of the test set using the trained variational quantum circuit model to obtain a prediction result;

[0153] The evaluation module 970 is used to perform performance evaluation on the variational quantum circuit model according to the prediction results;

[0154] The optimization module 980 is used to optimize the variational quantum circuit model according to the result of the performance evaluation;

[0155] The return module 990 is used to return the optimized structure and parameters of the variational quantum circuit model. The variational quantum circuit model with the optimized structure has the smallest number of quantum bits and / or quantum gates.

[0156] Optionally, the building block 930 includes:

[0157] A first determination module 931 is used to determine the number of quantum bits required in the variational circuit according to the quantum coding method;

[0158] A design module 932 is used to design a revolving gate layer structure of a quantum variable layer, wherein the revolving gate layer structure is based on an RX(θ) gate, an RY(θ) gate, and an RZ(θ) gate;

[0159] A construction module 933 is used to construct an entanglement gate layer organization structure of a variational quantum circuit, where the entanglement gate layer is based on a CNOT gate and a CZ gate;

[0160] The second determination module 934 is used to determine the depth level of the variational quantum circuit.

[0161] Optionally, the training module 950 includes:

[0162] A measurement module 951 is used to obtain a predicted value of a stock price trend label of the training set data by performing a measurement operation on the end of the variational quantum circuit;

[0163] A loss function construction module 952 is used to construct a loss function, where the loss function is a function of the stock price trend label;

[0164] A loss function optimization module 953, used to design an optimization algorithm for the loss function;

[0165] The iteration module 954 is used to iterate the variational quantum circuit model according to the optimization algorithm until the loss function reaches a convergence condition or reaches a maximum number of iterations, thereby obtaining optimal model parameters.

[0166] Optionally, the stock price trend label is determined based on the relationship between the stock's closing price on the next day and the closing price on the current day.

[0167] Optionally, the high-dimensional stock price feature factor is a 15-dimensional feature factor.

[0168] Optionally, the quantum coding method is as follows: amplitude coding; universal instantaneous quantum polynomial IQP coding; rotation angle coding.

[0169] Optionally, stock price data is obtained based on the stock daily K-line of the securities market.

[0170] The present application also provides an electronic device. Fig.10 As shown, the electronic device 1000 includes: at least one processor 1001, a memory 1002, and a computer program 1003 stored in the memory 1002 and executable on the at least one processor 1001. When the processor 1001 executes the computer program 1003, the channel selection method provided in the present application is implemented.

[0171] Exemplarily, the computer program 1003 may be divided into one or more modules / units, one or more modules / units are stored in the memory 1002, and are executed by the processor 1001 to complete the present application. One or more modules / units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program in the electronic device 1000.

[0172] Those skilled in the art will understand that Fig.10 It is only an example of the electronic device 1000 and does not constitute a limitation of the electronic device. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device 1000 may also include input and output devices, network access devices, buses, etc.

[0173] The processor 1001 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.

[0174] The memory 1002 may be an internal storage unit of the electronic device 1000, such as a hard disk or memory of the electronic device 1000. The memory 1002 may also be an external storage device of the electronic device 1000, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 1000. Further, the memory 1002 may also include both an internal storage unit of the electronic device 1000 and an external storage device. The memory 1002 is used to store computer programs and other programs and data required by the electronic device 1000. The memory 1002 may also be used to temporarily store data that has been output or is to be output.

[0175] The electronic device 1000 provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.

[0176] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.

[0177] An embodiment of the present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device can implement the steps in the above-mentioned method embodiments when executing the computer program product.

[0178] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above method embodiments, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above method embodiments can be implemented. Among them, the computer program includes computer program code, which can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the camera / electronic device, recording medium, computer memory, ROM (read-only memory), RAM (random access memory), CD-ROM (compact disc read-only memory), magnetic tape, floppy disk and optical data storage device. The computer-readable storage medium mentioned in the present application can be a non-volatile storage medium, in other words, a non-transient storage medium.

[0179] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0180] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0181] In the embodiments provided in the present application, it should be understood that the disclosed devices / equipment and methods can be implemented in other ways. For example, the device / equipment embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0182] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0183] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0184] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0185] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0186] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A variational quantum computing method for stock price prediction, characterized in that: include: Preprocessing the stock price data based on high-dimensional stock price characteristic factors to obtain a training set and a test set, wherein the high-dimensional stock price characteristic factors are obtained based on characteristic index calculations of the stock price; Using different quantum coding methods to map the high-dimensional stock price characteristic factors into quantum states, and building quantum coding circuits; Constructing a parameterized quantum variational pseudo-circuit, wherein the parameterized quantum variational pseudo-circuit includes a rotation gate with parameters and an entanglement gate without parameters; Combining the quantum coding circuit and the parameterized quantum variational hypothetical circuit to obtain a variational quantum circuit model; Training and optimizing parameters of the variational quantum circuit model based on the training set and the stock price trend label, wherein the stock price trend label is used to indicate whether the stock price is falling or rising; Using the trained variational quantum circuit model to predict the stock price trend label of the test set, to obtain a prediction result; Performing performance evaluation on the variational quantum circuit model according to the prediction result; Optimizing the variational quantum circuit model according to the result of the performance evaluation; The optimized structure and parameters of the variational quantum circuit model are returned, wherein the variational quantum circuit model of the optimized structure has the smallest number of quantum bits and / or quantum gates.

2. The method according to claim 1, characterized in that The construction of the parameterized quantum variational proposed circuit includes: According to the quantum coding method, determining the number of quantum bits required in the variational circuit; Designing a revolving gate layer structure of a quantum variable layer, wherein the revolving gate layer structure is based on RX(θ) gate, RY(θ) and RZ(θ) gate; Constructing an entangled gate layer organization structure of a variational quantum circuit, wherein the entangled gate layer is based on a CNOT gate and a CZ gate; Determines the depth of the variational quantum circuit.

3. The method according to claim 2, characterized in that The training and parameter optimization of the variational quantum circuit model includes: By performing a measurement operation on the end of the variational quantum circuit, a predicted value of the stock price trend label of the training set data is obtained; Constructing a loss function, wherein the loss function is a function of the stock price trend label; Designing an optimization algorithm for the loss function; According to the optimization algorithm, the variational quantum circuit model is iterated cyclically until the loss function reaches a convergence condition or a maximum number of iterations is reached, thereby obtaining optimal model parameters.

4. The method according to claim 3, characterized in that: The stock price trend label is determined based on the relationship between the stock's closing price on the next day and the closing price on the current day.

5. The method according to claim 4, characterized in that The high-dimensional stock price characteristic factor is a 15-dimensional characteristic factor.

6. The method according to claim 5, characterized in that The quantum encoding method includes one or more of the following: Amplitude coding; Universal instantaneous quantum polynomial IQP coding; Rotation angle encoding.

7. The method according to claim 6, characterized in that The stock price data is obtained based on the daily K-line of the stock in the securities market.

8. An electronic device, characterized in that: include: A preprocessing module, used to preprocess the stock price data based on a high-dimensional stock price characteristic factor to obtain a training set and a test set, wherein the high-dimensional stock price characteristic factor is obtained by calculating the characteristic index of the stock price; A mapping module, used to map the high-dimensional stock price characteristic factor into a quantum state using different quantum coding methods to build a quantum coding circuit; A construction module, used to construct a parameterized quantum variational pseudo-circuit, wherein the parameterized quantum variational pseudo-circuit includes a rotation gate with parameters and an entanglement gate without parameters; A combination module, used for combining the quantum coding circuit and the parameterized quantum variational assumed circuit to obtain a variational quantum circuit model; A training module, for training and optimizing parameters of the variational quantum circuit model based on the training set and a stock price trend label, wherein the stock price trend label is used to indicate whether the stock price is falling or rising; A prediction module, used to predict the stock price trend label of the test set using the trained variational quantum circuit model to obtain a prediction result; An evaluation module, used for performing performance evaluation on the variational quantum circuit model according to the prediction result; An optimization module, used for optimizing the variational quantum circuit model according to the result of the performance evaluation; The return module is used to return the optimized structure and parameters of the variational quantum circuit model, wherein the variational quantum circuit model of the optimized structure has the smallest number of quantum bits and / or quantum gates.

9. An electronic device comprising a memory, at least one processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.