Adaptive multi-agent stock trading method based on deep reinforcement learning

By constructing a multi-dimensional feature extractor and real-time reward feedback mechanism, combined with multi-agent collaborative decision-making, the problem of data noise and untimely feedback in the volatile market is solved, and efficient risk management and sustainable investment returns are achieved.

CN118799079APending Publication Date: 2024-10-18DALIAN UNIV OF TECH
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410943024.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-15
Publication Date
2024-10-18

AI Technical Summary

Technical Problem

In the volatile stock market, existing technologies are difficult to effectively deal with the impact of data noise, untimely feedback on market fluctuations, and errors in decision-making by a single agent. Moreover, risk management is insufficient and cannot fully protect the security of funds.

Method used

By building a multi-dimensional feature extractor to deeply mine stock trading information, design a real-time reward feedback mechanism and a dynamic stop-loss mechanism, and build a multi-agent synergy for the stock trading market, using convolutional neural networks, gated loop control units, and bidirectional long-term Short-term memory network and attention mechanism are used for feature extraction, and multi-agent trading decisions are made based on Dueling deep Q network.

Benefits of technology

It achieves high adaptability and real-time risk management to violent market fluctuations, reduces the risk of single-point errors, improves the efficiency and risk management capabilities of the trading framework, and ensures sustainable investment returns.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118799079A_ABST
    Figure CN118799079A_ABST
Patent Text Reader

Abstract

The invention discloses a self-adaptive multi-agent stock trading method based on deep reinforcement learning, and belongs to the field of quantitative trading. The method comprises the following steps: firstly, crawling stock historical transaction data, and processing a data vacancy value; performing normalization and windowing processing operation on the data to construct an initial stock feature tag; a convolutional neural network, a gating cycle control unit, a bidirectional long-short-term memory network and an attention mechanism are used to construct a multi-dimensional feature extractor, and the multi-dimensional feature extractor is used to perform deep feature extraction on the obtained stock. According to the method, an environment for agent transaction is constructed, a dynamic stop loss mechanism and a reward function are designed, a plurality of agents for transaction are constructed based on a Dueling deep Q network, decisions are independently executed according to state information provided by a multi-dimensional feature extractor, the decisions of all the agents are analyzed, and the most favorable decision in the current situation is formed. According to the invention, rapid changes of the market can be flexibly coped with, and more comprehensive decisions can be made.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of quantitative trading and relates to an adaptive multi-agent stock trading method based on deep reinforcement learning. The present invention uses deep learning technology and Dueling deep Q network to construct a multi-agent stock trading framework to achieve maximum profit and risk control in the scenario of stock market fluctuations. Background Art

[0002] The stock market is a highly complex and dynamically changing field, and has always been the focus of investors and researchers. With the increasing complexity of the market environment and the explosive growth of data, traditional investment strategies and technical analysis tools have gradually shown their limitations. In order to meet this challenge, researchers have begun to use advanced technologies such as machine learning, deep learning, and reinforcement learning to extract valuable information from massive data and optimize investment decisions.

[0003] (Leippold, M., Wang, Q., Zhou, W., 2022. Machine learning in the Chinese stock market.) Various machine learning techniques have been widely used in the Chinese stock market and have achieved remarkable results. (Sahu, SK, Mokhade, A., Bokde, ND, 2023. An overview of machine learning, deep learning, and reinforcement learning-based techniques in quantitative finance: recent progress and challenges.) Points out the challenges of machine learning, deep learning, and reinforcement learning in data acquisition, model interpretability, computational complexity, and financial market uncertainty. (Addy, WA, Ajayi-Nifise, AO, Bello, BG, Tula, ST, Odeyemi, O., Falaiye, T., et al., 2024. Machine learning in financial markets: A critical review of algorithmic trading and risk management.) Analyzes the importance of machine learning technology in risk management in high-frequency trading and automated trading systems. (Goutte, S., Le, HV, Liu, F., Von Mettenheim, HJ, 2023. Deep learning and technical analysis in cryptocurrency market.) proved the effectiveness of combining deep learning models and technical analysis indicators in cryptocurrency market prediction, and demonstrated performance under different market conditions. In order to achieve more efficient trading strategies, (Deng, Y., Bao, F., Kong, Y., Ren, Z., Dai, Q., 2016. Deep direct reinforcement learning for financial signal representation and trading.) proposed a direct deep reinforcement learning framework for the representation and trading of financial signals.(Yang, B., Liang, T., Xiong, J., Zhong, C., 2023. Deep reinforcement learning based on transformer and u-net framework for stock trading.) A deep reinforcement learning framework for stock trading was constructed.

[0004] However, in the volatile stock market, the drastic market fluctuations lead to a large amount of noise in the data, which significantly affects the signal extraction ability of the model. In such a frequently volatile environment, existing research is not adaptable enough to market fluctuations, and the model is difficult to effectively respond to different market scenarios. In addition, the problem of untimely transaction feedback is also prominent, and the ability to process and respond to the latest market status in real time is limited, which may lead to a lag in trading decisions. At the same time, the risk management measures of existing methods in the trading process are also insufficient, lacking effective risk assessment and management strategies, and unable to fully protect the safety of funds. Summary of the invention

