Stock prediction method and system based on time constraint contrast learning

By constructing a fragment-independent time-series prediction model and building positive and negative samples based on a time-constrained contrastive learning method, the problem of insufficient generalization ability of stock price prediction models is solved, and higher prediction accuracy and robustness are achieved.

CN121767091APending Publication Date: 2026-03-31HARBIN INSTITUTE OF TECHNOLOGY (SHENZHEN) (INSTITUTE OF SCIENCE AND TECHNOLOGY INNOVATION HARBIN INSTITUTE OF TECHNOLOGY SHENZHEN)
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-31
Publication Date
2026-03-31

AI Technical Summary

Technical Problem

Existing technologies are insufficient to effectively address the high noise, non-stationarity, and complex nonlinear characteristics of financial markets in stock price prediction. This results in inadequate model generalization ability, an inability to effectively distinguish between valuable signals and random fluctuations, and significant influence of the overall market environment on stock price fluctuations.

Method used

We employ a time-constrained contrastive learning approach. By constructing a segment-independent time-series prediction model, we use a multilayer perceptron for feature extraction and construct positive and negative samples based on time constraints. We design a joint loss function that combines information noise contrastive estimation loss and mean squared error loss for training.

Benefits of technology

It significantly improves the model's generalization performance and prediction accuracy, effectively identifies stock patterns, enhances the understanding of market microstructure, reduces information interference across time segments, and improves the robustness and accuracy of predictions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121767091A_ABST
    Figure CN121767091A_ABST
Patent Text Reader

Abstract

The invention discloses a stock prediction method and system based on time constraint comparative learning, and the method comprises the steps: obtaining the historical daily frequency transaction data of a stock, including an opening price, a closing price, a highest price, a lowest price, and a trading volume; preprocessing the data and dividing the data into a training set, a verification set and a test set; constructing a time sequence prediction model with independent fragments; constructing positive and negative samples based on time constraints; designing a loss function and training the model; and the model predicts and outputs the stock yield. Through the time sequence encoder with independent segments, the problem of data offset existing in the stock market can be effectively solved, generalization on a test set is improved, positive and negative samples are constructed through comparative learning, stock modes with similar incomes can be effectively captured, and through time constraint, the influence of big trend on stock incomes in different periods can be eliminated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of financial technology, and in particular relates to a stock prediction method and system based on time-constrained comparative learning. Background Technology

[0002] With the rapid development of financial markets and increasingly active investment activities, stock price prediction has gradually become a core issue in quantitative investment, risk control, and policy regulation. Stock price fluctuations are not only affected by corporate fundamentals and the macroeconomic environment, but also by various uncertainties such as investor sentiment, unforeseen events, and policy changes, exhibiting high volatility and complex nonlinear characteristics. This complexity makes accurate prediction of stock trends extremely challenging.

[0003] Early research was largely based on traditional financial theory, employing fundamental or technical analysis for judgment. Fundamental analysis emphasizes inferring value through information such as corporate finances, industry structure, and economic cycles, but it often lags behind in rapidly fluctuating markets. Technical analysis relies on historical patterns in prices and trading volumes, but it struggles to reflect potential structural changes. Both methods depend on experience and human judgment, lacking systematic data-driven capabilities.

[0004] To improve the scientific rigor of forecasts, statistical methods have been gradually introduced. Typical examples include time series models such as Autoregressive Moving Average (ARIMA) and Generalized Autoregressive Conditional Heteroskedasticity (GARCH). These models can describe certain short-term trends and volatility characteristics, but due to their relatively strict assumptions, they struggle to capture long-term dependent and event-driven non-stationary behaviors in financial markets, resulting in inherent limitations in their predictive capabilities.

[0005] With the continuous improvement of big data and computing power, machine learning methods have been widely explored and applied. Support vector machines, random forests, and gradient boosting trees can alleviate the shortcomings of nonlinear modeling to some extent and utilize high-dimensional data for learning. However, these methods often rely on the assumption of distributional consistency and perform poorly on the frequent structural changes, distributional drift, and heterogeneous data in financial markets, exhibiting insufficient predictive stability and generalization ability.

