Asset price prediction method and device and electronic equipment
By acquiring characteristic information of target assets over multiple time periods and using the Transformer model to predict asset price growth rates, the limitations of single-point prediction in existing technologies are overcome, achieving more accurate and robust market analysis.
Patent Information
- Application Number
- CN202511639902.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-10
- Publication Date
- 2026-03-10
AI Technical Summary
Existing technologies for asset price forecasting typically limit predictions to a single point in time, resulting in limited assistance for market analysis.
By acquiring the characteristic information of the target asset over multiple consecutive preset time periods, a first input sequence and a second input sequence are determined, and the Transformer model or its variant model is used for prediction to obtain the asset price growth rate for multiple prediction time periods.
It provides richer market analysis data, improves the accuracy and robustness of asset price forecasts, and solves the time series dependency problem caused by series non-stationarity.
Smart Images

Figure CN121639348A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of price forecasting technology, and in particular to an asset price forecasting method, apparatus and electronic equipment. Background Technology
[0002] Asset price forecasting is a hot topic in financial market analysis and quantitative trading decision-making research. It aims to predict future price trends using historical price data. Businesses can leverage asset price forecasts to gain more market information and new decision-making perspectives for financial planning and operational decisions, helping to establish more agile, intelligent, and robust financial decisions.
[0003] In related technologies, asset price forecasting is usually limited to predicting prices at a single point in time, which limits its help in actual market analysis. Summary of the Invention
[0004] This application discloses an asset price forecasting method, apparatus, and electronic device that can provide richer data for market analysis.
[0005] To solve the above problems, this application adopts the following technical solution: In a first aspect, embodiments of this application disclose an asset price prediction method, comprising: acquiring feature information of a target asset within a first preset time range, wherein the first preset time range includes multiple consecutive preset time periods, the multiple consecutive preset time periods include a first number of historical time periods and a second number of prediction time periods for the asset price growth rate to be predicted, the feature information corresponding to each historical time period includes price information and time information, and the feature information corresponding to each prediction time period includes time information; determining a first input sequence and a second input sequence based on the feature information of the target asset within the first preset time range, wherein the first input sequence includes feature information corresponding to the first number of historical time periods, the second input sequence includes feature information corresponding to a third number of historical time periods and feature information corresponding to the second number of prediction time periods, the third number of historical time periods being the last third number of historical time periods in the first input sequence, the third number being less than the first number; and obtaining the asset price growth rate of the target asset corresponding to the second number of prediction time periods output by the asset price prediction model by inputting the first input sequence and the second input sequence into an asset price prediction model, wherein the asset price prediction model is used to predict the asset price growth rate of the target asset corresponding to the second number of prediction time periods based on the feature information of the target asset corresponding to the first number of historical time periods.
[0006] Secondly, this application discloses an asset price prediction device, comprising: an acquisition module, configured to acquire feature information of a target asset within a first preset time range, wherein the first preset time range includes multiple consecutive preset time periods, the multiple consecutive preset time periods include a first number of historical time periods and a second number of prediction time periods for the price growth rate of the asset to be predicted, the feature information corresponding to each historical time period includes price information and time information, and the feature information corresponding to each prediction time period includes time information; and a determination module, configured to determine a first input sequence and a second input sequence based on the feature information of the target asset within the first preset time range, wherein the first input sequence includes feature information corresponding to the first number of historical time periods. The second input sequence includes feature information corresponding to a third number of historical time periods and feature information corresponding to a second number of predicted time periods. The third number of historical time periods are the last third number of historical time periods in the first input sequence, and the third number is less than the first number. The obtaining module is used to input the first input sequence and the second input sequence into the asset price prediction model to obtain the asset price growth rate of the target asset corresponding to the second number of predicted time periods output by the asset price prediction model. The asset price prediction model is used to predict the asset price growth rate of the target asset corresponding to the second number of predicted time periods based on the feature information of the target asset corresponding to the first number of historical time periods.
[0007] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, wherein the memory stores programs or instructions executable on the processor, and the programs or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0008] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer-executable program or instructions, which, when executed by a computer, implement the steps of the method described in the first aspect.
[0009] Fifthly, embodiments of this application provide a computer program product, the computer program product including a computer program stored on a non-transitory computer-readable storage medium, the computer program including program instructions, which, when executed by a computer, cause the computer to perform the steps of the method described in the first aspect.
[0010] The technical solution adopted in this application can achieve the following beneficial effects: This application provides an asset price prediction method. It involves acquiring characteristic information of a target asset within a first preset time range. This first preset time range includes multiple consecutive preset time periods, comprising a first number of historical time periods and a second number of prediction time periods for the asset's price growth rate. The characteristic information corresponding to each historical time period includes price and time information, and the characteristic information corresponding to each prediction time period includes time information. Based on the characteristic information of the target asset within the first preset time range, a first input sequence and a second input sequence are determined. The first input sequence includes characteristic information corresponding to the first number of historical time periods, and the second input sequence includes characteristic information corresponding to a third number of historical time periods and a second number of prediction time periods. The third number of historical time periods is the last third number of historical time periods in the first input sequence, and the third number is less than the first number. The first and second input sequences are then input into an asset price prediction model to obtain the asset price growth rate of the target asset corresponding to the second number of prediction time periods, as output by the asset price prediction model. By adopting the solution of this application, prediction results for asset price growth rates corresponding to multiple prediction time periods can be obtained, thereby providing richer data for market analysis. Attached Figure Description
[0011] Figure 1 This is a flowchart illustrating an asset price forecasting method disclosed in an embodiment of this application; Figure 2 This is an architecture diagram of a Transformer model disclosed in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of a vector representation network disclosed in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of an asset price prediction device disclosed in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application. Detailed Implementation
[0012] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0013] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the electrically connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0014] The asset price prediction method, apparatus, and electronic equipment disclosed in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.
[0015] This application discloses an asset price prediction method. Figure 1 This is a flowchart illustrating an asset price prediction method disclosed in an embodiment of this application. Figure 1 As shown, the method includes the following steps: S120. Obtain the characteristic information of the target asset within a first preset time range.
[0016] The first preset time range includes multiple consecutive preset time periods, which include a first number of historical time periods and a second number of prediction time periods for the growth rate of the asset price to be predicted. The feature information corresponding to each historical time period includes price information and time information, and the feature information corresponding to each prediction time period includes time information.
[0017] In this application, the target asset is the research asset object, and the first preset time range is a time range determined based on the selected start date and end date.
[0018] The preset time period can be a 15-minute interval. For example, the first preset time range may include multiple consecutive preset time periods: 9:45, 10:00, 10:15, 10:30, and 10:45. Here, 9:45 represents the period from 9:30 to 9:45, 10:00 represents the period from 9:45 to 10:00, 10:15 represents the period from 10:00 to 10:15, 10:30 represents the period from 10:15 to 10:30, and 10:45 represents the period from 10:30 to 10:45. 9:45, 10:00, and 10:15 can be historical time periods, while 10:30 and 10:45 can be predicted time periods, representing future periods. It should be noted that the specific length of the preset time period can be set according to actual needs and is not limited to the 15-minute intervals mentioned above.
[0019] In this application, the price information may include five features: opening price (open), highest price (high), lowest price (low), closing price (close), and trading volume (volume). The time information may include five features: the last time point of a preset time period, indicating which day of the year, day of the month, day of the week, hour of the day, and minute of the hour it falls under. The price information of the target asset within the preset time period is the opening price (open), highest price (high), lowest price (low), closing price (close), and trading volume of the target asset within that preset time period. The time information of the target asset within the preset time period is the last time point of that preset time period, indicating which day of the year, day of the month, day of the week, hour of the day, and minute of the hour it falls under.
[0020] In this application, the asset price growth rate can be determined based on the closing prices corresponding to two preset time periods. For example, the asset price growth rate corresponding to preset time period A can be determined based on the closing price corresponding to preset time period A and the closing price corresponding to preset time period B, where preset time period B is a preset time period preceding preset time period A. The formula for calculating the asset price growth rate is as follows: ,in, This refers to the asset price growth rate. The closing price for the preset time period A. The closing price for the preset time period B. This represents the current position in the sequence. This refers to the time interval order, assuming that preset time interval A and preset time interval B are adjacent time intervals. =1, assuming a preset time interval exists between preset time period A and preset time period B. =2.
[0021] It should be noted that this application does not limit the specific values of the first quantity and the second quantity. The second quantity can be less than the first quantity in order to improve the accuracy of the prediction.
[0022] S140. Based on the feature information of the target asset within the first preset time range, determine the first input sequence and the second input sequence.
[0023] The first input sequence includes feature information corresponding to the first number of historical time periods, and the second input sequence includes feature information corresponding to the third number of historical time periods and feature information corresponding to the second number of predicted time periods. The third number of historical time periods is the last third number of historical time periods in the first input sequence, and the third number is less than the first number.
[0024] It should be noted that the feature information corresponding to the third number of historical time periods included in the second input sequence is located at the very beginning of the second input sequence.
[0025] For example, if the first preset time range includes multiple consecutive preset time periods of 9:45, 10:00, 10:15, 10:30, and 10:45, and 9:45, 10:00, and 10:15 are historical time periods, and 10:30 and 10:45 are predicted time periods, the first input sequence may include feature information corresponding to the three historical time periods of 9:45, 10:00, and 10:15, and the second input sequence may include feature information corresponding to the historical time period of 10:15, and feature information corresponding to the two predicted time periods of 10:30 and 10:45. The first input sequence can be [ The second input sequence can be [ Data at each time point Each sequence contains C price information (open price, high price, low price, close price, and volume) and D time information (day of year, day of month, day of week, hour of day, and minute of hour), where t represents the current position in the sequence. The feature information corresponding to the historical time period of 9:45. The feature information corresponding to the historical time period of 10:00. The feature information corresponding to the historical time period of 10:15. The feature information corresponding to the historical time period of 10:30. The feature information corresponding to the historical time period of 10:45, the second input sequence in [ The symbol ] represents the target future price prediction information. Therefore, this numerical information is masked. Specifically, C can be replaced with 0 or other preset values to ensure the consistency of the input data dimensions. The second input sequence obtained after replacing it with 0 can be [ ].
[0026] In this application, by introducing feature information corresponding to a third number of historical time periods into the second input sequence, it is possible to ensure that the price information portion of the second input sequence is not entirely 0 or other preset values.
[0027] S160. By inputting the first input sequence and the second input sequence into the asset price prediction model, the asset price growth rate of the target asset in the second number of prediction time periods output by the asset price prediction model is obtained.
[0028] The asset price prediction model is used to predict the asset price growth rate of the target asset in the second prediction period based on the characteristic information of the target asset in the first number of historical time periods.
[0029] It should be noted that the target asset and the asset price prediction model can be matched one-to-one, that is, one asset price prediction model is used to predict the asset price growth rate of one asset.
[0030] In this application, by inputting a first input sequence and a second input sequence into an asset price prediction model, the asset price growth rate of the target asset corresponding to a second preset number of prediction time periods can be obtained. For example, the first input sequence [ ] and the second input sequence [ By inputting the asset price prediction model, you can obtain the asset price growth rate for the predicted time period at time t+1 and the asset price growth rate for the predicted time period at time t+2.
[0031] Since the non-stationarity of financial data is very common in the real world, and this leads to an increase in the difficulty of modeling time-series dependencies, extracting the asset closing price growth rate over a preset time period as the target prediction sequence solves the difficulty of learning time-series dependencies caused by non-stationarity of the sequence. This can improve the predictability of the data and minimize the change in data distribution over time.
[0032] This application provides an asset price prediction method. It involves acquiring characteristic information of a target asset within a first preset time range. This first preset time range includes multiple consecutive preset time periods, comprising a first number of historical time periods and a second number of prediction time periods for the asset's price growth rate. The characteristic information corresponding to each historical time period includes price and time information, and the characteristic information corresponding to each prediction time period includes time information. Based on the characteristic information of the target asset within the first preset time range, a first input sequence and a second input sequence are determined. The first input sequence includes characteristic information corresponding to the first number of historical time periods, and the second input sequence includes characteristic information corresponding to a third number of historical time periods and a second number of prediction time periods. The third number of historical time periods is the last third number of historical time periods in the first input sequence, and the third number is less than the first number. The first and second input sequences are then input into an asset price prediction model to obtain the asset price growth rate of the target asset corresponding to the second number of prediction time periods, as output by the asset price prediction model. By adopting the solution of this application, prediction results for asset price growth rates corresponding to multiple prediction time periods can be obtained, thereby providing richer data for market analysis.
[0033] In one implementation, the step of obtaining the asset price growth rate of the target asset in the second number of prediction time periods by inputting the first input sequence and the second input sequence into the asset price prediction model may include: inputting the first input sequence as the encoding input of the asset price prediction model and inputting the second input sequence as the decoding input of the asset price prediction model to obtain the asset price growth rate of the target asset in the second number of prediction time periods output by the asset price prediction model.
[0034] like Figure 2 As shown, the first input sequence can be used as the encoding input of the asset price prediction model into the encoding vector representation network of the asset price prediction model, and the second input sequence can be used as the decoding input of the asset price prediction model into the decoding vector representation network of the asset price prediction model, so as to obtain the asset price growth rate of the target asset corresponding to the second number of prediction time periods output by the fully connected layer of the asset price prediction model.
[0035] In one implementation, the asset price prediction model can be a Transformer model or a variant of the Transformer model. For example, the asset price prediction model can be as follows: Figure 2The Transformer model shown can also be a variant of the Transformer model, such as Non-stationary Transformer, Informer, Autoformer, FEDformer, TimesNet, Crossformer, iTransformer, etc.
[0036] The Transformer model possesses excellent capabilities in capturing long-sequence dependencies and integrating global information. Compared to traditional autoregressive models based on statistical methods or methods based on RNNs and CNNs, it can better uncover hidden periodicity and trends, improving prediction accuracy. This application, by employing the Transformer model or a variant of the Transformer model as an asset price prediction model, enhances the ability to handle complex time-series economic data, more effectively capturing market dynamics and thus improving the accuracy of asset price trend prediction. Furthermore, this application leverages the time-series modeling capabilities of the Transformer model's internal attention mechanism to capture implicit trends and periodicity in the data, providing more reliable and robust prediction results.
[0037] In this embodiment of the application, before obtaining the feature information of the target asset within a first preset time range, the method may further include: obtaining a training dataset, wherein each set of training data in the training dataset includes feature information of the target asset within a second preset time range, the second preset time range including multiple consecutive preset time periods, the multiple consecutive preset time periods including a fourth number of historical time periods and a fifth number of predicted time periods, the feature information including price information and time information; for each set of training data in the training dataset, based on the feature information of the target asset within the second preset time range, determining a third input sequence, a fourth input sequence, and an actual asset price growth rate sequence, wherein the third input sequence includes the feature information corresponding to the fourth number of historical time periods, the fourth input sequence includes the feature information corresponding to a sixth number of historical time periods and the time information corresponding to the fifth number of preset time periods. The sixth number of historical time periods is the last sixth number of historical time periods in the third input sequence. The sixth number is less than the fourth number. The actual asset price growth rate sequence includes the actual asset price growth rate corresponding to the fifth number of prediction time periods. Based on multiple sets of training data in the training dataset, the asset price prediction model to be trained is iteratively trained until the loss function corresponding to the asset price prediction model to be trained converges. In each iteration, the third input sequence and the fourth input sequence of a set of training data are input into the asset price prediction model to be trained to obtain the predicted asset price growth rate sequence output by the asset price prediction model to be trained. The predicted asset price growth rate sequence includes the predicted asset price growth rate of the target asset corresponding to the fifth number of prediction time periods. The loss function is determined based on the actual asset price growth rate sequence and the predicted asset price growth rate sequence.
[0038] In this application, the actual asset price growth rate corresponding to each prediction time period in the actual asset price growth rate sequence corresponding to each group of training data in the training dataset is calculated based on the asset price growth rate calculation formula described above. The third input sequence corresponding to each group of training data in the training dataset is similar to the first input sequence described above, and the fourth input sequence corresponding to each group of training data in the training dataset is similar to the second input sequence described above. This application will not repeat the details here.
[0039] During iterative training of the asset price prediction model, each iteration uses the third input sequence of a set of training data as the encoding input to the encoding vector representation network of the asset price prediction model, and the fourth input sequence as the decoding input to the decoding vector representation network of the asset price prediction model. This yields the predicted asset price growth rate sequence output by the fully connected layer of the asset price prediction model. This predicted asset price growth rate sequence includes the predicted asset price growth rate of the target asset for the fifth number of prediction time periods. After obtaining the predicted asset price growth rate sequence each time, a loss function is calculated based on the predicted asset price growth rate sequence and the actual asset price growth rate sequence. The error between the predicted asset price growth rate sequence and the actual asset price growth rate sequence is calculated based on the loss function. The error is then used to update the model parameters of the asset price prediction model through gradient backpropagation, resulting in an asset price prediction model with a higher ability to fit the data. The iterative training process is then repeated until the model converges, the loss function converges, or the return no longer increases.
[0040] In this embodiment, the loss function is determined based on the actual asset price growth rate sequence and the predicted asset price growth rate sequence, and may include: determining first data based on the actual asset price growth rate corresponding to the fifth number of predicted time periods in the actual asset price growth rate sequence and the predicted asset price growth rate corresponding to the fifth number of predicted time periods in the predicted asset price growth rate sequence; determining second data based on the actual asset price growth rate corresponding to the fifth number of predicted time periods in the actual asset price growth rate sequence; determining third data based on the predicted asset price growth rate corresponding to the fifth number of predicted time periods in the predicted asset price growth rate sequence; and determining the loss function based on the weight hyperparameter, the first data, the second data, and the third data.
[0041] In one implementation, determining the loss function based on the weight hyperparameter, the first data, the second data, and the third data may include: determining the loss function using the following formula; ,in, Let the loss function be... For weight hyperparameters, For the first data, For the second data, This is the third data. When When the loss function is MSE, the loss function is obtained by using the trend-enhancing loss function provided in this application. More signals are provided from the error to guide the training to better grasp the overall trend information, thereby helping the model improve the prediction accuracy of the overall trend and obtain more reliable and robust prediction results.
[0042] In one implementation, determining the first data based on the actual asset price growth rate corresponding to the fifth number of predicted time periods in the actual asset price growth rate sequence and the predicted asset price growth rate corresponding to the fifth number of predicted time periods in the predicted asset price growth rate sequence may include: determining the first data by the following formula; ,in, For the first data, This refers to the actual asset price growth rate series. The predicted asset price growth rate series, For the fifth quantity, This represents the actual asset price growth rate for the t-th prediction time period within the fifth number of prediction time periods. The predicted asset price growth rate corresponds to the t-th prediction time period in the fifth number of prediction time periods.
[0043] In one implementation, determining the second data based on the actual asset price growth rate corresponding to the fifth number of predicted time periods in the actual asset price growth rate sequence may include: determining the second data using the following formula; ,in, This refers to the second data. It is all The summation represents the actual growth rate of the entire sequence.
[0044] In one implementation, determining the third data based on the predicted asset price growth rate corresponding to the fifth number of predicted time periods in the predicted asset price growth rate sequence may include: determining the third data using the following formula; ,in, This refers to the third data. This represents the predicted growth rate of the entire sequence.
[0045] The architecture of the Transformer model is as follows: Figure 2As shown, the Transformer model in this application uses the asset price growth rate over a time unit (i.e., a preset time period) as the prediction target. The encoding vector representation network and decoding vector representation network of the Transformer model are constructed based on convolutional neural networks to process multivariate time series inputs (i.e., the first input sequence, second input sequence, third input sequence, and fourth input sequence mentioned above). The Transformer model includes encoding blocks and decoding blocks. The input of the encoding block is connected to the output of the encoding vector representation network, and the input of the decoding block is connected to the output of the decoding vector representation network. The latent vector representation of the input sequence is learned by the multi-head attention module inside the Transformer model, and the target predicted asset price growth rate sequence is output by the fully connected layer. The structure of the encoding vector representation network and decoding vector representation network in the Transformer model is as follows: Figure 3 As shown, it includes a value vector representation network, a time encoder, and a position encoder.
[0046] The asset price prediction model training in this application specifically includes the following steps: S1. Obtain the training dataset.
[0047] S1-1. Collection and Processing of Historical Asset Prices and Related Feature Data: Historical data of the corresponding assets are collected from publicly available financial databases based on the asset being studied, the start and end dates, and the sample collection interval. This includes all feature information of the target asset at the 15-minute level from the start date to the end date. This feature information includes price information and time information. Price information includes the opening price (open), high price (high), low price (low), closing price (close), and trading volume. Time information includes the last time point of the 15-minute level, which is the day of the year, day of the month, day of the week, hour of the day, and minute of the hour.
[0048] S1-2, Feature Extraction: Since the non-stationarity of financial data is very common in the real world, and this leads to an increase in the difficulty of modeling time-series dependencies, extracting the asset closing price growth rate per unit of time as the target prediction sequence can improve the predictability of the data and minimize the impact of data distribution changes over time. The formula for calculating the asset price growth rate is as follows: ,in, This represents the current position in the sequence. When calculating the growth rate of an asset's closing price over a 15-minute time interval, the time interval is used as the order of the interval. =1.
[0049] Furthermore, the feature information obtained by S1 is normalized, and sample features are truncated by a sliding window of a certain size. The features of the review window part are the third input sequence mentioned above, the features of the target prediction part are the fourth input sequence mentioned above, part of the fourth input sequence overlaps with the third input sequence, and the other part of the fourth input sequence is covered with price information, retaining only its time information.
[0050] After data normalization, the price information values follow a standardized distribution with a mean of 0 and a variance of 1, while the time information values range from -0.5 to 0.5.
[0051] In the process of extracting training and testing samples, this application uses a time length as... Sliding window to capture samples Where t is the current position in the sequence, and the data at each time step... Each contains C price features and D time features. (Previous sample) Feature data The third input sequence, after sample Feature data For the fourth input sequence, the fourth input sequence is... This represents the target's future price prediction information. Therefore, this part of the numerical information is masked and replaced with 0, retaining only its time characteristic data. The final fourth input sequence of the input model is... Furthermore, using the aforementioned formula for calculating asset price growth rates, the actual asset price growth rate sequence corresponding to the predicted portion of the extracted training and test samples is calculated.
[0052] S1-3. Dataset partitioning: Divide the dataset into training, validation, and test sets according to a certain ratio for model training, model parameter tuning, and model testing.
[0053] S2. Building an asset price prediction model based on the Transformer model.
[0054] S2-1, as shown Figure 2 As shown, the third input sequence is processed by an encoding vector representation network to obtain the first input embedding vector, and the fourth input sequence is processed by a decoding vector representation network to obtain the second input embedding vector. The encoding vector representation network and the decoding vector representation network in this application can use the same set of parameters.
[0055] The steps for processing the third input sequence using an encoding vector representation network to obtain the first input embedding vector are as follows: Figure 3As shown, the encoding vector representation network extracts the price feature sequence, time feature sequence, and location feature sequence of the third input sequence; this price feature sequence is then input into the value vector representation network constructed based on a one-dimensional convolutional layer for processing, resulting in the first input value embedding vector, expressed as: ,in, Given the input feature sequence, to ensure the sequence length remains unchanged after passing through the convolutional network, padding is performed at the beginning of the sequence with a value equal to the kernel size minus 1 (i.e., kernel_size-1). This positional feature sequence is then input into a positional encoder for processing to obtain the positional embedding vector. The location coding formula is: Where t is the position of the coordinate in the sequence. This represents the dimension of the embedding vector. For odd-numbered dimensions, the cosine function is used to calculate the encoded value, and for even-numbered dimensions, the sine function is used. The values from all dimensions are combined to obtain the position embedding vector at coordinate t. The time feature sequence is input into a time encoder for processing to obtain a time embedding vector. The time encoder is composed of a linear neural network, and the specific conversion formula is as follows: Where t is the position of the coordinate in the sequence. Let be the time feature vector at time t. and These are the learnable weight matrix and bias, respectively; the first input value embedding vector is then merged. Location embedding vector and time embedding vector ,get Then the first input embedding vector is obtained. ,in, Let be the embedding vector at time t.
[0056] Following a similar method described above, where the third input sequence is processed using an encoding vector representation network to obtain the first input embedding vector, the fourth input sequence is processed using a decoding vector representation network to obtain the second input embedding vector. .
[0057] S2-2, as shown Figure 2 As shown, the encoding block of the Transformer model processes the first input embedding vector to obtain the latent vector representation of the review information, and the decoding block of the Transformer model processes the second input embedding vector to obtain the latent vector representation of the expected information. Subsequently, the decoding block outputs the target feature information O based on the latent vector representation output by the encoding block. Figure 2 As shown, in this embodiment, the encoding block in the encoder and the decoding block in the decoder are both composed of a multi-head attention module, a regularization layer, and a forward propagation layer.
[0058] S2-2-1. The encoding block receives the first input embedding vector using a multi-head self-attention module (mechanism) MHA. After processing by the first regularization layer (with residual calculation), it outputs intermediate layer features, the specific expression of which is as follows: ,in, This is the first input embedding vector obtained from S2-1.
[0059] S2-2-2, Intermediate Layer Features The implicit vector representation is then processed again by the forward propagation layer and the second regularization layer (with residual calculation), as shown in the following expression: , ,in, and These are the learnable weight matrix and the bias, respectively.
[0060] S2-2-3. Use the output of the second regularization layer of the current coding block as the input of the multi-head self-attention module (mechanism) MHA of the coding block, and repeat S2-2-1 to S2-2-2 multiple times to obtain the final encoder latent vector expression, as shown in the following expression: .
[0061] S2-2-4. The decoding block receives the second input embedding vector using a multi-head self-attention module (mechanism) MHA. After processing by the first regularization layer (with residual calculation), it outputs the first intermediate layer features, as shown in the following expression: ,in This is the second input embedding vector obtained from S2-1.
[0062] S2-2-5. The decoding block further receives the first intermediate layer features and the encoder latent vector representation using a multi-head cross-attention module (mechanism) MHA. These are then processed by a second regularization layer (with residual calculation) to obtain the second intermediate layer features, the specific expression of which is as follows: Where U is the encoder latent vector representation obtained from S2-2-3, The first intermediate layer feature obtained from S2-2-4.
[0063] S2-2-6. The features of the second intermediate layer are processed again by the forward propagation layer and the third regularization layer (with residual calculation) to obtain the target feature representation, the specific expression of which is as follows: , ,in, and These are the learnable weight matrix and the bias, respectively.
[0064] S2-2-7. Use the output of the current decoding block as the input of the multi-head self-attention module (mechanism) MHA of the decoding block, and repeat S2-2-4 to S2-2-6 multiple times to obtain the final decoder target feature information expression, as follows: .
[0065] In this embodiment, in S2-2-1, S2-2-4, and S2-2-5, the multi-head attention module processes MHA, including the following steps: projecting the input features into Key (K), Query (Q), and Value (V) feature maps through three transformers respectively; the dot product output of the Query and Key feature maps is normalized by softmax to obtain the weight distribution; the Value feature map is weighted and combined according to the obtained weight distribution to obtain a new feature map; and then transformed by a fourth transformer to output the feature representation, the specific expression of which is as follows: , , Where h is the number of attention heads, In this context, O represents the matrix of the fourth transformer. , All are learnable transformation weight matrices. For multi-head attention outputs, [;] merges the multi-head outputs together when At this time, MHA is a multi-head self-attention mechanism. At this time, MHA is a multi-head cross-attention mechanism. To input the features into the 4th converter, This is the representation of how the fourth converter transforms the input features. and This is the information for K, Q, V conversion.
[0066] S2-3, as shown Figure 2 As shown, the fully connected layer network further transforms the target feature information O obtained in S2-2 into the final predicted asset price growth rate output, as shown in the following formula: ,in, Let be the predicted value at time t. and These are the learnable weight matrix and the bias, respectively.
[0067] S3. The model calculates the prediction error based on the loss function for iterative learning.
[0068] S3-1. For a set of input multivariate time series features (including the third and fourth input sequences mentioned above), the Transformer model output is obtained through forward propagation. .
[0069] S3-2. Calculate the error between the output predicted sequence (i.e., the predicted asset price growth rate sequence) and the target sequence (i.e., the actual asset price growth rate sequence) based on the loss function.
[0070] The formula for calculating the loss function for trend enhancement is as follows: The baseline loss function uses the mean squared error (MSE), calculated as follows: Where N is the length of the predicted sequence, It is the actual value at time t of the sequence. It is the predicted value at time t of the sequence. , ,in, It is all The summation represents the actual growth rate of the entire sequence. This represents the predicted growth rate of the entire sequence. For weight hyperparameters, when When = 1, the loss function is MSE.
[0071] It should be noted that, in addition to the aforementioned trend-enhancing loss function, Huber loss, quantile loss, and other methods can also be used.
[0072] S3-3. Update the model parameters by backpropagating the error using gradients to obtain a model with a higher ability to fit the data.
[0073] S3-4. Repeat steps S3-1 to S3-3 until the loss function converges, the model converges, or the profit no longer increases.
[0074] S4. The model is tested on the test set and the results are evaluated.
[0075] The asset price prediction method based on Transformer in this application fully understands the characteristics of asset price data. For the first time, it uses the closing price growth rate sequence of a time unit (i.e., a preset time period) as the prediction target. Based on the problem of numerical regression, it further predicts the trend of the sequence, solves the problem of sequence non-stationarity, and also bases the trend classification prediction on a more rigorous fitting regression.
[0076] The asset price forecasting method provided in this application can be executed by an asset price forecasting device. This application uses an asset price forecasting device executing the asset price forecasting method as an example to illustrate the asset price forecasting device provided in this application.
[0077] Figure 4 This is a schematic diagram of the structure of an asset price prediction device disclosed in an embodiment of this application. Figure 4As shown, the asset price prediction device 400 includes: an acquisition module 410, a determination module 420, and a obtaining module 430.
[0078] In this application, the acquisition module 410 is used to acquire feature information of a target asset within a first preset time range, wherein the first preset time range includes multiple consecutive preset time periods, the multiple consecutive preset time periods include a first number of historical time periods and a second number of prediction time periods for the price growth rate of the asset to be predicted, the feature information corresponding to each historical time period includes price information and time information, and the feature information corresponding to each prediction time period includes time information; the determination module 420 is used to determine a first input sequence and a second input sequence based on the feature information of the target asset within the first preset time range, wherein the first input sequence includes feature information corresponding to the first number of historical time periods, and the second input sequence... The system includes feature information corresponding to a third number of historical time periods and feature information corresponding to a second number of predicted time periods. The third number of historical time periods is the last third number of historical time periods in the first input sequence, and the third number is less than the first number. The obtaining module 430 is used to obtain the asset price growth rate of the target asset in the second number of predicted time periods by inputting the first input sequence and the second input sequence into the asset price prediction model. The asset price prediction model is used to predict the asset price growth rate of the target asset in the second number of predicted time periods based on the feature information of the target asset in the first number of historical time periods.
[0079] In one implementation, the obtaining module 430 obtains the asset price growth rate of the target asset in the second number of prediction time periods by inputting the first input sequence and the second input sequence into the asset price prediction model, including: inputting the first input sequence as the encoding input of the asset price prediction model and inputting the second input sequence as the decoding input of the asset price prediction model into the asset price prediction model to obtain the asset price growth rate of the target asset in the second number of prediction time periods.
[0080] In one implementation, the asset price prediction model is a Transformer model or a variant of the Transformer model.
[0081] In one implementation, the above apparatus further includes: the acquisition module 410, which is further configured to acquire a training dataset before acquiring the feature information of the target asset within a first preset time range, wherein each set of training data in the training dataset includes feature information of the target asset within a second preset time range, the second preset time range including multiple consecutive preset time periods, the multiple consecutive preset time periods including a fourth number of historical time periods and a fifth number of predicted time periods, and the feature information including price information and time information; the determination module 420, which is further configured to determine a third input sequence, a fourth input sequence, and an actual asset price growth rate sequence for each set of training data in the training dataset, based on the feature information of the target asset within the second preset time range, wherein the third input sequence includes the feature information corresponding to the fourth number of historical time periods, the fourth input sequence includes the feature information corresponding to a sixth number of historical time periods and the fifth number of preset time periods. The time information corresponding to the time intervals, the sixth number of historical time periods is the last sixth number of historical time periods in the third input sequence, the sixth number is less than the fourth number, the actual asset price growth rate sequence includes the actual asset price growth rate corresponding to the fifth number of predicted time periods; the training module is used to iteratively train the asset price prediction model to be trained based on multiple sets of training data in the training dataset until the loss function corresponding to the asset price prediction model to be trained converges, wherein, in each iteration of training, the third input sequence and the fourth input sequence of a set of training data are input into the asset price prediction model to be trained to obtain the predicted asset price growth rate sequence output by the asset price prediction model to be trained, the predicted asset price growth rate sequence includes the predicted asset price growth rate of the target asset corresponding to the fifth number of predicted time periods, and the loss function is determined based on the actual asset price growth rate sequence and the predicted asset price growth rate sequence.
[0082] In one implementation, the determining module 420 is further configured to determine first data based on the actual asset price growth rate corresponding to the fifth number of predicted time periods in the actual asset price growth rate sequence and the predicted asset price growth rate corresponding to the fifth number of predicted time periods in the predicted asset price growth rate sequence; the determining module 420 is further configured to determine second data based on the actual asset price growth rate corresponding to the fifth number of predicted time periods in the actual asset price growth rate sequence; the determining module 420 is further configured to determine third data based on the predicted asset price growth rate corresponding to the fifth number of predicted time periods in the predicted asset price growth rate sequence; and the determining module 420 is further configured to determine the loss function based on the weight hyperparameter, the first data, the second data, and the third data.
[0083] In one implementation, the determining module 420 determines the loss function based on the weight hyperparameter, the first data, the second data, and the third data, including: determining the loss function using the following formula; ,in, Let the loss function be... For weight hyperparameters, For the first data, For the second data, This refers to the third data.
[0084] In one implementation, the price information includes the opening price, the highest price, the lowest price, the closing price, and the trading volume.
[0085] Optionally, such as Figure 5 As shown, this application embodiment also provides an electronic device 500, including a processor 501 and a memory 502. The memory 502 stores a program or instructions that can run on the processor 501. When the program or instructions are executed by the processor 501, they implement the various steps of the above-described asset price prediction method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.
[0086] It should be noted that the electronic devices in the embodiments of this application include mobile electronic devices and non-mobile electronic devices.
[0087] This application also provides a computer-readable storage medium storing a program or instructions. When the computer-executable program or instructions are executed by a computer, they implement the various processes of the above-described asset price prediction method embodiments and achieve the same technical effects. To avoid repetition, these will not be described again here.
[0088] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0089] This application also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions that, when executed by a computer, cause the computer to perform the steps of the asset price prediction method described above.
[0090] The above embodiments of this application focus on describing the differences between the various embodiments. As long as the different optimization features between the various embodiments are not contradictory, they can be combined to form a better embodiment. For the sake of brevity, they will not be described in detail here.
[0091] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. An asset price prediction method characterized by, The method comprises: obtaining feature information of a target asset in a first preset time range, wherein the first preset time range comprises a plurality of continuous preset time periods, the plurality of continuous preset time periods comprise a first number of historical time periods and a second number of prediction time periods of asset price growth rate, the feature information corresponding to each historical time period comprises price information and time information, and the feature information corresponding to each prediction time period comprises time information; determining a first input sequence and a second input sequence based on the feature information of the target asset in the first preset time range, wherein the first input sequence comprises the feature information corresponding to the first number of historical time periods, the second input sequence comprises the feature information corresponding to a third number of historical time periods and the feature information corresponding to the second number of prediction time periods, the third number of historical time periods are the last third number of historical time periods in the first input sequence, and the third number is less than the first number; obtaining asset price growth rates of the target asset in the second number of prediction time periods output by an asset price prediction model by inputting the first input sequence and the second input sequence into the asset price prediction model, wherein the asset price prediction model is used to predict asset price growth rates of the target asset in the second number of prediction time periods based on feature information of the target asset in the first number of historical time periods.
2. The method of claim 1, wherein, The method of obtaining asset price growth rates of the target asset in the second number of prediction time periods output by an asset price prediction model by inputting the first input sequence and the second input sequence into the asset price prediction model comprises: inputting the first input sequence as an encoding input of an asset price prediction model into the asset price prediction model, inputting the second input sequence as a decoding input of the asset price prediction model into the asset price prediction model, and obtaining asset price growth rates of the target asset in the second number of prediction time periods output by the asset price prediction model.
3. The method of claim 2, wherein, The asset price prediction model is a Transformer model or a variant model of the Transformer model.
4. The method of claim 1, wherein, Before the method of obtaining feature information of a target asset in a first preset time range, the method further comprises: obtaining a training data set, wherein each set of training data in the training data set comprises feature information of the target asset in a second preset time range, the second preset time range comprises a plurality of continuous preset time periods, the plurality of continuous preset time periods comprise a fourth number of historical time periods and a fifth number of prediction time periods, and the feature information comprises price information and time information; For each set of training data in the training data set, based on the feature information of the target asset in the second preset time range, a third input sequence, a fourth input sequence and an actual asset price growth rate sequence are determined, wherein the third input sequence includes the feature information corresponding to the fourth number of historical time periods, the fourth input sequence includes the feature information corresponding to the sixth number of historical time periods and the time information corresponding to the fifth number of preset time periods, the sixth number of historical time periods is the last sixth number of historical time periods in the third input sequence, the sixth number is less than the fourth number, and the actual asset price growth rate sequence includes the actual asset price growth rate corresponding to the fifth number of prediction time periods. The asset price prediction model to be trained is iteratively trained based on multiple sets of training data in the training data set until a loss function corresponding to the asset price prediction model to be trained converges, wherein in each iteration, the third input sequence and the fourth input sequence of a set of training data are input into the asset price prediction model to be trained, and a predicted asset price growth rate sequence output by the asset price prediction model to be trained is obtained, the predicted asset price growth rate sequence includes the predicted asset price growth rate of the target asset corresponding to the fifth number of prediction time periods, and the loss function is determined based on the actual asset price growth rate sequence and the predicted asset price growth rate sequence.
5. The method of claim 4, wherein, The loss function is determined based on the actual asset price growth rate sequence and the predicted asset price growth rate sequence, comprising: determining first data based on the actual asset price growth rate corresponding to the fifth number of prediction time periods in the actual asset price growth rate sequence and the predicted asset price growth rate corresponding to the fifth number of prediction time periods in the predicted asset price growth rate sequence; determining second data based on the actual asset price growth rate corresponding to the fifth number of prediction time periods in the actual asset price growth rate sequence; determining third data based on the predicted asset price growth rate corresponding to the fifth number of prediction time periods in the predicted asset price growth rate sequence; determining the loss function based on the weight hyperparameter, the first data, the second data and the third data.
6. The method of claim 5, wherein, The determination of the loss function based on the weight hyperparameter, the first data, the second data and the third data comprises: determining the loss function by the following formula; wherein, is the loss function, is a weight hyperparameter, is the first data, is the second data, is the third data.
7. The method of claim 1, wherein, The price information includes opening price, highest price, lowest price, closing price and trading volume.
8. An asset price prediction device characterized by comprising: Comprise: an acquisition module configured to acquire feature information of a target asset in a first preset time range, wherein the first preset time range includes a plurality of continuous preset time periods, the plurality of continuous preset time periods include a first number of historical time periods and a second number of prediction time periods of asset price growth rate to be predicted, the feature information corresponding to each historical time period includes price information and time information, and the feature information corresponding to each prediction time period includes time information; determining a first input sequence and a second input sequence based on the feature information of the target asset in the first preset time range, wherein the first input sequence comprises feature information corresponding to the first number of historical time periods, the second input sequence comprises feature information corresponding to a third number of historical time periods and feature information corresponding to the second number of predicted time periods, the third number of historical time periods are the last third number of historical time periods in the first input sequence, and the third number is less than the first number; obtaining, by a obtaining module, asset price growth rates of the target asset in the second number of predicted time periods output by an asset price prediction model, by inputting the first input sequence and the second input sequence into the asset price prediction model, wherein the asset price prediction model is used to predict asset price growth rates of the target asset in the second number of predicted time periods based on feature information of the target asset in the first number of historical time periods.
9. An electronic device, comprising: The computer readable storage medium stores computer executable programs or instructions, and the computer executable programs or instructions are executed by a computer to implement the steps of the asset price prediction method according to any one of claims 1-7.
10. A computer readable storage medium characterized by, The computer readable storage medium stores computer executable programs or instructions, and the computer executable programs or instructions are executed by a computer to implement the steps of the asset price prediction method according to any one of claims 1-7.