[0005] The present invention mainly solves the problems of the impact of data noise on trading decisions in the volatile stock market, the untimely feedback of the volatile market environment, and the decision-making errors of a single agent. By constructing a multi-dimensional feature extractor, the stock trading information is deeply mined and the correlation is analyzed. The real-time reward feedback mechanism and the dynamic stop loss mechanism are redesigned to dynamically adjust the strategy when the market fluctuates violently according to the real-time feedback trading information. In addition, multiple agents are constructed to work together in the stock trading market. In order to achieve this method. First, crawl the historical stock trading information, obtain the initial data, construct the feature labels suitable for the trading framework, and then normalize and window the data to obtain unified and standardized stock data. Then, a multi-dimensional feature extractor is constructed using a convolutional neural network (CNN), a gated recurrent control unit (GRU), a bidirectional long short-term memory network (BiLSTM), and an attention mechanism to deeply mine and analyze financial time series and construct a state space for multi-agent trading. Next, we build multiple intelligent agents to work together in the stock trading market. We can evaluate the trading results by evaluating the cumulative rate of return, annualized rate of return, maximum drawdown, Sharpe ratio and other indicators brought by the exchange, and measure the robustness and high adaptability of the framework in executing transactions.

[0006] The technical solution of the present invention:

[0007] The adaptive multi-agent stock trading method based on deep reinforcement learning has the following steps:

[0008] Step 100, data crawling and preprocessing;

[0009] Step 101, determining the data source and the field and subject of stock trading;

[0010] Among them, the data source is determined. For the index, futures, and individual stock data sets to be obtained, Yahoo resources are selected, which is a website dedicated to stock market information;

[0011] Step 102, using crawler technology to obtain stock trading data from a data source;

[0012] Web crawler, by parsing function S d =Parse(html), extract function E d =Extract(S d ) to implement the crawler; html is the original web page, S d Represents the parsed data obtained after the parse function Parse(·), E d Represents the parsed data obtained after the parsing function Extract(·) is used.

[0013] Step 103, filtering and cleaning the stock trading data, removing irrelevant information, and making the data cleaner and more standardized;

[0014] Use text processing technology to clean and normalize data. d is the original data set, through the data filtering operation Filter(E d ), apply a series of filtering rules or conditions to filter out data that meets the requirements or standards from the original data and generate an intermediate data set F d ; Next, for the intermediate data set F d Perform data cleaning operation Clean(F d ), remove missing or erroneous data to ensure data consistency and accuracy, and finally generate the cleaned data set C d ; The formula is: C d =Clean(Filter(E d )); Filter(·) represents the operation of data filtering, which is to filter out data that meets the requirements or standards by applying a series of filtering rules or conditions; Clean(·) represents the operation of data cleaning, which is to process the filtered data and remove the data with missing values ​​to ensure the consistency and accuracy of the data;

[0015] Step 104, constructing feature labels using the acquired stock data;

[0016] Based on the opening price, highest price, closing price, closing price, trading volume and other information of stock data, the feature label S = {O, H, L, C, M} for the training framework is constructed using the moving average and exponential moving average. 30, M 60 , E 90}, where O is the opening price, H is the highest price, L is the lowest price, C is the closing price, M is the 30 is the 30-day simple moving average, M 60 is the 60-day simple moving average, E 90 is the 90-day exponential moving average;

[0017] Use M t represents the simple moving average at time t; N represents the time period of the moving average, indicating how many time units of price data are taken to calculate the average value, C i-1 represents the closing price of the i-1th time unit; E t represents the exponential moving average at time t; α represents the smoothing factor, which represents the weight of the exponential moving average of the current price and the previous time unit; C t represents the closing price of the tth time unit, E t-1 Represents the exponential moving average of the previous time unit; the formula is:

[0018] Step 105, data normalization and window processing;

[0019] Use MinMaxScaler normalization method to normalize the data for feature labels. Where X represents the stock feature data, X min represents the minimum value in the stock feature data, X max represents the maximum value in the stock feature data, X norm Represents the normalized stock feature data; normalize the feature labels to between (0 and 1) to eliminate the dimensional differences between different feature dimensions and improve the stability of the data. At the same time, in order to facilitate the discovery of the correlation between historical stock data, the data is windowed, and each window contains the data of the current day and the previous 60 days. t ={s t-1 ,s t-2 ,…,s t-60}. Among them, S t represents the window data of day t, s t-1 、s t-2 、s t-60 Represents the stock feature data of days t-1, t-2, and t-60;

[0020] Step 200, constructing a multi-dimensional feature extractor;

[0021] A multi-dimensional feature extractor is constructed using convolutional neural networks (CNN), gated recurrent control units (GRU), bidirectional long short-term memory networks (BiLSTM), and attention mechanisms for in-depth mining and analysis of financial time series.

[0022] Step 201, extracting feature data using a convolutional neural network;