[0006] In recent years, the rise of deep learning has opened up new avenues for stock prediction. Recurrent Neural Networks (RNNs), Long Short-Term Memory Networks (LSTMs), and Gated Recurrent Units (GRUs) can model time dependencies and have shown advantages in financial sequence prediction; Convolutional Neural Networks (CNNs) are used to capture local patterns; Transformer models based on self-attention mechanisms have potential in modeling long-range dependencies and parallel computing; Graph Neural Networks (GNNs) can characterize the complex correlation structures between stocks, while Reinforcement Learning (RL) can continuously optimize strategies through interaction with the market environment. These methods provide new tools for characterizing the dynamic features of the market.

[0007] Despite ongoing research, existing methods still face numerous challenges in practical applications: First, financial time series generally exhibit characteristics such as high noise, strong volatility, and non-stationarity, making it difficult for models to effectively distinguish between valuable signals and random fluctuations; second, the stock market suffers from data bias, with its characteristics changing significantly over time, resulting in poor generalization ability of existing deep learning models across different time periods; and third, stock price fluctuations are greatly influenced by the overall market environment, making it difficult for existing deep learning models to effectively model market price changes.

[0008] Therefore, there is an urgent need for a stock prediction method that can effectively address the high noise, non-stationarity, and complex nonlinear characteristics of financial markets, so as to improve the prediction accuracy while enhancing the generalization and applicability of the model, thereby better serving investment decisions and risk management. Summary of the Invention

[0009] To address the above-mentioned technical problems, this invention discloses a stock prediction method and system based on time-constrained comparative learning, aiming to solve the problems existing in the prior art.

[0010] The present invention solves the technical problem by adopting the following technical solution:

[0011] In a first aspect, the present invention provides a stock prediction method based on time-constrained contrastive learning, comprising the following steps:

[0012] Step S1: Obtain historical daily trading data for the stock, including opening price, closing price, highest price, lowest price, and trading volume;

[0013] Step S2: Preprocess the data and divide it into training set, validation set and test set;

[0014] Step S3: Construct fragment-independent time series prediction models;

[0015] Step S4: Construct positive and negative samples based on time constraints;

[0016] Step S5: Design the loss function and train the model;

[0017] Step S6: The model predicts and outputs the stock return rate.

[0018] In one implementation, obtaining historical daily trading data in step S1 means obtaining stock data that may enter the investment portfolio.

[0019] In one implementation, step S2, the method for preprocessing the data, includes:

[0020] Feature engineering: Based on the historical daily trading data, technical indicators are extracted from the Alpha158 feature set to form an initial feature vector;

[0021] Extreme value removal: On each trading day, remove stock samples whose returns exceed the preset quantile range.

[0022] Cross-sectional standardization: On each trading day, the return rate and features of the sample are Z-score standardized separately.

[0023] In one implementation, a cross-sectional extremum removal method is performed within each training batch as follows:

[0024] For a set of stocks traded on the same trading day, calculate the p1 and p2 quantiles, and remove samples that fall outside this range using the following formula:

[0025]

[0026] in, The sample set after removing extreme values. Let n be the target rate of return for the nth stock. These are the p1 and p2 quantile thresholds for the daily return, respectively.

[0027] In one implementation, the Z-score is used to standardize the sample's return rate and features separately using the following formula:

[0028]

[0029] in, σ is the standardized rate of return. t The standard deviation of the sample for that day, μ t This represents the sample mean for that day.

[0030] In one implementation, the division of the training set, validation set, and test set in step S2 is performed in chronological order, with the training set consisting of the earliest completed transactions, the validation set the next, and the test set the latest completed transactions.

[0031] In one implementation, step S3 involves constructing a fragment-independent time-series prediction model as follows:

[0032] The data is preprocessed, and the time series of each stock is divided into multiple segments of length L. p Overlapping time segments are used for local time series modeling:

[0033]

[0034] in, For the time series of the nth stock, Let N be the i-th time segment of the n-th stock on day t. p This represents the total number of time segments.

[0035] Each time segment captures local time-dependent features, which are then input into the time encoder module for feature extraction.

[0036] A multilayer perceptron is used as the backbone encoder, corresponding to a segment-independent structure; the encoding process is defined as follows:

[0037] Z1=σ(W1X i +b1), Z2=W2Z1+b2,

[0038] in, σ(·) is the ReLU activation function, and the output is... This refers to the temporal embedding of time segments, where Z1 is the hidden layer vector, and X... i Let b1 be the time series of the i-th stock, and b2 be the bias terms.

[0039] Finally, the embeddings of all the segments are concatenated to form a complete temporal representation:

[0040]

[0041] Where H represents the overall timing representation after splicing;

[0042] During the prediction phase, the model only takes the embedding vector at the last moment of each channel as the feature representation:

[0043]

[0044] Where h is the final feature representation of the batch, H t=T For the timing representation of the last moment, Flatten is a vectorization operation;

[0045] The final predicted value is then generated through a linear mapping layer:

[0046]

[0047] in, To predict the rate of return for the model, With b pred These are the weights and bias parameters of the prediction layer, respectively.

[0048] In one implementation, in step S3, the encoder of the segment-independent temporal prediction model is a multilayer perceptron, and each time segment is independently mapped to an embedding vector without cross-segment information interaction, thereby enhancing generalization ability.

[0049] In one implementation, step S4, the method for constructing the positive and negative samples includes:

[0050] Rank the stocks on the same trading day by their return rate;

[0051] For each anchor sample, positive samples are stock segments that are ranked adjacently on the same trading day, and negative samples are stock segments that are ranked far apart on the same trading day.

[0052] In one implementation, the loss function is obtained in step S5 as follows:

[0053] For each training batch, the loss is estimated using information-noise contrastive estimation:

[0054]

[0055] in, For information-noise contrast estimation loss, B is the number of samples in the batch, τ is the temperature coefficient, and h i For anchor point samples, h represents the positive sample features corresponding to the anchor sample. j This represents the negative sample feature representation corresponding to the anchor sample; This represents the number of negative samples.

[0056] For each training batch, the mean squared error loss is used to measure the deviation between the predicted value and the actual return.

[0057]

[0058] in, For mean square error loss, With y i These are the predicted value and the actual value of the i-th sample, respectively;

[0059] The final joint loss function is a weighted sum of the information-noise contrastive estimation loss and the mean squared error loss:

[0060]

[0061] in, This is the joint loss function.

[0062] Secondly, the present invention also provides a stock prediction system based on time-constrained contrastive learning, comprising:

[0063] The data acquisition module is used to acquire historical daily trading data of stocks, including opening price, closing price, highest price, lowest price, and trading volume;

[0064] The preprocessing module is used to preprocess the data and divide it into training, validation, and test sets.

[0065] The stock feature encoding module calculates the feature vectors of stocks and constructs a segment-independent time series prediction model.

[0066] The sample construction module is used to construct positive and negative samples based on time constraints.

[0067] The training module is used to design the loss function and train the model;

[0068] The prediction module is used to output the predicted stock return results.

[0069] Thirdly, the present invention also provides a terminal device, including a memory and one or more programs, wherein one or more programs are stored in the memory and configured to be executed by one or more processors, the one or more programs including a stock prediction method based on time-constrained contrastive learning as described in any of the preceding claims.

[0070] Fourthly, the present invention also provides a non-transitory computer-readable storage medium, wherein when the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is able to perform a stock prediction method based on time-constrained contrastive learning as described in any of the above.

[0071] The present invention discloses a stock prediction method and system based on time-constrained comparative learning, which has the following beneficial effects:

[0072] First, by constructing a segment-independent temporal encoder, the model extracts features independently within each time segment, avoiding cross-segment information interference, effectively alleviating the common data distribution offset problem in the stock market, and significantly improving the model's generalization performance on the test set.

[0073] Secondly, by employing a contrastive learning mechanism and constructing positive and negative sample pairs through time constraints, the model can effectively identify stock patterns with similar return behaviors, thereby enhancing its understanding of the market microstructure and improving the accuracy and robustness of predictions.

[0074] Finally, by introducing a time constraint mechanism to control the time window when constructing positive and negative samples, the influence of the overall market trend on individual stock returns is effectively eliminated, allowing the model to focus more on learning the unique price behavior characteristics of individual stocks. Attached Figure Description

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

[0076] Figure 1 This is a flowchart of a method according to an embodiment of the present invention.

[0077] Figure 2 This is a block diagram illustrating the principle of a stock prediction system based on time-constrained comparative learning, according to an embodiment of the present invention.

[0078] Figure 3 This is a flowchart illustrating a stock prediction system based on time-constrained comparative learning, according to an embodiment of the present invention.

[0079] Figure 4 This is a schematic block diagram of a stock prediction system based on time-constrained comparative learning according to an embodiment of the present invention. Detailed Implementation

