General method and system for calculating custom indicators in the financial field
Through QLEXpress script engine analysis and caching technology, the problem that traditional financial data platforms cannot support complex custom indicator calculations is solved, and high-precision and high-performance financial data processing is achieved to meet the diverse analysis needs in the financial field.
Patent Information
- Application Number
- CN202411252487.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2044-09-09
AI Technical Summary
Traditional financial data platforms cannot support complex custom indicator calculation logic, especially if condition judgment and null value judgment, and cannot select the accuracy of calculation results as needed, which cannot meet the diverse analysis needs in the financial field.
The QLEXpress script engine dynamically analyzes the custom indicator expressions entered by users, supports high-precision calculations of numerical, Boolean and other data types, and combines pre-checks and local cache technology to generate instruction sets and perform type conversion and precision processing.
It realizes custom indicator computing support for complex scenarios, improves computing performance and accuracy, and meets customized analysis needs in the financial field.
Smart Images

Figure CN118778926B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of financial data, and in particular, to a general method and system for calculating custom indicators in the financial field, and more particularly, to a general processing method for extracting indicator data for custom calculation. Background Art
[0002] Practitioners in various segments of the financial industry have diverse calculation and viewing needs for indicator data. The basic indicator data provided by traditional data platforms has the problem of insufficient flexibility and cannot support customized analysis needs in many fields. If the user needs to customize the indicator calculation logic according to the usage scenario, the prior art only supports a single calculation process for the basic indicator data, such as mathematical formula calculation or aggregate function calculation, and cannot support complex scenarios that combine logical processing with the calculation process such as if condition judgment and null value judgment, and the user cannot select the result accuracy of the indicator calculation as needed. In response to these defects, the present invention can dynamically parse the custom indicator expression input by the user, is compatible with various data types such as numeric and Boolean during the execution of the expression, supports high-precision calculation, and performs calculation result accuracy processing according to user settings. Summary of the invention
[0003] In view of the defects in the prior art, the purpose of the present invention is to provide a general method and system for calculating custom indicators in the financial field.
[0004] According to the present invention, a general method for calculating a custom indicator in the financial field is provided, comprising:
[0005] Step S1: pre-check the expression text of the indicator calculation to be calculated to obtain the corresponding calculation result type;
[0006] Step S2: obtaining a corresponding instruction set based on the expression text of the indicator calculation to be currently calculated;
[0007] Step S3: The QLExpress script engine performs indicator calculations based on basic indicator data and corresponding instruction sets;
[0008] Step S4: According to the calculation result type and calculation accuracy requirements, the calculation result is converted into a type and the numerical precision is processed.
[0009] Preferably, the step S1 adopts: using the word segmenter in QLExpress to perform word segmentation processing on the indicator calculation expression to be operated to obtain the word segmentation result; judging the calculation result type of the expression according to the word segmentation result; if the outermost layer in the word segmentation result is a null judgment logic function, the calculation result type is Boolean; if the outermost layer of the word segmentation result is not a null judgment logic function and a mixed percentage operation is performed, the calculation result type is percentage; the remaining cases are numerical.
[0010] Preferably, the pre-checking of the expression text of the indicator calculation to be currently calculated also includes: obtaining the expression text of the user-side indicator calculation and pre-checking it, including: checking whether the basic indicator parameter name and function name contained in the indicator calculation expression text are legal, and checking whether the indicator calculation expression text complies with grammatical rules;
[0011] The verification indicator calculation expression text contains basic indicator parameter names and function names, including:
[0012] Use the word segmenter in QLExpress to segment the verification indicator calculation expression, and compare the segmentation result with the existing basic indicator parameter name and function name. If the segmentation result is inconsistent with the existing basic indicator parameter name and function name, it is considered that the basic indicator parameter name and function name contained in the current verification indicator calculation expression text are illegal;
[0013] The verification indicator calculation expression text complies with the grammatical rules, including: performing abstract syntax tree matching on the word segmentation result. If there are unpaired matching brackets and unmatched function input parameters, and the syntax matching cannot be completed, then it is considered that the current verification indicator calculation expression text does not comply with the grammatical rules.
[0014] Preferably, the step S2 adopts: determining whether the instruction set corresponding to the current indicator calculation expression is already in the local cache; if so, obtaining the instruction set corresponding to the current indicator calculation expression in the local cache; if not, using the QLExpress script engine to parse the current indicator calculation expression, obtaining the instruction set, and storing it in the local cache.
[0015] Preferably, the method of using the QLExpress script engine to parse the current indicator calculation expression, obtain the instruction set, and store it in the local cache includes:
[0016] Step S2.1: Obtain a defined rule set, the rule set including: calculation function, aggregation function and logic judgment method;
[0017] Step S2.2: Connecting the rule set to the QLExpress scripting engine;
[0018] Step S2.3: Use the QLExpress script engine to parse the expression text of the indicator calculation and generate an instruction set; and store the generated instruction set in the local cache.
[0019] Preferably, the step S2.2 adopts: the rule set is added to the QLExpress script engine using an extension interface.
[0020] Preferably, the method further comprises: setting a cache storage upper limit and a cache elimination strategy for the local cache;
[0021] The cache elimination strategy is to remove data that meets preset requirements from the cache when the cache storage space reaches the storage upper limit.
[0022] According to the present invention, a general system for calculating custom indicators in the financial field is provided, comprising:
[0023] Module M1: Pre-check the expression text of the indicator calculation to be calculated and obtain the corresponding calculation result type;
[0024] Module M2: Obtain the corresponding instruction set based on the expression text of the indicator calculation to be currently calculated;
[0025] Module M3: QLExpress script engine performs indicator calculations based on basic indicator data and corresponding instruction sets;
[0026] Module M4: According to the calculation result type and calculation accuracy requirements, the calculation result is converted into type and numerical precision is processed.
[0027] Preferably, the module M1 adopts: using the word segmenter in QLExpress to perform word segmentation processing on the indicator calculation expression to be calculated to obtain the word segmentation result; judging the type of the calculation result of the expression according to the word segmentation result; if the outermost layer in the word segmentation result is a null judgment logic function, the calculation result type is Boolean; if the outermost layer of the word segmentation result is not a null judgment logic function and a mixed percentage operation is performed, the calculation result type is percentage type; the remaining cases are numerical types;
[0028] The pre-checking of the expression text of the indicator calculation to be currently calculated also includes: obtaining the expression text of the user-side indicator calculation and pre-checking it, including: checking whether the basic indicator parameter name and function name contained in the indicator calculation expression text are legal, and checking whether the indicator calculation expression text complies with the grammatical rules;
[0029] The verification indicator calculation expression text contains basic indicator parameter names and function names, including:
[0030] Use the word segmenter in QLExpress to segment the verification indicator calculation expression, and compare the segmentation result with the existing basic indicator parameter name and function name. If the segmentation result is inconsistent with the existing basic indicator parameter name and function name, it is considered that the basic indicator parameter name and function name contained in the current verification indicator calculation expression text are illegal;
[0031] The verification indicator calculation expression text complies with the grammatical rules, including: performing abstract syntax tree matching on the word segmentation result. If there are unpaired matching brackets and unmatched function input parameters, and the syntax matching cannot be completed, then it is considered that the current verification indicator calculation expression text does not comply with the grammatical rules.
[0032] Preferably, the module M2 adopts: judging whether the instruction set corresponding to the current indicator calculation expression is already in the local cache, if it is, obtaining the instruction set corresponding to the current indicator calculation expression in the local cache; if it is not, parsing the current indicator calculation expression using the QLExpress script engine, obtaining the instruction set, and storing it in the local cache;
[0033] The QLExpress script engine is used to parse the current indicator calculation expression, obtain the instruction set, and store it in the local cache, including:
[0034] Module M2.1: Obtain a defined rule set, which includes: calculation functions, aggregation functions, and logical judgment methods;
[0035] Module M2.2: Connecting the rule set to the QLExpress scripting engine;
[0036] Module M2.3: Use the QLExpress script engine to parse the expression text of the indicator calculation and generate an instruction set; and store the generated instruction set in the local cache;
[0037] The module M2.2 adopts: the rule set is added to the QLExpress script engine using the extension interface;
[0038] The method further includes: setting a cache storage upper limit and a cache elimination strategy for the local cache;
[0039] The cache elimination strategy is to remove data that meets preset requirements from the cache when the cache storage space reaches the storage upper limit.
[0040] Compared with the prior art, the present invention has the following beneficial effects:
[0041] 1. In terms of calculation method, the present invention can support mixed processing of calculation function, aggregation function and logical judgment;
[0042] 2. In terms of computing performance, the present invention uses a customized cache strategy to store the compiled instruction set of the custom indicator calculation expression locally, which reduces the time consumption of the compilation stage when batch calculating custom indicators and significantly improves the computing performance;
[0043] 3. In terms of calculation accuracy, the present invention supports users to select the result accuracy of indicator calculation as needed, thereby meeting the accuracy requirements of users in the financial field for data processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0045] Figure 1 Pre-validate the flow chart for custom indicator expressions.
[0046] Figure 2 Calculates the flow chart for a custom indicator. DETAILED DESCRIPTION
[0047] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.
[0048] Example 1
[0049] In order to meet the diverse secondary processing needs of financial practitioners for basic indicators, the present invention supports the mixed use of multiple judgment logics, aggregation formulas and calculation functions to customize indicator processing logic. A general method and system suitable for calculating customized indicators in the financial field is provided, and the calculation result display accuracy can be set to adapt to a variety of complex analysis scenarios.
[0050] According to a general method for calculating a custom indicator in the financial field provided by the present invention, Figures 1 to 2 As shown, including:
[0051] Step 1: Set up a rule set, which includes common calculation functions, aggregation functions, and logical judgment methods;
[0052] Step 2: Introduce the QLExpress scripting engine, and add the calculation functions, aggregation functions, and logic judgment methods in the defined Java class to the QLExpress scripting engine using the method extension interface provided by the QLExpress scripting engine;
[0053] Step 3: Customize the local cache, set the cache storage limit and cache elimination strategy. After the QLExpress script engine parses the expression text of the custom indicator calculation to generate the instruction set and before starting to execute the instruction set, store the instruction set corresponding to the text in the local cache to avoid repeated parsing operations of the same custom indicator calculation text, thereby improving the overall performance of indicator batch calculation;
[0054] Step 4: Get the expression text of the custom indicator calculation entered by the user and perform pre-verification. Only the custom indicator that passes the pre-verification can be saved. Otherwise, the user will be given a corresponding error reminder. While saving the correct and executable custom indicator calculation expression text, the calculation result type of the expression is also given through pre-verification, which is convenient for the page to reasonably display the calculation results later;
[0055] Wherein, step 4 comprises the following steps:
[0056] Step 4.1: First, check whether the basic indicator parameter name and function name contained in the indicator calculation expression are legal. Use the word breaker in QLExpress to word segment the expression, and compare the word segmentation result with the existing basic indicator parameter name and function name. If there are illegal basic indicator parameter names and illegal function names in the word segmentation result, remind the user not to enter illegal basic indicator parameters and to use the function correctly.
[0057] Step 4.2: Secondly, check whether the indicator calculation expression meets the grammatical specifications. Perform AST (abstract syntax tree) matching on the word segmentation results obtained in step 4.1. If there are unmatched brackets, unmatched function input parameters, etc., and the syntax matching cannot be completed, the user is reminded to modify the expression to meet the grammatical specifications;
[0058] Step 4.3: If the indicator calculation expression passes the pre-check, the calculation result type of the expression is determined based on the word segmentation result in step 4.1. If the outermost layer of the word segmentation result is a null judgment logic function, the calculation result type is Boolean; if the outermost layer of the word segmentation result is not a null judgment logic function and a mixed percentage operation is performed, the calculation result type is percentage; the remaining cases are numeric;
[0059] Step 4.4: Finally, save the indicator calculation expression that has passed the pre-verification, and save the calculation result type obtained in step 4.3;
[0060] Step 5: After the user chooses to extract basic indicator data, the basic indicator data is used as the input parameter of the custom indicator calculation expression for operation processing, and it is determined whether the compilation instruction set corresponding to the indicator calculation expression is already in the local cache. If the compilation instruction set cache already exists, the compilation instruction set is taken out from the local cache, combined with the input parameter data, and input into the QLExpress script engine for operation; if the compilation instruction set cache does not exist, the QLExpress script engine is first used for parsing operations, and after obtaining the compilation instruction set and storing it in the local cache, the compilation instruction set and the basic indicator data are input into the QLExpress script engine for operation;
[0061] Step 6: According to the calculation result type and the precision set by the user, perform type conversion and numerical precision processing on the calculation result.
[0062] The present invention also provides a general system for calculating custom indicators in the financial field. The general system for calculating custom indicators in the financial field can be implemented by executing the process steps of the general method for calculating custom indicators in the financial field, that is, those skilled in the art can understand the general method for calculating custom indicators in the financial field as a preferred implementation of the general system for calculating custom indicators in the financial field.
[0063] Example 2
[0064] Embodiment 2 is a preferred embodiment of Embodiment 1
[0065] Step 1. Define the four arithmetic operations of addition, subtraction, multiplication and division, ABS(), EXP(), SQRT(), LOG(), LN(), AVG(), MAX(), MIN(), IF(), ISBLANK() and other commonly used calculation functions, aggregation functions and logical judgment methods in the Java backend service.
[0066] Step 2: Introduce the QLExpress script engine and load the calculation functions, aggregation functions, and logical judgment methods in the defined Java class into the QLExpress script engine:
[0067] (1) For the four arithmetic operations of addition, subtraction, multiplication and division, you first need to inherit the basic operator class Operator in the QLExpress script engine, then implement the specific calculation logic in the reserved execution method, and finally use the operator replacement interface in the QLExpress script engine to replace the built-in four arithmetic operators with custom four arithmetic classes; (2) For commonly used calculation functions, aggregation functions and logical judgment methods such as ABS(), EXP(), SQRT(), LOG(), LN(), AVG(), MAX(), MIN(), IF(), ISBLANK(), use the method extension interface provided by the QLExpress script engine to add them to the QLExpress script engine.
[0068] Step 3: Customize the local cache, set the cache storage limit to 10,000, set the cache elimination strategy, and store the instruction set corresponding to the text in the local cache after the QLExpress script engine parses the expression text of the custom indicator calculation to generate the instruction set and before starting to execute the instruction set;
[0069] Step 4: Get the expression text of the custom indicator calculation entered by the user and perform pre-verification:
[0070] (1) First, check whether the basic indicator name and function name contained in the indicator calculation expression are legal. If not, the user will be prompted with "illegal characters";
[0071] (2) Secondly, check whether the indicator calculation expression conforms to the grammatical specifications. If not, the user will be prompted with "syntax error";
[0072] (3) If the indicator calculation expression passes the pre-verification, the expression entered by the user is saved, and the calculation result type of the expression is also saved, that is, whether it is numeric, Boolean or percentage.
[0073] Step 5: After the user chooses to extract basic indicator data, the basic indicator data is used as the input parameter of the custom indicator calculation expression for operation processing:
[0074] (1) First check whether the indicator calculation expression contains the percentage symbol "%". If it does, replace the "%" with the equivalent calculation " / 100" before calculation;
[0075] (2) Determine whether the compilation instruction set corresponding to the indicator calculation expression is already in the local cache. If the compilation instruction set cache already exists, take out the compilation instruction set from the local cache, combine it with the input parameter data, and input it into the QLExpress script engine for calculation. If the compilation instruction set cache does not exist, first use the QLExpress script engine to perform a parsing operation, obtain the compilation instruction set and store it in the local cache, and then input the compilation instruction set and the input parameter data into the QLExpress script engine for calculation.
[0076] Step 6: According to the calculation result type and the precision set by the user, perform type conversion and numerical precision processing on the calculation result:
[0077] (1) If the calculation result type is numeric, the result will be converted to a numeric value with the corresponding precision according to the precision set by the user;
[0078] (2) If the calculation result is a Boolean type, it is converted to Boolean TRUE or Boolean FALSE depending on whether the result value is 1 or 0;
[0079] (3) If the calculation result is a percentage, convert the result into a percentage.
[0080] Those skilled in the art know that, in addition to realizing the system and its various devices, modules, and units provided by the present invention in a purely computer-readable program code, it is entirely possible to realize the same functions in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, the system and its various devices, modules, and units provided by the present invention can be considered as a hardware component, and the devices, modules, and units included therein for realizing various functions can also be regarded as structures within the hardware component; the devices, modules, and units for realizing various functions can also be regarded as both software modules for realizing the method and structures within the hardware component.
[0081] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. A general method for calculating custom indicators in the financial field, characterized in that: include: Step S1: pre-check the expression text of the indicator calculation to be calculated to obtain the corresponding calculation result type; Step S2: obtaining a corresponding instruction set based on the expression text of the indicator calculation to be currently calculated; Step S3: The QLExpress script engine performs indicator calculations based on basic indicator data and corresponding instruction sets; Step S4: According to the calculation result type and calculation accuracy requirements, the calculation result is converted into a type and the numerical precision is processed; The step S1 adopts: using the word segmenter in QLExpress to perform word segmentation processing on the indicator calculation expression to be calculated to obtain the word segmentation result; judging the type of the calculation result of the expression according to the word segmentation result; if the outermost layer in the word segmentation result is a null judgment logic function, the calculation result type is Boolean; if the outermost layer of the word segmentation result is not a null judgment logic function and a mixed percentage operation is performed, the calculation result type is percentage type; the remaining cases are numerical type; The pre-checking of the expression text of the indicator calculation to be currently calculated also includes: obtaining the expression text of the user-side indicator calculation and pre-checking it, including: checking whether the basic indicator parameter name and function name contained in the indicator calculation expression text are legal, and checking whether the indicator calculation expression text complies with the grammatical rules; The verification indicator calculation expression text contains basic indicator parameter names and function names, including: Use the word segmenter in QLExpress to segment the verification indicator calculation expression, and compare the segmentation result with the existing basic indicator parameter name and function name. If the segmentation result is inconsistent with the existing basic indicator parameter name and function name, it is considered that the basic indicator parameter name and function name contained in the current verification indicator calculation expression text are illegal; The verification indicator calculation expression text complies with the grammatical rules, including: performing abstract syntax tree matching on the word segmentation result. If there are unpaired matching brackets and unmatched function input parameters, and the syntax matching cannot be completed, then it is considered that the current verification indicator calculation expression text does not comply with the grammatical rules.
2. The general method for calculating custom indicators in the financial field according to claim 1, characterized in that: The step S2 adopts: judging whether the instruction set corresponding to the current indicator calculation expression is already in the local cache, if it exists, obtaining the instruction set corresponding to the current indicator calculation expression in the local cache; if it does not exist, using the QLExpress script engine to parse the current indicator calculation expression, obtain the instruction set, and store it in the local cache.
3. The general method for calculating custom indicators in the financial field according to claim 2, characterized in that: The QLExpress script engine is used to parse the current indicator calculation expression, obtain the instruction set, and store it in the local cache, including: Step S2.1: Obtain a defined rule set, the rule set including: calculation function, aggregation function and logic judgment method; Step S2.2: Connecting the rule set to the QLExpress scripting engine; Step S2.3: Use the QLExpress script engine to parse the expression text of the indicator calculation and generate an instruction set; and store the generated instruction set in the local cache.
4. The general method for calculating custom indicators in the financial field according to claim 3, characterized in that: The step S2.2 adopts: the rule set is added to the QLExpress script engine using the extension interface.
5. The general method for calculating custom indicators in the financial field according to claim 2, characterized in that: The method further includes: setting a cache storage upper limit and a cache elimination strategy for the local cache; The cache elimination strategy is to remove data that meets preset requirements from the cache when the cache storage space reaches the storage upper limit.
6. A general system for calculating custom indicators in the financial field, characterized in that: include: Module M1: Pre-check the expression text of the indicator calculation to be calculated and obtain the corresponding calculation result type; Module M2: Obtain the corresponding instruction set based on the expression text of the indicator calculation to be currently calculated; Module M3: QLExpress script engine performs indicator calculations based on basic indicator data and corresponding instruction sets; Module M4: According to the calculation result type and calculation accuracy requirements, the calculation result is converted into type and the numerical precision is processed; The module M1 adopts: using the word segmenter in QLExpress to perform word segmentation processing on the indicator calculation expression to be operated to obtain the word segmentation result; judging the type of the calculation result of the expression according to the word segmentation result; if the outermost layer in the word segmentation result is a null judgment logic function, the calculation result type is Boolean; if the outermost layer of the word segmentation result is not a null judgment logic function and a mixed percentage operation is performed, the calculation result type is percentage type; the remaining cases are numerical type; The pre-checking of the expression text of the indicator calculation to be currently calculated also includes: obtaining the expression text of the user-side indicator calculation and pre-checking it, including: checking whether the basic indicator parameter name and function name contained in the indicator calculation expression text are legal, and checking whether the indicator calculation expression text complies with the grammatical rules; The verification indicator calculation expression text contains basic indicator parameter names and function names, including: Use the word segmenter in QLExpress to segment the verification indicator calculation expression, and compare the segmentation result with the existing basic indicator parameter name and function name. If the segmentation result is inconsistent with the existing basic indicator parameter name and function name, it is considered that the basic indicator parameter name and function name contained in the current verification indicator calculation expression text are illegal; The verification indicator calculation expression text complies with the grammatical rules, including: performing abstract syntax tree matching on the word segmentation result. If there are unpaired matching brackets and unmatched function input parameters, and the syntax matching cannot be completed, then it is considered that the current verification indicator calculation expression text does not comply with the grammatical rules.
7. The general system for calculating custom indicators in the financial field according to claim 6, characterized in that: The module M2 adopts: judging whether the instruction set corresponding to the current indicator calculation expression is already in the local cache, if it is, obtaining the instruction set corresponding to the current indicator calculation expression in the local cache; if it is not, parsing the current indicator calculation expression using the QLExpress script engine, obtaining the instruction set, and storing it in the local cache; The QLExpress script engine is used to parse the current indicator calculation expression, obtain the instruction set, and store it in the local cache, including: Module M2.1: Obtain a defined rule set, which includes: calculation functions, aggregation functions, and logical judgment methods; Module M2.2: Connecting the rule set to the QLExpress scripting engine; Module M2.3: Use the QLExpress script engine to parse the expression text of the indicator calculation and generate an instruction set; and store the generated instruction set in the local cache; The module M2.2 adopts: the rule set is added to the QLExpress script engine using the extension interface; The method further includes: setting a cache storage upper limit and a cache elimination strategy for the local cache; The cache elimination strategy is to remove data that meets preset requirements from the cache when the cache storage space reaches the storage upper limit.