[0023] By using the convolution operation of the convolutional neural network (CNN), we can focus on the local area in the financial time series, thereby capturing short-term dependencies. In addition, by stacking multiple convolutional layers, we can achieve multi-level feature representation from low-level features to high-level features. Where i represents the i-th time step, j is the index of the convolution kernel in the time step dimension, ranging from 1 to k, k is the size of the convolution kernel in the time step dimension, that is, the height of the convolution kernel. l is the index of the convolution kernel in the feature dimension, ranging from 1 to m, and m is the size of the convolution kernel in the feature dimension, that is, the width of the convolution kernel. W jl Is the weight of the convolution kernel, which represents the weight of the convolution kernel at position (j, l). (i+j-1)(l) Represents the value of the input data at position (i+1-1, l), where i is the time step index of the current convolution operation. b is the bias vector, added to each convolution output. i is the output of the convolution operation at time step i, Z i is the output of the activation function, the result after applying the ReLU activation function. p is the size of the pooling window, P i is the output of the pooling result at time step i after pooling, W fc is the weight matrix of the fully connected layer, b fc is the bias vector of the fully connected layer, and the expansion function flatten(·) is used to convert P i Expanded into a one-dimensional vector, is the final output of CNN branch It is the output feature map after convolution. Secondly, the convolution and pooling operations of convolutional neural network (CNN) can efficiently process large-scale financial time series data with low computational complexity and fast training speed.

[0024] Step 202, extracting feature data using a gated recurrent unit;

[0025] The Gated Recurrent Unit (GRU) can capture long-term dependencies in financial time series. Where X t represents the input data vector at time step t, h t-1 represents the hidden state vector of the previous time step, σ represents the Sigmoid activation function, z t represents the update gate vector at time step t, rt represents resetting the gate vector at time step t, represents the candidate hidden state vector at time step t, h t W represents the hidden state vector at time step t. z Represents the input data weight matrix for calculating the update gate, U z represents the hidden state weight matrix for calculating the update gate, b z Represents the bias vector for calculating the update gate. W r Represents the input data weight matrix of the reset gate, U r represents the hidden state weight matrix for calculating the reset gate, b r Represents the bias vector for calculating the reset gate. W h represents the input data weight matrix for calculating the candidate hidden state, U h represents the hidden state weight matrix for calculating candidate hidden states, b h represents the bias vector for calculating the candidate hidden state, and tanh(·) represents the Tanh activation function. branch It indicates the output result after the data is processed by the gated loop control unit. And each weight matrix quickly adjusts the memory state according to the current input to ensure timely adjustment when the market fluctuates violently.

[0026] Step 203, extracting feature data using a bidirectional long short-term memory network;

[0027] The Bidirectional Long Short-Term Memory (BiLSTM) network can comprehensively consider the previous and next information when processing the input of the current time step.

[0028] The forward long short-term memory network (LSTM) processes data from time step t=1 to t=n:

[0029]

[0030] The backward long short-term memory network (LSTM) processes data from time step t=n to t=1:

[0031]

[0032] Among them, X t represents the input data at the tth time step, and represents the hidden state vector of the previous time step, and represents the cell state vector at the previous time step, and represents the forget gate vector at time step t, and represents the input gate vector at time step t, and represents the cell state vector at time step t, and represents the output gate vector at time step t, and represents the hidden state vector at time step t, W f Represents the input data weight matrix for calculating the forget gate, U f represents the hidden state weight matrix for calculating the forget gate, b f Represents the bias vector for calculating the forget gate, W i Represents the input data weight matrix for calculating the input gate, U i represents the hidden state weight matrix of the input gate, b i Represents the bias vector for calculating the input gate, W c represents the input data weight matrix for calculating the candidate cell state, U c represents the hidden state weight matrix for calculating the candidate cell state, b c represents the bias vector for calculating the candidate cell state, W o Represents the input data weight matrix for calculating the output gate, U o represents the hidden state weight matrix for calculating the output gate, b o Represents the bias vector for calculating the output gate, σ represents the Sigmoid activation function, and tanh(·) represents the Tanh activation function. branch Represents the output result after using the bidirectional long short-term memory network to process the data. This comprehensive way of acquiring information enables BiLSTM to better understand the dynamic characteristics of financial time series, thereby improving the generalization ability and prediction accuracy of the model.

[0033] Step 204, using the attention mechanism to further extract the data;

[0034] Apply the attention mechanism to the data processed by the gated recurrent unit GRU and the bidirectional long short-term memory network BiLSTM, using attention branch Represents the output of the attention mechanism, attention branch =[GRU branch , BiLTM branch ] can help the model automatically identify and highlight the information of these key time points, providing more accurate and explanatory feature information.

[0035] Step 205, feature data fusion;

[0036] The data processed by the convolutional neural network (CNN), gated recurrent control unit (GRU), bidirectional long short-term memory network (BiLSTM), and attention mechanism are merged, using merge, merge = {CNN branch |GRU branch |BiLTM branch |attention branch}, use the merged data to build the environment state State = {merge1, merge2, ...merge t}, where merge t Represents the state data of the tth time step after fusion.

[0037] Step 300, the agent executes the transaction;

[0038] Step 301, constructing a transaction environment;

[0039] Define the fee consideration mechanism based on real transaction scenarios, ftee=close t ×dimension×0.1 / 100. Among them, free represents the transaction fee, close t is the closing price at time t, and dimension is the transaction size. Position limits and short position limits are set for transactions. Position limit: If the number of stocks currently held by the agent has reached the preset maximum position limit, it is prohibited to continue to buy the stock. This restriction is intended to avoid over-investment and repeated transactions, thereby reducing transaction costs. Short position limit: If the agent does not currently hold a certain stock, it is prohibited to perform a sell operation. This restriction ensures the rationality of the transaction and prevents short selling without goods.