[0080] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments and the accompanying drawings. It should be understood that these descriptions are merely exemplary and not intended to limit the scope of the invention. Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concept of the invention.

[0081] This invention provides a stock prediction method and system based on time-constrained contrastive learning, aiming to solve the problems existing in the prior art:

[0082] (1) There is a data bias in the stock market. As time changes, the characteristics of the stock market will also change significantly. Existing deep learning models have poor generalization ability in different time periods.

[0083] (2) Stock price fluctuations are greatly affected by the overall market environment, and existing deep learning models cannot effectively model market price changes.

[0084] refer to Figure 1 This invention provides a stock prediction method based on time-constrained contrastive learning, comprising the following steps:

[0085] Step S1: Obtain historical daily trading data for the stock, including opening price, closing price, highest price, lowest price, and trading volume;

[0086] In this embodiment of the invention, web crawling technology is used to obtain daily trading data of the target stock pool from a professional financial data platform.

[0087] Step S2: Preprocess the data and divide it into training set, validation set and test set;

[0088] In this embodiment of the invention, data preprocessing includes the following steps:

[0089] Feature engineering: Based on the historical daily trading data, technical indicators are extracted from the Alpha158 feature set to form an initial feature vector;

[0090] Extreme value removal: On each trading day's cross-section, stock samples whose returns exceed a preset quantile range are removed. Due to significant differences in return distribution and extreme value interference among different stocks, this embodiment of the invention performs cross-sectional extreme value removal within each training batch. Specifically, for the stock set on the same trading day, the p1 and p2 quantiles are calculated, and samples exceeding this range are removed.

[0091]

[0092] in, The sample set after removing extreme values. Let n be the target rate of return for the nth stock. These are the p1 and p2 quantile thresholds for the daily return, respectively.

[0093] Cross-sectional standardization: For each trading day's cross-section, the sample's returns and features are Z-score standardized separately.

[0094]

[0095] in, σ is the standardized rate of return. t The standard deviation of the sample for that day, μ t This represents the sample mean for that day.

[0096] Similarly, the feature matrix X (t) Each feature dimension is also cross-sectionally standardized within the training batch to eliminate the offset caused by differences in dimensions between different stocks.

[0097] Unlike conventional stock-by-stock or time-window-by-time normalization methods, this paper performs extremum removal and standardization within training batches to maintain cross-sectional consistency and comparability of return distributions. This preprocessing method effectively reduces the perturbation of abnormal returns on the model gradient, improves training stability, and helps to correctly model the contrastive learning loss in the return ranking space.

[0098] Step S3: Construct fragment-independent time series prediction models;

[0099] After standardization, this embodiment of the invention divides the time series of each stock into multiple segments of length L. p Overlapping time segments are used for local time series modeling:

[0100]

[0101] in, For the time series of the nth stock, Let N be the i-th time segment of the n-th stock on day t. p This represents the total number of time segments.

[0102] Each time segment captures local time-dependent features, which are then fed into the time-series encoder module for feature extraction.

[0103] This invention employs a multilayer perceptron (MLP) as the backbone encoder, corresponding to a "segment-independent" structure. Each time segment is independently mapped to the embedding space, with no attention or interaction operations across time segments, thus achieving independent representation of time segments. The encoding process is defined as follows:

[0104] Z1=σ(W1X i +b1), Z2=W2Z1+b2

[0105] in, σ(·) is the ReLU activation function, Z1 is the hidden layer vector, and the output is... This refers to the temporal embedding of time segments, X i Let b1 be the time series of the i-th stock, and b2 be the bias terms.

[0106] Finally, the embeddings of all the segments are concatenated to form a complete temporal representation:

[0107]

[0108] Where H represents the overall timing representation after splicing;

[0109] During the prediction phase, the model only takes the embedding vector at the last moment of each channel as the feature representation:

[0110]

[0111] Where h is the final feature representation of the batch, H t=T For the timing representation of the last moment, Flatten is a vectorization operation;

[0112] The final predicted value is then generated through a linear mapping layer:

[0113]

[0114] in, To predict the rate of return for the model, With b pred These are the weights and bias parameters of the prediction layer, respectively.

[0115] Compared to attention-based models such as Transformer, this structure significantly reduces parameter size and computational complexity, and is more robust to distribution shifts in financial time series.

[0116] Step S4: Construct positive and negative samples based on time constraints;

