Foreign exchange market risk quantification and early warning method based on long and short term memory model
Through the foreign exchange market risk quantification and early warning method based on long and short-term memory models, the characteristic matrix is constructed and the LSTM model is trained using historical data, which solves the complexity of risk monitoring of foreign exchange rate fluctuations, and achieves more efficient and accurate risk warning.
Patent Information
- Application Number
- CN202410994019.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2025-01-03
AI Technical Summary
In the prior art, foreign exchange market exchange rate monitoring relies on manual judgment, which leads to complex data processing, long processes and experience-dependent, making it difficult to effectively monitor and early warning of exchange rate fluctuations risks.
Using the foreign exchange market risk quantification and early warning method based on long and short-term memory models, the foreign exchange market characteristic matrix is constructed by obtaining historical macro and micro business data, stable operators and error correction operators are designed, and the LSTM model is trained to predict exchange rate changes, and through the index Calculate and judge the risk of exchange rate fluctuation by inflection points and inverted points of inflow volume.
It improves the accuracy and efficiency of exchange rate fluctuation prediction, provides a scientific and systematic risk management solution, which can timely identify and manage foreign exchange market risks and reduces the dependence of manual judgment.
Smart Images

Figure CN119250954A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of financial data processing and analysis, and in particular to a foreign exchange market risk quantification and early warning method based on a long-short term memory model. Background Art
[0002] Preventing and defusing systemic risks is an eternal theme in financial work. In the foreign exchange market, exchange rate fluctuations are key indicators for measuring market risks, which are related to the monitoring and early warning of risk indicators such as the mark-to-market value, risk exposure, margin, and clearing fund requirements of market institutions' position portfolios in daily risk monitoring of the foreign exchange market; in the case of default handling, it has an important impact on the timely and efficient completion of the position segmentation, risk hedging, and position auctions of defaulting institutions, which is directly related to whether the default handling can be completed quickly and smoothly to prevent risk spillover.
[0003] The present invention proposes a foreign exchange market risk quantification and early warning method based on the Long Short Term Memory (LSTM) model. As an advanced time series prediction model, LSTM can effectively capture the long-term dependencies and short-term dynamic changes of exchange rate fluctuations in the foreign exchange market, and provides a unified and scalable analysis toolbox for foreign exchange market risk monitoring. Compared with traditional time series models, the LSTM model shows higher accuracy and flexibility in dealing with exchange rate fluctuation prediction problems, significantly improving the efficiency and accuracy of daily risk monitoring.
[0004] In addition, this project also introduces the LSTM model to judge the possibility of violent fluctuations, providing a quantitative basis for early warning. The present invention uses advanced data analysis technology to provide a more scientific and systematic solution for foreign exchange market risk management, and can provide financial institutions with a better way to identify, measure and manage foreign exchange market risk measurement methods, helping relevant market institutions make timely and accurate judgments in a volatile market environment. Summary of the invention
[0005] The purpose of the present invention is to overcome the shortcomings of the prior art and provide a foreign exchange market risk quantification and early warning method based on a long short-term memory model, which is used to obtain historical macro and micro business data, use the model to judge the exchange rate fluctuation of the day and whether there is abnormal fluctuation, and solve the problems of complex data processing, long process and reliance on experience in the manual judgment of existing exchange rate monitoring personnel.
[0006] In order to achieve the above purpose, a foreign exchange market risk quantification and early warning method based on long short-term memory model is designed. The method is as follows:
[0007] S1. Obtain historical characteristic data that affects exchange rate risk, derive and screen the characteristics based on the original data, and construct a data set, including:
[0008] S1.1. Obtain domestic and foreign macroeconomic data, micro exchange rate data, micro liquidity data, and micro market sentiment data through the Wind database;
[0009] S1.2. According to the share of currencies in China's monetary policy basket, we select important currencies, including RMB (CNY), US dollar (USD), Australian dollar (AUD), Euro (EUR), British pound (GBP), Hong Kong dollar (KHD), Japanese yen (JPY), Korean won (KRW), Ruble (RUB), Thai won (THB), to form the important currency set C, which is expressed as follows:
[0010] C={CNY,USD,AUD,EUR,GBP,HKD,JPY,KRW,RUB,THB}
[0011] S1.3. Based on the selected important currency set, the foreign exchange market characteristic matrix is constructed as follows:
[0012]
[0013] M I The constructed foreign exchange market characteristic matrix has a size of m×n, where m represents the number of selected currencies and n represents the number of selected days. represents the currency characteristics of CNY at time t0, It can represent CNY from time t0 to t n characteristic trends;
[0014] S1.4. Derivation of features based on the original data: Derivation of features by subtracting the previous value from the next value and dividing the previous value from the next value, represented by _diff and _div suffixes respectively;
[0015] S1.5. Select features with strong correlation based on Pearson correlation coefficient;
[0016] S2. Construct a stabilization operator and an error correction operator, calculate the adjustment coefficient, and avoid inaccurate risk warning caused by the violent fluctuations of high-weight currencies themselves, including:
[0017] S2.1. Design a stabilization operator to characterize the volatility of currency in continuous time, defined as follows:
[0018]
[0019] Where m represents the number of currencies, c represents the specific currency, and t represents the tth day. represents the estimated index value of currency c on day t;
[0020] S2.2. Design an error correction operator to characterize the prediction error. The calculation process is:
[0021]
[0022] Where m represents the number of currencies, n represents the number of days for statistics, c represents the specific currency, and t represents the tth day. represents the real exchange rate of currency c on day t, represents the estimated exchange rate of currency c on day t,
[0023] The input of the error correction operator includes the actual value of the exchange rate matrix and the estimated value of the exchange rate matrix.
[0024]
[0025] M E is the actual value of the exchange rate matrix, and the matrix size is It means any combination of two currencies from m currencies, n means the number of consecutive days, Indicates the real exchange rate of CNY to USD on day t0;
[0026]
[0027] M e Represents the estimated value of the exchange rate matrix, the matrix size is It means any combination of two currencies from m currencies, n means the number of consecutive days, It represents the estimated exchange rate of currency A to currency B on day t0, where the estimated value of currency A to currency B is
[0028] S2.3. Calculate the adjustment coefficient. The adjusted error is the sum of the index volatility error coefficient multiplied by the index volatility coefficient and the exchange rate estimation error multiplied by the exchange rate estimation error coefficient. The formula is as follows:
[0029] Error=Weight wave *Error wave +Weight exchange *Error exchange
[0030] S3. Build a sample and exchange rate prediction LSTM model, predict exchange rate changes based on historical data, and train and evaluate the exchange rate prediction model, including:
[0031] S3.1. Split the historical exchange rate data samples into training set and test set in a ratio of 3:1, where feature X is all valid feature data from day T to day T+30, and label Y is the real exchange rate on day T+31;
[0032] S3.2. The model selects a 2-layer LSTM model, using MSELoss. The input data is all valid feature data from T to T+30. The model output is the predicted exchange rate on T+31, and the model reference value is the actual exchange rate on T+31.
[0033] S3.3. Perform model training and evaluation based on the training set and test set, optimize model parameters, and reduce model prediction error;
[0034] S4. Check the results of the exchange rate prediction LSTM model and determine whether to issue a risk warning, including:
[0035] S4.1. Calculate the index inflection point and form an index inflection point set
[0036] Set IndexChangePoint = {Date t ,if|i t+1 -i t |>threshold IndexChangePoint}
[0037] This process represents the step of collecting dates that exceed the index inflection point threshold;
[0038] S4.2. Calculate the inflection point of the delivery volume and form a set of inflection points of the delivery volume
[0039] Set SupplyChangePoint = {Date t ,if|s t+1 -s t |>threshold SupplyChangePoint}
[0040] This process means that the set of dates that exceed the inflection point threshold of the delivery volume will be counted;
[0041] S4.3. Calculation of Fluctuation Inflection Point Registration Score
[0042] Score 拐点配准得分 =len(Set 指数拐点 ∩Set 投放量拐点 ) / len(Set 指数拐点 )
[0043] This process represents the intersection ratio of the index inflection point date set and the delivery volume inflection point set;
[0044] S4.4. If the absolute value of the volatility inflection point matching score is greater than 0.015, it indicates that there is a risk of volatility in the foreign exchange market and an early warning will be issued; otherwise, no early warning will be issued.
[0045] Preferably, step S3.3 of the method of the present invention is as follows: during the training process, the back propagation algorithm is used to calculate the error between the output result predicted by the model and the original true result based on the test set, the model parameters are iteratively updated based on the goal of reducing the error, and the best set of model parameters are selected during the iteration process to minimize the model prediction error and complete the training of the exchange rate model. During the evaluation process, the error evaluation calculation is performed based on the trained model parameters brought into the test set to ensure that the error performance of the model on the test set is basically consistent with that on the training set.
[0046] Compared with the prior art, the present invention has the following advantages:
[0047] By obtaining historical business data, including but not limited to the exchange rate closing price, the US dollar index, the Japanese yen exchange rate, the exchange rate closing price, the offshore exchange rate closing price, the Nasdaq Composite Index, the gold price, the emerging market currency index, the highest exchange rate, the lowest exchange rate, the middle exchange rate, and the onshore and offshore exchange rate spreads, the model in the present invention can be used to determine the exchange rate fluctuations of the day and whether there is a risk of abnormal fluctuations. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 , is the overall workflow diagram of the present invention;
[0049] Figure 2 , is a flow chart of data processing of the present invention;
[0050] Figure 3 , is a flow chart of constructing an exchange rate model according to the present invention;
[0051] Figure 4 , is a schematic diagram of effective feature screening according to an embodiment of the present invention;
[0052] Figure 5 , is a schematic diagram of predicted interest rate fluctuations and actual interest rate fluctuations according to an embodiment of the present invention;
[0053] Figure 6 , is a schematic diagram of the optimization process of an embodiment of the present invention. DETAILED DESCRIPTION
[0054] In order to make the purpose, principle and structure of the present invention more clear, it is further described below in conjunction with the drawings and specific embodiments.
[0055] This embodiment provides a foreign exchange market risk quantification and early warning method based on a long short-term memory model, comprising the following steps:
[0056] Step 1: Obtain historical feature data that affects exchange rate risk, derive features based on the original data, perform feature screening, and construct a data set.
[0057] Step (1-1) obtains domestic and foreign macroeconomic data, micro exchange rate data, micro liquidity data, and micro market sentiment data from the Wind database. The macro characteristic data include but are not limited to the Shanghai Composite Index, the Standard & Poor's Index, the Dow Jones Industrial Average, the Nasdaq Composite Index, etc.; the micro liquidity data include but are not limited to the offshore RMB spot spread, the onshore RMB spot spread, etc.; the micro market sentiment data include but are not limited to the gold price panic index, etc.
[0058] Step (1-2) selects important currencies according to the share of currencies in China's monetary policy basket, including RMB (CNY), US dollar (USD), Australian dollar (AUD), Euro (EUR), British pound (GBP), Hong Kong dollar (KHD), Japanese yen (JPY), Korean won (KRW), Ruble (RUB), Thai won (THB), to form an important currency set C, which is expressed as follows:
[0059] C={CNY,USD,AUD,EUR,GBP,HKD,JPY,KRW,RUB,THB}
[0060] Steps (1-3) construct the foreign exchange market characteristic matrix based on the selected important currency set as follows:
[0061]
[0062] M I To construct the foreign exchange market characteristic matrix, the matrix size is m×n, m represents the number of selected currency types, and n represents the number of selected days. represents the currency characteristics of CNY at time t0, It can represent CNY from time t0 to t n characteristic trends.
[0063] Step (1-4) derives features based on the original data. The selected original data is derived by subtracting the previous value from the next value and dividing the previous value from the next value, which are indicated by the suffixes _diff and _div respectively.
[0064] Steps (1-5) select highly correlated features based on the Pearson correlation coefficient. Among the 91 valid features, there are 10 highly correlated features, all of which are liquidity and market sentiment related factors.
[0065] Step 2: Construct a stabilization operator and calculate the adjustment coefficient to avoid inaccurate risk warnings caused by drastic fluctuations in high-weight currencies themselves.
[0066] Step (2-1) designs a stabilization operator to characterize the fluctuation of currency in continuous time, which is defined as follows:
[0067]
[0068] Where m represents the number of currencies, c represents the specific currency, and t represents the tth day. Represents the estimated index value of currency c on day t.
[0069] Step (2-2) designs an error correction operator to characterize the prediction error. The calculation process is:
[0070]
[0071] Where m represents the number of currencies, n represents the number of days for statistics, c represents the specific currency, and t represents the tth day. represents the real exchange rate of currency c on day t, represents the estimated exchange rate of currency c on day t.
[0072] The input of the error correction operator includes the actual value of the exchange rate matrix and the estimated value of the exchange rate matrix.
[0073]
[0074] M E is the actual value of the exchange rate matrix, and the matrix size is It means any combination of two currencies from m currencies, n means the number of consecutive days, Indicates the real exchange rate of CNY to USD on day t0.
[0075]
[0076] M e Represents the estimated value of the exchange rate matrix, the matrix size is It means any combination of two currencies from m currencies, n means the number of consecutive days, represents the estimated exchange rate of A to B on day t0.
[0077] The estimated exchange value of currency A to currency B is
[0078] Step (2-3) calculates the adjustment coefficient. The adjusted error is the sum of the index volatility error coefficient multiplied by the index volatility coefficient and the exchange rate estimation error multiplied by the exchange rate estimation error coefficient. The formula is as follows:
[0079] Error=Weight wave *Error wave +Weight exchange *Error exchange
[0080] Step 3: Build a sample and exchange rate prediction LSTM model, predict exchange rate changes based on historical data, and train and evaluate the exchange rate prediction model.
[0081] Step (3-1) splits the historical exchange rate data samples into a training set and a test set in a ratio of 3:1, where feature X is all valid feature data from day T to day T+30, and label Y is the real exchange rate on day T+31.
[0082] In step (3-2), a 2-layer LSTM model is selected, using MSELoss. The input data is all valid feature data from T to T+30. The model output is the predicted exchange rate on T+31, and the model reference value is the actual exchange rate on T+31.
[0083] Step (3-3) performs model training and evaluation based on the training set and test set to optimize model parameters and reduce model prediction error.
[0084] During the training process, the back propagation algorithm is used based on the test set to calculate the error between the output results predicted by the model and the original true results. The model parameters are iteratively updated based on the goal of reducing the error. The best set of model parameters is selected during the iteration process to minimize the model prediction error and complete the training of the exchange rate model.
[0085] During the evaluation process, the trained model parameters are brought into the test set for error evaluation calculation to ensure that the error performance of the model on the test set is basically consistent with that on the training set.
[0086] Step 4: Use volatility to test the results of the exchange rate prediction LSTM model to determine whether to issue a risk warning.
[0087] Step (4-1) calculates the index inflection point and forms an index inflection point set
[0088] Set IndexC hangePoint = {Date t ,if|i t+1 -i t |>threshold IndexC hangePoint}
[0089] This procedure represents the step of collecting dates that will count the number of dates that exceed the index inflection point threshold.
[0090] Step (4-2) calculates the inflection point of the delivery volume and forms a set of inflection points of the delivery volume:
[0091] Set SupplyC hangePoint = {Date t ,if|s t+1 -s t |>threshld SupplyC hangePoint}
[0092] This process means that a set of dates that exceed the delivery volume inflection point threshold will be counted.
[0093] Step (4-3) calculates the fluctuation inflection point registration score:
[0094] Score 拐点配准得分 =len(Set 指数拐点 ∩Set 投放量拐点 ) / len(Set 指数拐点 )
[0095] This process represents the intersection ratio of the index inflection point date set and the delivery volume inflection point set.
[0096] Step (4-4) If the absolute value of the volatility inflection point registration score is greater than 0.015, it indicates that there is a volatility risk in the foreign exchange market and an early warning is issued; otherwise, no early warning is issued.
[0097] The following is an example of the implementation of the foreign exchange market risk quantification and early warning method based on the long-term and short-term memory model (see Figure 1-3 ):
[0098] (1) Wind’s domestic and international macroeconomic data, micro exchange rate data, micro liquidity data, and micro market sentiment data were selected, including 345 macro characteristic data, mainly including the two categories of RMB value and USD value, and 46 micro characteristic data, mainly including the two categories of liquidity and market sentiment.
[0099] (2) The 391 feature data are cleaned and mean-filled for outliers and null values. Feature data with a time period of 31 days are selected to construct a sample data set, where the first 30 days are input feature X and the 31st day is the predicted label Y.
[0100] (3) Based on the feature X of the previous 30 days, the feature is derived by subtracting the previous value from the latter value and dividing the former value from the latter value, which are indicated by the suffixes _diff and _div, respectively. There are about 1,200 derived features. Then, the effective features of all the features are screened, and the Pearson correlation coefficient method is used to screen out 91 effective features (correlation coefficient>0.1) and 10 strongly correlated features (correlation coefficient>0.5). (See Figure 4 )
[0101] (4) Define the target task as predicting the exchange rate fluctuation on T+31 by inputting data features from T to T+30, and build the model algorithm network parameters. The model selects the LSTM time series model, the model loss function is the mean square error MSELoss, the network layer is a 2-layer LSTM network, and the optimizer selects the optimization algorithm Adam with adaptive learning rate, and the learning rate is set to 0.001.
[0102] (5) One year of data is selected, and the input samples are constructed by defining slices based on the sample time. The training set and the test set are split in a 3:1 ratio. The training set is used for network model training, and the test set is used for evaluating the effect of the network model.
[0103] (6) Optimize the model: Use L1 regularization to constrain model complexity, reduce overfitting, and improve generalization ability; reduce hidden size, reduce model complexity, and improve generalization ability; select important features, reduce noise interference, and improve generalization ability; analyze the importance of model components and improve model robustness.
[0104] The overall effect of the final model can be found in Figure 5 , the optimization process can be seen in Figure 6 .
[0105] (7) The volatility inflection point registration score is calculated based on the market volatility. When the absolute value is greater than 0.015, it indicates that there is a risk of volatility in the foreign exchange market and an early warning is issued. Otherwise, no early warning is issued. The exchange rate risk is predicted based on the LSTM time series network model, which can identify and warn in a timely manner, laying the foundation for effective observation and early warning of financial risks.
[0106] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent substitutions or changes according to the technical solutions and novel concepts of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.
Claims
1. A foreign exchange market risk quantification and early warning method based on long-short-term memory model, characterized by The method is as follows: S1. Obtain historical characteristic data that affects exchange rate risk, derive and screen the characteristics based on the original data, and construct a data set, including: S1.
1. Obtain domestic and foreign macroeconomic data, micro exchange rate data, micro liquidity data, and micro market sentiment data through the Wind database; S1.
2. According to the share of currencies in China's monetary policy basket, we select important currencies, including RMB (CNY), US dollar (USD), Australian dollar (AUD), Euro (EUR), British pound (GBP), Hong Kong dollar (KHD), Japanese yen (JPY), Korean won (KRW), Ruble (RUB), Thai won (THB), to form the important currency set C, which is expressed as follows: C={CNY,USD,AUD,EUR,GBP,HKD,JPY,KRW,RUB,THB} S1.
3. Based on the selected important currency set, the foreign exchange market characteristic matrix is constructed as follows: M I The constructed foreign exchange market characteristic matrix has a size of m×n, where m represents the number of selected currencies and n represents the number of selected days. represents the currency characteristics of CNY at time t0, It can represent CNY from time t0 to t n characteristic trends; S1.
4. Derivation of features based on the original data: Derivation of features by subtracting the previous value from the next value and dividing the previous value from the next value, represented by _diff and _div suffixes respectively; S1.
5. Select features with strong correlation based on Pearson correlation coefficient; S2. Construct a stabilization operator and an error correction operator, calculate the adjustment coefficient, and avoid inaccurate risk warning caused by the violent fluctuations of high-weight currencies themselves, including: S2.
1. Design a stabilization operator to characterize the volatility of currency in continuous time, defined as follows: Where m represents the number of currencies, c represents the specific currency, and t represents the tth day. represents the estimated index value of currency c on day t; S2.
2. Design an error correction operator to characterize the prediction error. The calculation process is: Where m represents the number of currencies, n represents the number of days for statistics, c represents the specific currency, and t represents the tth day. represents the real exchange rate of currency c on day t, represents the estimated exchange rate of currency c on day t, The input of the error correction operator includes the actual value of the exchange rate matrix and the estimated value of the exchange rate matrix. M E is the actual value of the exchange rate matrix, and the matrix size is It means any combination of two currencies from m currencies, n means the number of consecutive days, Indicates the real exchange rate of CNY to USD on day t0; M e Represents the estimated value of the exchange rate matrix, the matrix size is It means any combination of two currencies from m currencies, n means the number of consecutive days, represents the estimated exchange rate of A to B on day t0, The estimated exchange value of currency A to currency B is S2.
3. Calculate the adjustment coefficient. The adjusted error is the sum of the index volatility error coefficient multiplied by the index volatility coefficient and the exchange rate estimation error multiplied by the exchange rate estimation error coefficient. The formula is as follows: Error=Weight wave *Error wave +Weight exchange *Error exchange S3. Build a sample and exchange rate prediction LSTM model, predict exchange rate changes based on historical data, and train and evaluate the exchange rate prediction model, including: S3.
1. Split the historical exchange rate data samples into training set and test set in a ratio of 3:1, where feature X is all valid feature data from day T to day T+30, and label Y is the real exchange rate on day T+31; S3.
2. The model selects a 2-layer LSTM model, using MSELoss. The input data is all valid feature data from T to T+30. The model output is the predicted exchange rate on T+31, and the model reference value is the actual exchange rate on T+31. S3.
3. Perform model training and evaluation based on the training set and test set, optimize model parameters, and reduce model prediction error; S4. Check the results of the exchange rate prediction LSTM model and determine whether to issue a risk warning, including: S4.
1. Calculate the index inflection point and form an index inflection point set Set IndexC hangePoint ={Bate t ,if|i t+1 -i t |>thresold IndexC hangePoint } This process represents the step of collecting dates that exceed the index inflection point threshold; S4.
2. Calculate the inflection point of the delivery volume and form a set of inflection points of the delivery volume Set SupplyC hangePoint ={Date t ,if|s t+1 -s t |>thresold SupplyC hangePoint } This process means that the set of dates that exceed the inflection point threshold of the delivery volume will be counted; S4.
3. Calculation of Fluctuation Inflection Point Registration Score Score 拐点配准得分 =len(Set 指数拐点 ∩Set 投放量拐点 ) / len(Set 指数拐点 ) This process represents the intersection ratio of the index inflection point date set and the delivery volume inflection point set. S4.
4. If the absolute value of the volatility inflection point matching score is greater than 0.015, it indicates that there is a risk of volatility in the foreign exchange market and an early warning will be issued; otherwise, no early warning will be issued.
2. A foreign exchange market risk quantification and early warning method based on long short-term memory model as claimed in claim 1, characterized in that The method step S3.3 is specifically as follows: during the training process, the back propagation algorithm is used based on the test set to calculate the error between the output result predicted by the model and the original true result, the model parameters are iteratively updated based on the goal of reducing the error, and the best set of model parameters are selected from hundreds of rounds of iterations to minimize the model prediction error and complete the training of the exchange rate model. During the evaluation process, the trained model parameters are brought into the test set for error evaluation calculation to ensure that the error performance of the model on the test set is basically consistent with that on the training set.
Citation Information
Cited By
Method for realizing exchange rate prediction profit maximization based on hybrid prediction model
CN119991289A