[0040] Step 302, designing a dynamic stop loss mechanism;

[0041] In order to ensure that the agent can effectively control potential losses while pursuing maximum returns, an adaptive risk adjustment factor is used to combine the dynamic stop loss mechanism with the reward function to enhance the agent's risk awareness and capital protection capabilities. price =Base Stop_price ×(1+δ·ATR), where Stop price Indicates the closing price of the dynamic stop loss in the current state, Base Stop_price is the basic stop loss price of the stock, δ is the adaptive risk adjustment factor, and ATR represents the recent average volatility range. In this way, the agent can not only optimize returns, but also manage risks more effectively and protect its capital from large fluctuations.

[0042] Step 303, designing a reward function;

[0043] The reward function consists of two parts: trading profit and dynamic stop-loss reward. The trading profit part reflects the agent's actual gains in each transaction, encouraging it to find and exploit profitable opportunities in the market. The dynamic stop-loss reward is adjusted according to market volatility and risk level, aiming to encourage the agent to make smarter decisions in controlling potential losses. This dual reward mechanism not only motivates the agent to pursue higher profits, but also ensures that it always pays attention to risk management in the process of pursuing returns. This ensures a robust and sustainable return on investment in the volatile stock market. The reward function is expressed as R = P-C + B. Among them, R is the final return, representing the comprehensive performance of this transaction; P is the trading profit; C is the transaction cost, covering all transaction fees for a transaction; B is the reward item based on the agent's risk management performance.

[0044] Step 304, constructing a multi-agent transaction model;

[0045] The Dueling DQN-based agent uses the value flow and advantage flow in its dual network structure to perform a dual analysis of stock market dynamics. The value flow focuses on evaluating the overall value of the current state, while the advantage flow measures the advantage of a specific action over other possible choices Q(s, a) = V(s) + A(s, a), where s represents the current state, a represents the action in the current state s, and V(s) is the state value function, which represents the expected return in state s without considering the specific action. A(s, a) is the advantage function, which represents the advantage of choosing action a in state s over the average action taken in state s, and Q(s, a) is the state-action value function, which represents the expected return after choosing action a in state s. This dual analysis method enables the agent to more accurately evaluate market conditions and trading opportunities, thereby providing a solid foundation for its decision-making.

[0046] Based on the Dueling deep Q network, multiple agents for stock trading are constructed. First, each agent is trained separately according to the environmental state information of the training set provided by the multi-dimensional feature extractor to ensure the independence of each agent. Then, the state environmental state information of each agent in the verification set provided by the multi-dimensional feature extractor is used to verify the training effect of each agent. The model parameters with the best effect of each agent are selected as the model parameters of the agent. Secondly, all trained and verified agents are applied to the constructed trading environment. At each time step t, each agent makes a decision based on the current state, and a voting mechanism is used to select the most favorable decision at the moment. The formula for voting to select the best decision is: best action = argmax{a1, a2, ..., a n}, where best action Indicates the most favorable decision selected, a1~a nRespectively represent the decisions made by each agent in the current state s. Through this multi-agent trading method, the risk of single point error can be effectively reduced, and when the market fluctuates violently, it can flexibly respond to the rapid changes in the market and make more comprehensive decisions, achieving a more stable and sustainable return on investment.

[0047] Compared with the existing method, the beneficial effects of the present invention are:

[0048] The present invention constructs a multi-agent trading framework through deep reinforcement learning to achieve sustainable investment returns. The first part is to pre-process the crawled stock trading data based on stock market technical analysis, and construct feature labels suitable for the trading framework. The second part uses convolutional neural network (CNN), gated recurrent control unit (GRU), bidirectional long short-term memory network (BiLSTM), and attention mechanism to construct a multi-dimensional feature extractor for in-depth mining and analysis of financial time series, and to construct a state space suitable for the trading framework. The third part is designed to approximate the real trading environment, and redesign the reward feedback mechanism and dynamic stop loss mechanism to achieve timely feedback on trading information and effective risk management, so that the framework can be highly adapted to the violently volatile stock market. In addition, multiple agents are constructed to work together in the stock trading market, and the most favorable decisions are formed under the current situation by analyzing the decisions of all agents. The risk of single-point errors can be effectively reduced, and when the market fluctuates violently, it can flexibly respond to the rapid changes in the market and make more comprehensive decisions, so as to achieve more robust and sustainable investment returns.

[0049] The present invention uses a multi-dimensional feature extractor to conduct in-depth mining of stock trading information, analyze the correlation therein, and effectively solve the noise impact caused by drastic market fluctuations. At the same time, by designing a real-time reward feedback mechanism and a dynamic stop-loss mechanism, it is possible to dynamically adjust the strategy when the market fluctuates drastically according to the real-time feedback of trading information, achieve a high degree of adaptability to the drastically volatile market, and effectively control trading risks. The use of a multi-agent trading mechanism can significantly reduce the risk of decision-making errors of a single agent, and greatly improve the overall efficiency and risk management capabilities of the trading framework. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 It is a flow chart for implementing the adaptive multi-agent stock trading method based on deep reinforcement learning provided by the present invention;