[0117] In this embodiment of the invention, in order to maintain the relative ranking of stock returns in the embedding space, a contrastive learning loss based on return ranking is introduced. First, the samples are sorted in ascending order by label and normalized:

[0118]

[0119] Where Normalize(·) represents feature normalization, h π(1:B) For samples sorted in ascending order of yield, argsort(y) is the sorting operation.

[0120] For each sample i, the set of positive samples is defined as:

[0121]

[0122] in, Let be the set of positive samples for the i-th sample, π(i) be the index of sample i, π(j) be the index of sample j, and k be the index of sample j. pos The threshold for the ranking interval of positive samples;

[0123] The negative sample set is:

[0124]

[0125] in, For the negative sample set, k neg The threshold for the negative sample ranking interval;

[0126] In the implementation, each sample is selected from its set of positive samples. A positive sample i is randomly selected from the data. + ,

[0127] Step S5: Design the contrastive learning loss function and train the model;

[0128] In this embodiment of the invention, information noise contrastive estimation loss is used for each training batch.

[0129]

[0130] in, For information-noise contrast estimation loss, B is the number of samples in the batch, τ is the temperature coefficient, and h i For anchor point samples, h represents the positive sample features corresponding to the anchor sample. j This represents the negative sample feature representation corresponding to the anchor sample; This represents the number of negative samples.

[0131] This loss encourages the clustering of samples with similar returns in the embedding space, while distancing them from samples with significantly different returns.

[0132] In this embodiment of the invention, the mean squared error loss is used to measure the deviation between the predicted value and the actual return for each training batch:

[0133]

[0134] in, For mean square error loss, With y i Let be the predicted value and the actual value of the i-th sample;

[0135] The final joint loss function is a weighted sum of the information-noise contrast estimation loss and the mean square error loss.

[0136]

[0137] in, This is the joint loss function.

[0138] Step S6: The model predicts and outputs the stock return rate.

[0139] In this embodiment of the invention, the preprocessed input data is input into the trained model, and the model will output the predicted rate of return for a future period of time.

[0140] This invention also discloses a stock prediction system based on time-constrained contrastive learning, such as... Figure 2 As shown, it includes:

[0141] The data acquisition module 100 is used to acquire historical daily trading data of stocks, including opening price, closing price, highest price, lowest price and trading volume;

[0142] The preprocessing module 200 is used to preprocess the data and divide it into training set, validation set and test set;

[0143] The stock feature encoding module 300 calculates the feature vector of the stock and constructs a segment-independent time series prediction model.

[0144] Sample construction module 400 is used to construct positive and negative samples based on time constraints;

[0145] Training module 500 is used to design the loss function and train the model;

[0146] The prediction module 600 is used to output the predicted stock return results.

[0147] In an embodiment of the present invention, a flowchart of a stock prediction system based on time-constrained contrastive learning is shown below. Figure 3 As shown in the diagram, firstly, the data acquisition module obtains historical daily stock data from a financial data platform using web crawling technology and stores the data in a stock pool. Then, the preprocessing module preprocesses the data, and the sample construction module constructs positive and negative samples according to time constraints. Subsequently, the training module trains the stock representation calculation model. Finally, for the stock code to be predicted, the prediction module first retrieves a segment of historical stock data from the stock pool, preprocesses it, and inputs it into the stock feature encoding module. The stock feature vector is obtained through the stock representation calculation model, and the predicted rate of return is further calculated.

[0148] The stock prediction system based on time-constrained contrastive learning according to an embodiment of the present invention can be deployed on various platforms or devices. A schematic block diagram of such a system is shown below. Figure 4 As shown.

[0149] This invention discloses a computer-readable storage medium comprising a computer program that, when run on an electronic device, causes the electronic device to perform a stock prediction method based on time-constrained contrastive learning as described in any of the preceding embodiments.

[0150] This invention discloses an apparatus comprising a processor and a memory connected together, the processor being configured to execute a computer program stored in the memory to perform a stock prediction method based on time-constrained contrastive learning as described in any of the preceding embodiments.

[0151] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A stock prediction method based on time-constrained contrastive learning, characterized in that, It comprises the following steps: Step S1, obtaining historical daily frequency trading data of stocks, including opening price, closing price, highest price, lowest price and trading volume; Step S2, preprocessing data and dividing training set, validation set and test set; Step S3, constructing a segment-independent time series prediction model; Step S4, constructing positive and negative samples based on time constraints; Step S5, designing a loss function and training a model; Step S6, the model predicts the output of stock returns.