[0051] Figure 2 is a flowchart for implementing step 100;

[0052] Figure 3 is a flow chart for implementing step 200;

[0053] Figure 4 is a flowchart for implementing step 300. DETAILED DESCRIPTION

[0054] The specific implementation of the present invention is further described below in conjunction with the accompanying drawings and technical solutions.

[0055] Figure 1 This is a flowchart of the implementation of the adaptive multi-agent stock trading method based on deep reinforcement learning provided by the present invention. The specific steps are as follows:

[0056] Step 100, data crawling, data normalization and window processing and feature label construction. The historical stock trading data is obtained through crawler technology, the data is first preprocessed for missing values, and feature labels are constructed through technical indicator analysis, and then the data is normalized and windowed to obtain the initial feature data set.

[0057] like Figure 2 As shown, step 100 includes steps 101 to 105:

[0058] Step 101, the data source is determined, and the required index, futures, and individual stock data sets are obtained on Yahoo;

[0059] Step 102, the web crawler analyzes the function S d =Parse(html), extract function E d =Extract(S d ) to implement the crawler; html is the original web page, S d Represents the parsed data obtained after the parse function Parse(·), E d Represents the parsed data obtained after the parsing function Extract(·);

[0060] Step 103, filter and clean stock trading data, use text processing technology to clean and normalize data, C d =Clean(Fliter(E d )) Ensure data consistency and accuracy and address data quality issues;

[0061] Step 104, construct feature labels, and use simple moving average and exponential moving average to construct feature labels S = {O, H, L, C, M} for training framework based on the opening price, highest price, closing price, closing price, trading volume and other information of stock data. 30 , M 60 , E 90}.

[0062] Step 105, data normalization and window processing, use MinMaxScaler normalization method to normalize the data for feature labels, The feature labels are normalized to between (0 and 1) to eliminate the dimensional differences between different feature dimensions and improve the stability of the data. At the same time, in order to facilitate the discovery of the correlation between historical stock data, the data is windowed, and each window contains the data of the current day and the previous 60 days. t ={s t-1 ,s t-2 ,…,s t-60}.

[0063] Step 200, construct a multi-dimensional feature extractor.

[0064] like Figure 3 As shown in the figure, by using convolutional neural network (CNN), gated recurrent control unit (GRU), bidirectional long short-term memory network (BiLSTM), and attention mechanism to build a multi-dimensional feature extractor, the financial time series can be deeply mined and analyzed.

[0065] Step 201, using a convolutional neural network to extract feature data, using the convolution operation of the convolutional neural network (CNN), it is possible to focus on the local area in the financial time series, thereby capturing short-term dependencies. In addition, by stacking multiple convolutional layers, multi-level feature representation from low-level features to high-level features can be achieved. Secondly, the convolution and pooling operations of the convolutional neural network (CNN) can efficiently process large-scale financial time series data, with lower computational complexity and faster training speed.

[0066] Step 202, using a gated recurrent unit to extract feature data, can capture long-term dependencies in financial time series, quickly adjust the memory state according to the current input, and ensure timely adjustments when the market fluctuates violently.

[0067] Step 203, using a bidirectional long short-term memory network to extract feature data, when processing the input of the current time step, it can comprehensively consider the previous and subsequent information, better understand the dynamic characteristics of the financial time series, and thus improve the generalization ability and prediction accuracy of the model.

[0068] Step 204, use the attention mechanism to further extract the data, and apply the attention mechanism to the data processed by the gated recurrent unit (GRU) and the bidirectional long short-term memory network (BiLSTM) branch =[GRU branch , BiLTM branch ] can help the model automatically identify and highlight the information of these key time points, providing more accurate and explanatory feature information.

[0069] Step 205, feature data fusion, merge the data processed by the convolutional neural network (CNN), the gated recurrent control unit (GRU), the bidirectional long short-term memory network (BiLSTM), and the attention mechanism merge = {CNN branch |GRU branch |BiLTM branch |attention branch}, use the merged data to build the environment state State = {merge l , merge2, …merge t}.

[0070] Step 300, multiple agents execute transactions;

[0071] like Figure 4 As shown in the figure, a multi-agent trading environment is defined, a reward feedback mechanism and a dynamic stop-loss mechanism are designed, and a multi-agent trading framework is constructed.

[0072] Step 301, build a trading environment, and define the fee consideration mechanism free=close based on the actual trading scenario t ×dimension×0.1 / 100. There are also position limits and short position limits on transactions to ensure the rationality of transactions and prevent short selling without goods.

[0073] Step 302, design a dynamic stop-loss mechanism to ensure that the agent can effectively control potential losses while pursuing maximum returns, and use an adaptive risk adjustment factor to combine the dynamic stop-loss mechanism with the reward function to enhance the agent's risk awareness and capital protection capabilities.

[0074] Step 303, design a reward function that combines trading profit and dynamic stop loss rewards as a reward feedback mechanism. This not only motivates the agent to pursue higher profits, but also ensures that it always pays attention to risk management in the process of pursuing returns. This ensures that the framework can achieve a robust and sustainable return on investment in the volatile stock market.

[0075] Step 304, construct a multi-agent trading model, and the agent based on Dueling DQN uses the value flow and advantage flow in its dual network structure to perform a dual analysis of market dynamics Q(s,a)=V(s)+A(s,a). This enables the agent to more accurately evaluate market conditions and trading opportunities, thereby providing a solid foundation for its decision-making.

[0076] In combination with the solution of the present invention, experimental analysis is performed on different data sets, as follows:

[0077] Table 1: Experimental results on the index dataset

[0078]

[0079] Table 2: Experimental results on the futures dataset

[0080]

[0081] Table 3: Experimental results on individual stock datasets

[0082]

[0083]

[0084] From the results in Table 1, it can be seen that on the index data set, compared with the classic buy-and-hold strategy, the method proposed in the present invention has an overall improvement of 15% to 71% in the cumulative rate of return, especially on the SZI data set, the cumulative rate of return has increased by 70.40%. Compared with basic prediction models such as decision trees and support vector machines (SVM), the method proposed in the present invention has an improvement of 12% to 45% in the cumulative rate of return. Compared with models based on deep reinforcement learning (such as Q-learning, deep Q networks based on gated recurrent control units, and deep Q networks based on convolutional neural networks), the counter-party of the present invention also has an improvement of 5% to 40% in the cumulative rate of return. Especially on the N100 data set, it has increased by 65.13% compared with Q-learning. Although the framework of the present invention is at a disadvantage on the SSE Composite and SZI data sets in terms of the maximum drawdown index, this is because the method of the present invention selects the highest return strategy within the tolerable risk range. However, from the performance of the Sharpe ratio, it can be seen that the returns brought by the framework of the present invention when bearing these risks are very considerable.

[0085] From the results in Table 2, it can be seen that on the futures data set, compared with the buy-and-hold strategy, the method proposed in the present invention has an overall improvement of 15% to 69% in the cumulative rate of return. Compared with basic prediction models such as decision trees and support vector machines (SVM), the method proposed in the present invention has an overall improvement of 20% to 85% in the cumulative rate of return. Compared with models based on deep reinforcement learning (such as Q-learning, deep Q networks based on gated recurrent control units, and deep Q networks based on convolutional neural networks), the proposed framework has an overall improvement of 5% to 60% in the cumulative rate of return. It is particularly worth mentioning that in the Crude data set, the proposed framework has an overall improvement of 109.1% in the cumulative rate of return compared with the Q-learning model. Although the method of the present invention is slightly inferior to the deep Q network based on the gated recurrent control unit in the maximum drawdown indicator on the Crude and Corn data sets, this is because the framework selects a strategy to maximize the return under the premise of controllable risks, which brings certain trading risks. However, judging from the results of the Sharpe ratio, the returns brought by these risks are very considerable and generally acceptable.

[0086] From the results in Table 3, it can be seen that on the individual stock data set, compared with the buy and hold strategy, the method proposed in the present invention generally improves by 10% to 63%. It is particularly worth mentioning that on the AMZN data set, the method proposed in the present invention improves by 52.37%, and on the NVDA data set it improves by 62.43%. Compared with basic prediction models such as decision trees and support vector machines (SVM), the method proposed in the present invention improves by 30% to 130%. In particular, on the NVDA data set, compared with the decision tree, the method proposed in the present invention improves by 100.35%, and compared with the SVM, it improves by 71.43%. On the AMZN data set, compared with the decision tree, the proposed model improves by 128.56%. These significant improvements highlight the efficiency and accuracy of the method proposed in the present invention in processing complex financial data. Compared with deep reinforcement learning models such as Q-learning, deep Q networks based on gated recurrent control units, and deep Q networks based on convolutional neural networks, the method proposed in the present invention generally improves by 30% to 100%. On the NVDA dataset, compared with the Q-learning model, the framework of the present invention has improved by 91.08%; compared with the deep Q network model based on the gated recurrent control unit, it has improved by 60.20%. On the AMZN dataset, compared with the Q-learning model, the method proposed by the present invention has improved by 99.11%. These data fully demonstrate the robustness and adaptability of the method proposed by the present invention on different datasets. In terms of evaluation indicators such as annualized rate of return, maximum drawdown, and Sharpe ratio, the method proposed by the present invention still maintains a leading advantage. Although the maximum drawdown and Sharpe ratio of the present invention are slightly inferior in the AMZN and NVDA datasets, this does not affect the overall advantages of the present invention. The reason for this is that the method proposed by the present invention chooses to maximize returns within a controllable risk range, which reflects the balance between risk management and return maximization of the method proposed by the present invention. The results show that the present invention not only performs well in capturing market fluctuations, but also has good robustness and adaptability.

Claims