2. The stock prediction method based on time-constrained contrastive learning according to claim 1, characterized in that, In step S2, the method of preprocessing data includes: Feature engineering: based on the historical daily frequency trading data, technical indicators in the Alpha158 feature set are extracted to form an initial feature vector; Extreme value elimination: on the cross-section of each trading day, eliminate the stock samples whose returns exceed the preset quantile range; Cross-section standardization: on the cross-section of each trading day, the returns and features of the samples are respectively standardized by Z-score.

3. The stock prediction method based on time-constrained contrastive learning according to claim 2, characterized in that, The extreme value elimination method on the cross-section level within each training batch is as follows: For a set of stocks on the same trading day, calculate the p1 and p2 quantiles, and eliminate the samples that exceed the range by the following formula: wherein, is the sample set after removing outliers, is the target return rate of the nth stock, are the p1 and p2 quantile thresholds of the daily return rate, respectively.

4. The stock prediction method based on time-constrained contrastive learning according to claim 3, characterized in that, The returns and features of the samples are respectively standardized by Z-score using the following formula: where, is the standardized return, σ t is the sample standard deviation, μ t is the sample mean.

5. The stock prediction method based on time-constrained contrastive learning according to claim 4, characterized in that, In step S3, the method of constructing a segment-independent time series prediction model is as follows: The data is pre-processed, and the time series of each stock is divided into multiple overlapping time segments of length L p for local temporal modeling: wherein, is the time series of the nth stock, is the ith time slice of the nth stock on the tth day, N p is the total number of time slices; Each time slice captures local time-dependent features, which are then input into a time series encoder module for feature extraction; A multi-layer perceptron is used as the backbone encoder, corresponding to the segment-independent structure; the encoding process is defined as: Z1 = σ(W1X i + b1), Z2 = W2Z1 + b2, where, σ(·) is the ReLU activation function, output is the time-series embedding of the time slice, Z1is the hidden layer vector, X i is the time-series embedding of the time slice, Z1is the hidden layer vector, X Finally, the embeddings of all segments are concatenated to form the overall time series representation: Where H is the overall time series representation after concatenation; In the prediction phase, the model only takes the embedding vector of the last time of each channel as the feature representation: where h is the final feature representation of the batch, H t=T is the last-minute timing representation, Flatten is the vectorization operation; And through a linear mapping layer to generate the final prediction value: where, is the predicted return for the model, and b pred are the weight and bias parameters for the prediction layer, respectively.

6. The stock prediction method based on time-constrained contrastive learning according to claim 5, characterized in that, In step S4, the construction method of the positive and negative samples includes: Sort the stocks on the same trading day according to their returns; For each anchor sample, the positive sample is the stock segment adjacent to the same trading day in the order, and the negative sample is the stock segment far away from the same trading day in the order.

7. The stock prediction method based on time-constrained contrastive learning according to claim 1, characterized in that, In step S5, the method of obtaining the loss function is: For each training batch, use information noise contrast to estimate the loss: wherein, is the information noise contrast estimation loss, B is the number of samples in the batch, τ is the temperature coefficient, h i is the anchor sample, is the positive sample feature representation corresponding to the anchor sample, h j is the negative sample feature representation corresponding to the anchor sample, is the number of negative samples; For each training batch, use mean square error loss to measure the deviation between the predicted value and the true return: wherein, is the mean squared error loss, and y i are the predicted and true values, respectively, for the i-th sample. The final joint loss function is the weighted sum of the information noise contrast estimation loss and the mean square error loss: wherein, is the joint loss function.

8. A stock prediction system based on time-constrained contrastive learning, characterized in that, It includes: A data acquisition module for obtaining historical daily frequency trading data of stocks, including opening price, closing price, highest price, lowest price and trading volume; A preprocessing module for preprocessing data and dividing training set, validation set and test set; A stock feature encoding module that calculates the feature vector of the stock and constructs a segment-independent time series prediction model; A sample construction module for constructing positive and negative samples based on time constraints; A training module for designing a loss function and training a model; A prediction module for outputting stock return prediction results.

9. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The processor executes the computer program to implement a stock prediction method based on time constraint contrast learning according to any one of claims 1-8.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that The computer program is executed by the processor to implement the stock prediction method based on time constraint contrast learning according to any one of claims 1-8.