1. Adaptive multi-agent stock trading method based on deep reinforcement learning, It is characterized in that The steps are as follows: Step 100, data crawling and preprocessing; Step 101, determining the data source and the field and subject of stock trading; Among them, the data source is determined. For the index, futures, and individual stock data sets to be obtained, select Yahoo resources; Step 102, using crawler technology to obtain stock trading data from a data source; Web crawler, by parsing function S d =Parse(html), extract function E d =Extract(S d ) to implement the crawler; html is the original web page, S d Represents the parsed data obtained after the parse function Parse(·), E d Represents the parsed data obtained after the parsing function Extract(·); Step 103, filtering and cleaning the stock trading data, removing irrelevant information, and making the data cleaner and more standardized; Use text processing technology to clean and normalize data. d is the original data set, through the data filtering operation Filter(E d ), apply filtering rules or conditions to filter out data that meets the requirements or standards from the original data and generate an intermediate data set F d ; Next, for the intermediate data set F d Perform data cleaning operation Clean(F d ), remove missing or erroneous data to ensure data consistency and accuracy, and finally generate the cleaned data set C d ; The formula is: C d =Clean(Filter(E d )); Filter(·) represents the data filtering operation, and Clean(·) represents the data cleaning operation; Step 104, constructing feature tags using the acquired stock data; Based on the opening price, highest price, closing price, closing price, and trading volume information of stock data, the feature label S = {O, H, L, C, M} for the training framework is constructed using moving average and exponential moving average. 30 , M 60 , E 90 }, where O is the opening price, H is the highest price, L is the lowest price, C is the closing price, M is the 30 is the 30-day simple moving average, M 60 is the 60-day simple moving average, E 90 is the 90-day exponential moving average; Use M t represents the simple moving average at time t; N represents the time period of the moving average, indicating how many time units of price data are taken to calculate the average; C i-1 represents the closing price of the i-1th time unit; E t represents the exponential moving average at time t; α represents the smoothing factor, which represents the weight of the exponential moving average of the current price and the previous time unit; C t represents the closing price of the tth time unit, E t-1 Represents the exponential moving average of the previous time unit; the formula is: Step 105, data normalization and window processing; Use MinMaxScaler normalization method to normalize the data for feature labels. Where X represents the stock feature data, X min represents the minimum value in the stock feature data, X max represents the maximum value in the stock feature data, X norm Represents the normalized stock feature data; normalize the feature labels to between (0 and 1) to eliminate the dimensional differences between different feature dimensions and improve the stability of the data; at the same time, in order to facilitate the discovery of the correlation between historical stock data, the data is windowed, and each window contains the data of the current day and the previous 60 days S t ={s t-1 ,s t-2 ,…,s t-60 }, where S t represents the window data of day t, s t-1 、s t-2 、s t-60 Represents the stock feature data of days t-1, t-2, and t-60; Step 200, constructing a multi-dimensional feature extractor; Use convolutional neural network (CNN), gated recurrent control unit (GRU), bidirectional long short-term memory (BiLSTM), and attention mechanism to build a multi-dimensional feature extractor for in-depth mining and analysis of financial time series; Step 201, extracting feature data using a convolutional neural network; The convolution operation of the convolutional neural network (CNN) is used to capture short-term dependencies in financial time series; by stacking multiple convolutional layers, multi-level feature representation from low-level features to high-level features is achieved. Among them, i represents the i-th time step, j is the index of the convolution kernel in the time step dimension, ranging from 1 to k, k is the size of the convolution kernel in the time step dimension, that is, the height of the convolution kernel; l is the index of the convolution kernel in the feature dimension, ranging from 1 to m, m is the size of the convolution kernel in the feature dimension, that is, the width of the convolution kernel; W jl is the weight of the convolution kernel, which represents the weight of the convolution kernel at position (j, l); X (i+j-1)(l) represents the value of the input data at position (i+1-1, l), where i is the time step index of the current convolution operation; b is the bias vector, which is added to each convolution output; Y i is the output of the convolution operation at time step i, Z i is the output of the activation function, the result after applying the ReLU activation function; p is the size of the pooling window, P i is the output of the pooling result at time step i after pooling; W fc is the weight matrix of the fully connected layer, b fc is the bias vector of the fully connected layer. The expansion function flatten(·) is used to expand Pi into a one-dimensional vector. is the final output of CNN branch It is the output feature map after convolution; Step 202, extracting feature data using a gated recurrent unit; The gated recurrent control unit GRU captures long-term dependencies in financial time series. Where X t represents the input data vector at time step t, h t-1 represents the hidden state vector of the previous time step, σ represents the Sigmoid activation function, z t represents the update gate vector at time step t, r t represents resetting the gate vector at time step t, represents the candidate hidden state vector at time step t, h t represents the hidden state vector at time step t; W z Represents the input data weight matrix for calculating the update gate, U z represents the hidden state weight matrix for calculating the update gate, b z Represents the bias vector for calculating the update gate; W r Represents the input data weight matrix of the reset gate, U r represents the hidden state weight matrix for calculating the reset gate, b r Represents the bias vector for calculating the reset gate; W h represents the input data weight matrix for calculating the candidate hidden state, U h represents the hidden state weight matrix for calculating candidate hidden states, b h represents the bias vector for calculating the candidate hidden state, tanh(·) represents the Tanh activation function; GRU branch Indicates the output result after the data is processed by the gated loop control unit; Step 203, extracting feature data using a bidirectional long short-term memory network; The bidirectional long short-term memory network BiLSTM takes into account the previous and subsequent information when processing the input of the current time step; The forward LSTM network processes data from time step t=1 to t=n: The backward LSTM network processes data from time step t=n to t=1: Among them, Xt 表 represents the input data at the tth time step, and represents the hidden state vector of the previous time step, and represents the cell state vector at the previous time step, and represents the forget gate vector at time step t, and represents the input gate vector at time step t, and represents the cell state vector at time step t, and represents the output gate vector at time step t, and represents the hidden state vector at time step t, W f Represents the input data weight matrix for calculating the forget gate, U f represents the hidden state weight matrix for calculating the forget gate, b f Represents the bias vector for calculating the forget gate, W i Represents the input data weight matrix for calculating the input gate, U i represents the hidden state weight matrix of the input gate, b i Represents the bias vector for calculating the input gate, W c represents the input data weight matrix for calculating the candidate cell state, U c represents the hidden state weight matrix for calculating the candidate cell state, b c represents the bias vector for calculating the candidate cell state, W o Represents the input data weight matrix for calculating the output gate, U o represents the hidden state weight matrix for calculating the output gate, b o represents the bias vector for calculating the output gate, σ represents the Sigmoid activation function, and tanh(·) represents the Tanh activation function; through BiLTM branch Represents the output result after using the bidirectional long short-term memory network to process the data; Step 204, using the attention mechanism to further extract the data; Apply the attention mechanism to the data processed by the gated recurrent unit GRU and the bidirectional long short-term memory network BiLSTM, using attention branch Represents the output of the attention mechanism, attention branch =[GRU branch , BiLTM branch ], helping the model automatically identify and highlight the information of these key time points, providing more accurate and explanatory feature information; Step 205, feature data fusion; The data processed by the convolutional neural network CNN, the gated recurrent control unit GRU, the bidirectional long short-term memory network BiLSTM, and the attention mechanism are merged and expressed as merge. The formula is: merge = {CNN branch |GRU branch |BiLTM branch |attention branch }, use the merged data to build the environment state State = {merge 1 , merge 2 , …merge t }, where merge t Represents the state data of the tth time step after fusion; Step 300, the agent executes the transaction; Step 301, constructing a transaction environment; Define the fee consideration mechanism based on real transaction scenarios, free = close t ×dimension×0.1 / 100; where free represents the transaction fee, close t is the closing price at time t, dimension is the transaction size; and position limits and short position limits are set for transactions; position limit: if the number of stocks currently held by the agent has reached the preset maximum position limit, it is prohibited to continue to buy the stock; short position limit: if the agent does not currently hold a certain stock, it is prohibited to perform a sell operation; Step 302, designing a dynamic stop loss mechanism; In order to ensure that the agent can effectively control potential losses while pursuing maximum returns, an adaptive risk adjustment factor is used to combine the dynamic stop loss mechanism with the reward function to enhance the agent's risk awareness and capital protection capabilities; Stop price =Base Stop_price ×(1+δ·ATR), where Stop price Indicates the closing price of the dynamic stop loss in the current state, Base Stop_price is the basic stop loss price of the stock, δ is the adaptive risk adjustment factor, and ATR represents the recent average volatility range; Step 303, designing a reward function; The reward function consists of two parts: trading profit and dynamic stop-loss reward; the trading profit part reflects the agent's actual income in each transaction, encouraging it to find and take advantage of profitable opportunities in the market; the dynamic stop-loss reward is adjusted according to market volatility and risk level, aiming to encourage the agent to make smarter decisions in controlling potential losses; the reward function is expressed as R = P-C+B; where R is the final return, representing the overall performance of this transaction; P is the trading profit; C is the transaction cost, covering all transaction fees for a transaction; B is the reward item based on the agent's risk management performance; Step 304, constructing a multi-agent transaction model; The Dueling DQN-based agent uses the value flow and advantage flow in its dual network structure to perform a dual analysis of stock market dynamics; the value flow focuses on evaluating the overall value of the current state, while the advantage flow measures the advantage of a specific action over other possible choices Q(s, a) = V(s) + A(s, a), where s represents the current state, a represents the action in the current state s, V(s) is the state value function, which represents the expected return in state s without considering the specific action; A(s, a) is the advantage function, which represents the advantage of choosing action a in state s over the average action taken in state s, and Q(s, a) is the state-action value function, which represents the expected return after choosing action a in state s; Based on the Dueling deep Q network, multiple agents for stock trading are constructed. First, each agent is trained separately according to the environmental state information of the training set provided by the multi-dimensional feature extractor to ensure the independence of each agent. Then, the state environmental state information of each agent in the verification set provided by the multi-dimensional feature extractor is used to verify the training effect of each agent. The model parameters with the best effect of each agent are selected as the model parameters of the agent. Secondly, all trained and verified agents are applied to the constructed trading environment. At each time step t, each agent makes a decision based on the current state, and a voting mechanism is used to select the most favorable decision at the moment. The formula for voting to select the best decision is: best action = argmax{a 1 , a 2 , …, a n }, where best action represents the most favorable decision selected, a 1 ~a n Represent the decisions made by each agent in the current state s.

Citation Information

Cited By

  • Energy project investment management method and system based on artificial intelligence

    CN119941166A

  • Energy project investment management method and system based on artificial intelligence

    CN119941166B

  • Multi-agent collaboration system for financial investment

    CN120765182A