Online pricing method, device, equipment and storage medium

By constructing Reverse Polish Notation and generating Java bytecode files, the slow speed caused by the complex calculation logic of the online pricing interpretation engine was solved, achieving a faster calculation speed.

CN114253526BActive Publication Date: 2025-11-07GLODON CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111571671.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-21
Publication Date
2025-11-07
Estimated Expiration
2041-12-21

AI Technical Summary

Technical Problem

During online pricing, the computational logic of the interpreter and execution engine is complex, resulting in slow operation.

Method used

By constructing the Reverse Polish Notation of the target formula statement, a Java bytecode file is generated and loaded as a Java class, which is then stored in a cache for direct calling, avoiding the tedious operation of interpreted execution.

Benefits of technology

The calculation logic has been simplified, and the speed of online pricing has been improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114253526B_ABST
    Figure CN114253526B_ABST
Patent Text Reader

Abstract

The application relates to an online pricing method, device, equipment and storage medium, and particularly relates to the field of financial calculation. The method comprises the following steps: obtaining target transaction data and a target formula statement; when it is detected that a JAVA class of the target formula statement exists in a cache, calling the JAVA class corresponding to the target formula statement, processing the target transaction data to obtain a target pricing result, and the JAVA class corresponding to the target formula statement is obtained by loading a JAVA bytecode file corresponding to the target formula statement; the JAVA bytecode file is generated based on the arrangement order of operators and operation components in a reverse polish expression of the target formula statement. The above scheme separates the compiling process and the calculation process, avoids the tedious operation of interpreting a sentence and then executing the sentence by the computer equipment, simplifies the calculation logic, and improves the operation speed of online pricing.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of financial calculation, in particular to an online pricing method, device, equipment and storage medium. BACKGROUND

[0002] Online pricing is to move the pricing process to the online operation by using Internet technology, which has the characteristics that each place can view the operation at one time, and supports collaborative modification of the pricing file and other advantages.

[0003] In the online pricing calculation process, in addition to the fixed calculation logic, the business of fee composition and fee summary also involves the calculation of the results of specific formulas. At present, in order to realize online pricing, the calculation engine of interpretation execution can be used to calculate the formula and obtain the calculation result. Interpretation execution does not depend on the platform, because the compiler will parse according to different platforms, it directly inputs the source language as the source program, and after interpreting a sentence, it submits the computer to execute a sentence, and does not form a target program.

[0004] In the above scheme, the calculation engine of interpretation execution is used to calculate the formula, and the calculation logic is complex and the running speed is slow. SUMMARY

[0005] The present application provides an online pricing method, device, equipment and storage medium, which improves the operation speed of online pricing. The technical scheme is as follows.

[0006] In one aspect, an online pricing method is provided, which comprises:

[0007] obtaining target transaction data and a target formula statement;

[0008] when it is detected that the JAVA class of the target formula statement exists in the cache, calling the JAVA class corresponding to the target formula statement to process the target transaction data to obtain a target pricing result;

[0009] wherein the JAVA class corresponding to the target formula statement is obtained by loading the JAVA bytecode file corresponding to the target formula statement; and the JAVA bytecode file is generated based on the arrangement order of the operators and the operation components in the reverse polish expression of the target formula statement.

[0010] In another aspect, an online pricing device is provided, which comprises:

[0011] a formula obtaining module, configured to obtain target transaction data and a target formula statement;

[0012] The class calling module is configured to call the JAVA class corresponding to the target formula statement to process the target transaction data to obtain a target pricing result when it is detected that the JAVA class of the target formula statement exists in the cache.

[0013] The JAVA class corresponding to the target formula statement is obtained by loading a JAVA bytecode file corresponding to the target formula statement; and the JAVA bytecode file is generated based on the arrangement order of the operators and the operation components in the reverse polish expression of the target formula statement.

[0014] In a possible implementation, the apparatus further includes:

[0015] The expression obtaining module is configured to mark the operation components and the operators in the target formula statement to obtain a reverse polish expression of the target formula statement when it is detected that the JAVA class corresponding to the target formula statement does not exist in the cache.

[0016] The bytecode file generating module is configured to generate the JAVA bytecode file according to the arrangement order of the operation components and the operators in the reverse polish expression, and load the JAVA bytecode file as the JAVA class corresponding to the target formula statement.

[0017] In a possible implementation, the bytecode file generating module is further configured to,

[0018] When a target operation component is traversed, the operation component is encapsulated as JAVA bytecode and placed in a JAVA bytecode temporary list.

[0019] When a target operator is traversed, the JAVA bytecode corresponding to the target operator is taken out from the JAVA bytecode temporary list, spliced with the JAVA bytecode of the target operator, and placed in the JAVA bytecode temporary list.

[0020] The JAVA bytecode file is generated based on the JAVA bytecode in the JAVA bytecode temporary list obtained by traversing the reverse polish expression.

[0021] In a possible implementation, the reverse polish expression further includes a target function.

[0022] The bytecode file generating module is further configured to,

[0023] When a target function is traversed, the JAVA bytecode corresponding to the target function is taken out from the JAVA bytecode temporary list according to the target function name, and spliced with the JAVA bytecode of the target function to obtain JAVA bytecode in a call function format.

[0024] putting the call function format JAVA bytecode into the JAVA bytecode temporary list.

[0025] In a possible implementation, the apparatus further includes:

[0026] The RPN expression reading module is configured to acquire a target operator in the RPN expression and an operation component corresponding to the target operator.

[0027] The first detection module is configured to detect whether the data type of the operation component matches the execution data type of the target operator, and generate a first error message if the data types do not match.

[0028] In a possible implementation, the apparatus further includes:

[0029] The second detection module is configured to detect whether a function name of the target function exists when the target function exists in the RPN expression, and generate a second error message if the function name does not exist.

[0030] In a possible implementation, the apparatus further includes:

[0031] The function parameter analysis module is configured to acquire a parameter definition quantity of the target function and a parameter call quantity of the target function.

[0032] The third detection module is configured to generate a third error message if the parameter definition quantity of the target function and the parameter call quantity of the target function are different.

[0033] In another aspect, a computer device is provided, the computer device including a processor and a memory, the memory storing at least one instruction, at least one program, a code set, or an instruction set, the at least one instruction, at least one program, code set, or instruction set being loaded and executed by the processor to implement the online pricing method described above.

[0034] In yet another aspect, a computer readable storage medium is provided, the storage medium storing at least one instruction, the at least one instruction being loaded and executed by a processor to implement the online pricing method described above.

[0035] In still another aspect, a computer program product is provided, the computer program product or computer program including computer instructions stored in a computer readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions to cause the computer device to perform the online pricing method described above.

[0036] The technical scheme provided in the application can include the following beneficial effects:

[0037] Before online pricing is performed, the computer device constructs a reverse Polish expression of the target formula statement, so as to represent the operation sequence of the target formula statement; the computer device then compiles and encapsulates the reverse Polish expression into a JAVA bytecode file according to the operation sequence in the reverse Polish expression, and generates a JAVA class corresponding to the JAVA bytecode file to be saved in the cache of the computer device; at this time, when the computer device needs to perform calculation on target transaction data, the JAVA class can be directly called to perform data calculation on the target transaction data, so that the compiling process and the calculation process are separated, the tedious operation of interpreting a sentence and then executing the sentence by the computer device is avoided, the calculation logic is simplified, and the operation speed of online pricing is improved. BRIEF DESCRIPTION OF DRAWINGS

[0038] In order to more clearly illustrate the technical scheme in the specific embodiments or prior art, the drawings needed in the specific embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0039] Figure 1 FIG. 1 is a structural schematic diagram of an online pricing system according to an example embodiment.

[0040] Figure 2 FIG. 2 is a method flowchart of an online pricing method according to an example embodiment.

[0041] Figure 3 FIG. 3 is a method flowchart of an online pricing method according to an example embodiment.

[0042] Figure 4 FIG. 4 shows a conversion flowchart of a reverse Polish expression.

[0043] Figure 5 FIG. 5 shows a flow block diagram of an online pricing method according to an embodiment of the present application.

[0044] Figure 6 FIG. 6 is a structural block diagram of an online pricing device according to an example embodiment.

[0045] Figure 7 FIG. 7 is a schematic diagram of a computer device according to an example embodiment of the present application. DETAILED DESCRIPTION

[0046] The technical solutions of the present application will be described clearly and completely in connection with the drawings. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of the present application.

[0047] It should be understood that the "indication" mentioned in the embodiments of the present application can be direct indication, indirect indication, or an indication of an associated relationship. For example, A indicates B, which can mean that B can be obtained directly through A; or A indirectly indicates B, for example, A indicates C, and B can be obtained through C; or A and B have an associated relationship.

[0048] In the description of the embodiments of the present application, the term "corresponding" can mean a direct or indirect corresponding relationship between the two, or an associated relationship between the two, or an indication and being indicated, configuration and being configured, etc.

[0049] In the embodiments of the present application, "predefined" can be realized by pre-saving corresponding codes, tables or other means for indicating related information in devices (such as terminal devices and network devices), and the specific implementation manner is not limited in the present application.

[0050] The online pricing method provided in the embodiments of the present application can be applied to computer devices with strong data processing capability. For example, the online pricing method provided in the embodiments of the present application can be applied to personal computers, workstations or servers, that is, at least one of the personal computer, the workstation and the server processes the input formula to realize the process of calculating the input data.

[0051] Figure 1 is a structural schematic diagram of an online pricing system according to an exemplary embodiment. The image classification system includes a server 110 and a terminal 120. The terminal 120 and the server 110 communicate data through a communication network, which can be a wired network or a wireless network.

[0052] Optionally, the terminal 120 is installed with an application program with online pricing function, which can be a professional financial application program, a social application program, or an AI application program with formula calculation function, and the embodiments of the present application do not limit this.

[0053] Optionally, the terminal 120 can be a terminal device with a data acquisition component for storing the calculation data input by the user in a data storage module in the terminal 120 according to the input operation of the receiving user; the terminal 120 can also be a terminal device with a data transmission interface for receiving the calculation data collected by the device with the data acquisition component.

[0054] Optionally, the terminal 120 can be a mobile terminal such as a smart phone, a tablet computer, a laptop computer, etc., or a terminal such as a desktop computer, a projection computer, etc., or a smart terminal with a data processing component, and the embodiments of the present application do not limit this.

[0055] The server 110 can be implemented as a server or a server cluster composed of a group of servers, which can be a physical server or a cloud server. In a possible implementation manner, the server 110 is a background server of the application program in the terminal 120.

[0056] In a possible implementation manner of the embodiments of the present application, when the terminal 120 receives the calculation data and the calculation formula input by the user (for example, receives the calculation data and the calculation formula input by the user in the application program), the terminal 120 can send the calculation data and the calculation formula to the background server corresponding to the application program. At this time, the background server can generate the JAVA class corresponding to the calculation formula according to the processing of the calculation formula and save it in the cache, and then call the JAVA class corresponding to the calculation formula to calculate the calculation data, so as to obtain the calculation result. The background server returns the calculation result to the terminal 120 to complete the online pricing process.

[0057] In another possible implementation manner of the embodiments of the present application, when the terminal receives the calculation formula, the terminal 120 directly processes the calculation formula to generate the JAVA bytecode file corresponding to the calculation formula, and loads it into the corresponding JAVA class saved in the cache through JVM, so as to call the JAVA class corresponding to the calculation formula to calculate the calculation data.

[0058] In a possible implementation manner, when the terminal generates the JAVA bytecode file corresponding to the calculation formula, the terminal can send the bytecode file to the background server corresponding to the application program (that is, the professional financial application program) in the terminal, so that other devices can directly obtain the JAVA bytecode file corresponding to the calculation formula from the background server when they need to use the formula, thereby avoiding the repeated processing process of the formula.

[0059] Optionally, the server can be a standalone physical server, a server cluster composed of multiple physical servers, or a distributed system, and can also be a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.

[0060] Optionally, the system can further include a management device for managing the system (such as managing the connection state between each module and the server, etc.), which is connected to the server through a communication network. Optionally, the communication network is a wired network or a wireless network.

[0061] Optionally, the wireless network or wired network uses standard communication technology and / or protocols. The network is usually the Internet, but can also be any other network, including but not limited to a local area network, a metropolitan area network, a wide area network, a mobile, limited or wireless network, a private network or any combination of virtual private networks. In some embodiments, technologies and / or formats including HyperText Markup Language, Extensible Markup Language, etc. are used to represent data exchanged through the network. In addition, all or some links can be encrypted using conventional encryption technologies such as Secure Sockets Layer, Transport Layer Security, Virtual Private Network, Internet Protocol Security, etc. In other embodiments, custom and / or dedicated data communication technologies can be used instead of or in addition to the above data communication technologies.

[0062] Figure 2 is a method flowchart of an online pricing method according to an exemplary embodiment. The method is executed by a computer device, which can be a server or a terminal in an online pricing system as shown in Figure 1 . As shown in Figure 2 , the online pricing method can include the following steps:

[0063] Step 201, obtaining target transaction data and target formula statement.

[0064] When online pricing is needed, a calculation formula is usually involved, at which time the computer device can obtain the target formula statement that needs to be applied when calculating the target transaction data.

[0065] Optionally, the target formula statement is a formula statement in infix expression format.

[0066] Step 202, when it is detected that there is a JAVA class of the target formula statement in the cache, the JAVA class corresponding to the target formula statement is called to process the target transaction data to obtain a target pricing result.

[0067] The JAVA class corresponding to the target formula statement is obtained by loading the JAVA bytecode file corresponding to the target formula statement; the JAVA bytecode file is generated based on the arrangement order of the operators and the operation components in the reverse polish expression of the target formula statement.

[0068] That is, in a possible implementation, the JAVA class generation process corresponding to the target formula statement can be as follows.

[0069] First, the operation components and the operators in the target formula statement are marked, and a reverse polish expression is constructed according to the marking result.

[0070] Before analyzing the target formula statement, the operation components and the operators in the target formula statement can be marked first, the operation components and the operators in the target formula statement are identified, and then the logic of the target formula is identified according to the marking result, so as to construct a reverse polish expression.

[0071] At this time, the computer device analyzes the marked tokens, and constructs a reverse polish expression. The reverse polish expression is also called a postfix expression, which writes the operation quantity in front and the operator in back, such as 1+2 written as [1,2,+]. The implementation logic is to extract and process the marked token array one by one, the operands are entered into the operand list and the result list, the operators are processed for unary and binary distinction and priority judgment, and then entered into the result list after the required operands, and the left and right parentheses are specially stacked, forming a reverse polish expression.

[0072] Then, according to the arrangement order of the operation components and the operators in the reverse polish expression, the JAVA bytecode file is generated and loaded as the JAVA class corresponding to the target formula statement.

[0073] When the reverse polish expression of the target formula statement is constructed, since the syntax order of the reverse polish expression is actually the execution syntax of the target formula statement, the corresponding JAVA bytecode file can be generated according to the syntax order of the reverse polish expression, and the JAVA class is generated through the JVM in the computer device.

[0074] For example, when 1+2 in the reverse polish expression is read, the computer device can identify the constant 1 and the constant 2, generate the corresponding JAVA bytecode, identify the operator + in the reverse polish expression, and generate the corresponding JAVA bytecode. The JAVA bytecode of the constant 1, the constant 2 and the operator + is spliced, that is, the JAVA bytecode of 1+2 is generated.

[0075] And when the formula has multiple operations, the JAVA bytecode formed by the operation statement with high operation priority can be spliced with the JAVA bytecode formed by the operation statement with low operation priority as a parameter according to the syntax order of the reverse polish expression, so as to realize the formation of the JAVA bytecode file of a more complex formula.

[0076] When the JAVA bytecode is formed, the computer device can load the class file bytecode content into the memory (for example, the cache) through the JVM, and convert the static data into the runtime data structure in the method area, and generate a Class object representing the class in the heap.

[0077] Finally, when the JAVA class of the target formula statement is detected in the cache, the JAVA class corresponding to the target formula statement is called to calculate the input target transaction data to obtain the target pricing result.

[0078] When the JVM loads the Class file bytecode content into the memory, the computer device can directly call the class object to calculate the input target transaction data, so as to obtain the target pricing result obtained by substituting the target transaction data into the target formula statement.

[0079] In summary, before online pricing, the computer device constructs the reverse polish expression of the target formula statement, so as to represent the operation order of the target formula statement. The computer device then compiles and encapsulates the JAVA bytecode file according to the operation order in the reverse polish expression, and correspondingly generates the JAVA class to be saved in the cache of the computer device. At this time, when the computer device needs to calculate the target transaction data, the JAVA class can be directly called to calculate the target transaction data. The compiling process and the calculation process are separated, avoiding the tedious operation of interpreting and executing one sentence at a time of the computer device, simplifying the calculation logic, and improving the operation speed of online pricing.

[0080] Figure 3 is a method flowchart of an online pricing method according to an example embodiment. The method is executed by a computer device, which can be a server or a terminal in the prior pricing system as shown in Figure 1 As shown in Figure 3 , the online pricing method can include the following steps:

[0081] Step 301, obtaining target transaction data and target formula statement.

[0082] When the computer device needs to perform formula calculation, the target transaction data input by the user and the target formula statement for calculating the target transaction data can be obtained.

[0083] In a possible implementation, when the computer device is a terminal, the terminal runs a client of the financial application, and the user can input the target transaction data and the target formula statement into the terminal through a data collection component (such as a keyboard or a touch screen) of the terminal.

[0084] In another possible implementation, when the computer device is a server, the server runs a server of the financial application, and the server can communicate with a terminal running a client of the financial application to receive the target transaction data and the target formula statement, perform calculation in the server, and return the calculated pricing result to the terminal.

[0085] In step 302, it is detected whether the JAVA class corresponding to the target formula statement exists in the cache.

[0086] When the computer device receives the target formula statement, the computer device can first perform detection in the cache to check whether the JAVA class corresponding to the target formula statement exists in the cache of the computer device, so as to determine the operation performed on the target formula statement subsequently.

[0087] In a possible implementation, when it is detected that the JAVA class corresponding to the target formula statement exists in the cache, the JAVA class corresponding to the target formula statement is invoked to calculate the input target transaction data, and the target pricing result is obtained.

[0088] When it is detected that the JAVA class corresponding to the target formula statement exists in the cache, it indicates that the target formula statement has been parsed and constructed as a JAVA Class file, and the computer device does not need to parse the target formula statement, but can directly invoke the JAVA class loaded in the cache to calculate the input target transaction data, so as to obtain the target pricing result.

[0089] In step 303, when it is detected that the JAVA class corresponding to the target formula statement does not exist in the cache, the operation components and the operators in the target formula statement are marked, and an inverse Polish expression is constructed according to the marking result.

[0090] When it is detected that the JAVA class corresponding to the target formula statement does not exist in the cache, it indicates that the target formula statement has not been parsed before, and the target formula statement needs to be processed again.

[0091] In the process of processing the target formula statement, the operation components and the operators in the target formula statement need to be marked first, so as to mark and distinguish various operators, parentheses, variables, functions, and the like.

[0092] In the embodiment of the present application, when the target formula statement is labeled, the formula string can be parsed character by character, and the cutting processing of whether the characters before and after are of the same type and whether more characters are needed after the character is judged, and the cut string is labeled to form a labeled word segmentation array.

[0093] For example, the commonly used operators (such as four arithmetic operators) in the target formula statement are first marked, and then other characters are marked in turn. For example, when the data 100 appears, the computer device recognizes that the three adjacent characters 1, 0 and 0 are characters of the same type, so the three adjacent characters can be marked as a constant.

[0094] When each operator and operation component in the formula is marked, the target formula statement in the infix form can be parsed and converted into a postfix expression in the reverse Polish expression, as shown in Figure 4 The conversion flowchart of the reverse Polish expression is shown in Figure 4 The conversion logic of the reverse Polish expression is as follows.

[0095] When the operator and operation component of the target formula statement are obtained, the priority relationship between the operators is first input in the computer device, and the infix expression is scanned from left to right.

[0096] When the operation component is scanned, the operation component is directly output.

[0097] When the operator is scanned, it is judged whether the operation stack (W stack) is empty at this time. When the W stack is empty, the operator is stacked. When the W stack is not empty, the priority of the current operator and the operator at the top of the W stack is compared. If the priority of the current operator is higher, the stacking operation is performed. If the priority of the current operator is lower, the stack is output.

[0098] When the left bracket is scanned, the stacking operation is directly performed.

[0099] When the right bracket is scanned, it is judged whether the top of the stack is a left bracket, and whether the W stack is empty at this time. If the W stack is empty, the program error is executed. If the W stack is not empty, the stack is output.

[0100] When the scanning is completed, it is judged whether the W stack is empty. If the W stack is empty, the process is ended. If the W stack is not empty, it is judged whether the top of the stack is a left bracket. If the top of the stack is a left bracket, the program error is executed. If the top of the stack is not a left bracket, the stack is output.

[0101] In a possible implementation, the target operator in the reverse Polish expression is acquired, and the operation component corresponding to the target operator is acquired; it is detected whether the data type of the operation component matches the execution data type of the target operator, and if not, a first error message is generated.

[0102] After the reverse Polish expression is acquired, the reverse Polish expression needs to be checked to ensure its correctness.

[0103] When the reverse Polish expression is acquired, each operator (for example, a target operator) in the reverse Polish expression can be checked, that is, it is detected whether the data type required to be executed by the target operator is consistent with the data type of the operation component. When the data type required to be executed by the target operator is inconsistent with the data type of the operation component, the reverse Polish expression cannot be normally executed, and the computer device generates a first error message.

[0104] In a possible implementation, when the target function exists in the reverse Polish expression, it is detected whether the function name of the target function exists, and if not, a second error message is generated.

[0105] The computer device can also verify the function name of the target function in the reverse Polish expression. If the computer device does not detect the function name of the target function in the cache, it indicates that the target function is not defined in the computer device, and the target function cannot normally execute the operation, and the second error message is generated.

[0106] In a possible implementation, the parameter definition quantity of the target function and the parameter call quantity of the target function are acquired.

[0107] When the parameter definition quantity of the target function and the parameter call quantity of the target function are inconsistent, a third error message is generated.

[0108] The computer device can also further check the target function, acquire the parameter definition quantity in the target function, for example, the target function defines three data, and the parameter called by the target function is greater than three data, that is, the target function calls undefined data, and the reverse Polish expression is obviously abnormal, and the third error message is generated.

[0109] In step 304, according to the arrangement order of the operation component and the operator in the reverse Polish expression, a JAVA bytecode file is generated and loaded as a JAVA class corresponding to the target formula statement.

[0110] In the embodiments of the present application, since the arrangement order of the operation components and the operators in the reverse Polish expression is the execution order of the reverse Polish expression, the arrangement order of the operation components and the operators in the reverse Polish expression is generated into the JAVA bytecode file, and each binary data in the JAVA bytecode file can indicate the computer to process each operation component according to the arrangement order of the operators.

[0111] In a possible implementation manner of the embodiments of the present application, when the target function exists in the target formula statement, the target function also exists in the reverse Polish expression, that is, the operation components, the operators and the target function exist in the reverse Polish expression, and the arrangement order of the above three is also the execution order of the reverse Polish expression.

[0112] The principle of compiling the reverse Polish expression into the JAVA bytecode is introduced below.

[0113] In a possible implementation manner, the reverse Polish expression is traversed, when a target operation component is traversed, the operation component is encapsulated into the JAVA bytecode and placed in the JAVA bytecode temporary list; when a target operator is traversed, the JAVA bytecode corresponding to the target operator is taken out from the JAVA bytecode temporary list, spliced with the JAVA bytecode of the target operator, and placed in the JAVA bytecode temporary list; and the JAVA bytecode file is generated based on the JAVA bytecode in the JAVA bytecode temporary list obtained by traversing the reverse Polish expression.

[0114] The computer device traverses the reverse Polish expression, when a target operation component is traversed, the operation component is encapsulated into the JAVA bytecode format and placed in the JAVA bytecode temporary list.

[0115] When the computer device traverses a target operator, the JAVA bytecode is taken out from the JAVA bytecode temporary list, for example, when the target operator is an arithmetic operator, the two JAVA bytecode format parameters which are last-in first-out are taken out from the JAVA bytecode temporary list, spliced with the JAVA bytecode corresponding to the target operator, and encapsulated into a JAVA bytecode and returned to the JAVA bytecode temporary list.

[0116] For example, when a target operator "+" is traversed, the computer device takes out two JAVA bytecode format parameters, such as "1" and "2", from the JAVA bytecode temporary list, and then splices the JAVA bytecodes of "1", "2" and "+" into a JAVA bytecode and stacks it, that is, the computer device saves "1+2" as an operation result in the JAVA bytecode format.

[0117] When traversing each target operator, the only one JAVA bytecode left after the merging operation between JAVA bytecodes is the JAVA bytecode representing the whole calculation flow of the target formula statement, i.e. the JAVA bytecode file corresponding to the target formula statement.

[0118] Since the reverse Polish expression itself represents the operation logic of the target formula statement, the generated JAVA bytecode can also represent the operation logic allowed by the target formula, and the computer device can recognize the operation logic of the target formula statement and execute the operation logic of the target formula statement according to the content in the JAVA bytecode file after the JAVA bytecode file is loaded by the JVM.

[0119] In a possible implementation, when the target function is traversed, the JAVA bytecode corresponding to the target function name is taken out from the JAVA bytecode temporary list, and is spliced with the JAVA bytecode calling the target function to obtain the JAVA bytecode in the calling function format; and the JAVA bytecode in the calling function format is placed in the JAVA bytecode temporary list.

[0120] When the target formula statement has the target function, the target function also exists in the reverse Polish expression, and when the target function in the reverse Polish expression is traversed, the number of parameters required to be called by the target function is determined, and the JAVA bytecode corresponding to the number of parameters required to be called by the target function is taken out to be spliced with the JAVA bytecode calling the target function to obtain the JAVA bytecode in the calling function format.

[0121] For example, when the function F(X, Y, Z) is traversed, the function name F is marked from the beginning to the position of the closing bracket, and it is found that the function F(X, Y, Z) needs to call three parameters, and the three JAVA bytecodes are taken out from the JAVA bytecode temporary list to be spliced with the JAVA bytecode calling the function F(X, Y, Z), and the finally spliced JAVA bytecode represents the result obtained by substituting the three parameters into the function F(X, Y, Z).

[0122] In a possible implementation, when the target function is obtained, the function header of the target function is processed into the function stack, and when the comma in the target function is traversed, if the number of parameter lists of the function at the top of the function stack is 0, two parameters are taken out from the JAVA bytecode temporary list and written into the parameter list of the function at the top of the function stack, and if the number of parameter lists of the function at the top of the function stack is not 0, one parameter is taken out from the JAVA bytecode temporary list and written into the parameter list of the function at the top of the function stack.

[0123] For example, for F(X, Y, Z), the function header is first written into the function stack, at this time the function at the top of the function stack is "F(X, Y, Z)", at this time the computer device continues to detect F(X, Y, Z), when detecting the first comma in F(X, Y, Z), at this time the parameter list has not been written, the parameter in the parameter list is 0, therefore two parameters are taken from the JAVA bytecode temporary list and written into the parameter list (as X and Y); when detecting the second comma in F(X, Y, Z), at this time the parameter list has the parameter, therefore one parameter is taken from the JAVA bytecode temporary list and written into the parameter list (as Z), thereby completing the operation of the JAVA bytecode in the JAVA bytecode temporary list for taking the number of parameters of the target function call.

[0124] When the JAVA bytecode file corresponding to the target formula statement is generated, the computer device can load the JAVA bytecode file through JVM to generate the JAVA class corresponding to the target formula statement.

[0125] In a possible implementation, the constants and variables of the reverse Polish expression in the embodiment of the present application are encapsulated by the Java bytecode of new BigDecimal().

[0126] The API class BigDecimal provided by Java in the java.math package is used to perform accurate operation on numbers with more than 16 significant digits. The double precision floating point variable double can process 16 significant numbers. In actual application, operation and processing of larger or smaller numbers are required.

[0127] Therefore, encapsulation into the JAVA bytecode by BigDecimal can realize higher precision data calculation.

[0128] In step 305, the JAVA class corresponding to the target formula statement is called to calculate the target transaction data to obtain the target pricing result.

[0129] The computer device calls the JAVA class corresponding to the target formula statement, and can calculate the input target transaction data to obtain the target pricing result obtained by substituting the target transaction data into the target formula statement.

[0130] In summary, before online pricing is performed, the computer device constructs a reverse Polish expression of the target formula statement, thereby representing the operation sequence of the target formula statement; the computer device then compiles and encapsulates the operation sequence in a JAVA bytecode file according to the operation sequence in the reverse Polish expression, and generates a corresponding JAVA class for saving in the cache of the computer device; at this time, when the computer device needs to perform calculation on target transaction data, the JAVA class can be directly called to perform data calculation on the target transaction data, the compiling process and the calculation process are separated, the tedious operation of the computer device interpreting one sentence and then executing another sentence is avoided, the calculation logic is simplified, and the operation speed of online pricing is improved.

[0131] Please refer to Figure 5 which shows a flow block diagram of an online pricing method according to an embodiment of the present application. As Figure 5 shown, the present application embodiment realizes the compiling and execution of a calculation expression, the calculation is based on BigDecimal, the precision is high, basic four operations are supported, variables and custom functions are supported, and the formula can be verified.

[0132] The implementation logic of the present application embodiment is as follows:

[0133] The implementation process in the present application embodiment includes six modules of lexical analysis, syntax analysis, semantic analysis, compilation, dynamic loading, and execution.

[0134] The lexical analysis module performs tokenization on the formula, and distinguishes various operators, parentheses, variables, functions, etc. The implementation logic is to parse the formula string character by character, judge whether the front and back characters are of the same type, and whether more characters are needed after the character, perform cutting processing, and perform type annotation on the cut string to form a token array after annotation.

[0135] The syntax analysis module analyzes the token after annotation, and constructs a reverse Polish expression. The reverse Polish expression, also known as the postfix expression, writes the operation quantity in front and the operator in back, such as 1+2 written as [1,2, +]. The implementation logic is to extract the token array after annotation one by one, the operands are entered into the operand list and the result list, the operators are processed by distinguishing one from two and judging the priority, and then entered into the result list after the required operands, the left and right parentheses are specially stacked, and the reverse Polish expression is formed.

[0136] The semantic analysis module analyzes and verifies the constructed reverse Polish expression, verifies the data type of the operands for the operator, verifies whether the function name exists, verifies the number of parameters of the function call and the definition parameter range of the corresponding function, and throws a friendly formula error prompt.

[0137] The compiling module loads the reverse polish expression, processes and encapsulates the JAVA bytecode syntax, compiles into a JAVA bytecode form of a class implementing a specific interface, and generates a corresponding JAVA bytecode file.

[0138] The JAVA bytecode syntax processing and encapsulation process is as follows: first, the class header, constructor method, and member method header of the JAVA bytecode are generated and stored in the class generator. In the second step, the reverse polish expression is traversed, and the constant operands such as 123 are encapsulated into the JAVA bytecode in the form of new BigDecimal(), and the JAVA bytecode array is placed in the JAVA bytecode temporary list; the variable is generated to obtain the JAVA bytecode of the variable and placed in the JAVA bytecode temporary list.

[0139] When the function is traversed, the function header is processed into the function stack; for the comma, if the parameter list of the function at the top of the function stack is zero, two parameters are taken from the JAVA bytecode temporary list and placed into the parameter list of the function at the top of the function stack, otherwise one parameter is taken from the JAVA bytecode temporary list and placed into the parameter list of the function at the top of the function stack, and the corresponding number of nodes in the reverse polish expression is removed; for the function end, the parameters are processed and encapsulated into the JAVA bytecode call of the function, the JAVA bytecode of the function is stored in the current node, and the node is set as the result type; for the result type, the JAVA bytecode of the node is obtained and placed in the JAVA bytecode temporary list.

[0140] When the operator is traversed, the JAVA bytecode of two parameters is taken from the JAVA bytecode temporary list and removed, the JAVA bytecode containing the current calculation is generated and stored in the current node, the node is set as the result type, and the corresponding number of nodes in the reverse polish expression is removed.

[0141] In the third step, the type of the only remaining node is judged, the JAVA bytecode in the form of new BigDecimal() is generated for the constant operand, the JAVA bytecode of the variable is generated for the variable, and the JAVA bytecode stored in the node is obtained for the result, and the finally generated JAVA bytecode is stored in the class generator. Finally, the member method end and other required end contents of the JAVA bytecode are generated and stored in the class generator, and the generation of the entire JAVA bytecode file is completed.

[0142] The dynamic loading module loads the compiled JAVA bytecode file as a class into the class loader of the JVM and stores it in the cache for calling.

[0143] When the formula is executed, it is first determined whether the JAVA class corresponding to the formula exists in the cache. If not, the lexical analysis and other processes are performed for analysis and compilation, and after the corresponding JAVA class is found, it is called and the result is obtained.

[0144] The formula operation shown in the embodiment of the application has the feature that the running speed is equivalent to the performance of the original JAVA code (the class file is consistent) except that it needs to be compiled once for the first execution. No additional intermediate variable support is needed, and long formulas are written as JAVA code equivalent to one line. It is difficult to write such a simplified code manually. In terms of debugging support, the class file is generated to the local when the debug is enabled, and the compiled code can be output. The breakpoint can be directly set for the custom function.

[0145] Figure 6 A structural block diagram of an online pricing device is shown according to an exemplary embodiment, as shown in Figure 6 The device includes:

[0146] The formula obtaining module 601 is configured to obtain target transaction data and a target formula statement.

[0147] The class calling module 602 is configured to call a JAVA class corresponding to the target formula statement to process the target transaction data to obtain a target pricing result when it is detected that the JAVA class corresponding to the target formula statement exists in the cache.

[0148] The JAVA class corresponding to the target formula statement is obtained by loading a JAVA bytecode file corresponding to the target formula statement; and the JAVA bytecode file is generated based on the arrangement order of the operators and the operation components in the reverse Polish expression of the target formula statement.

[0149] In a possible implementation, the device further includes:

[0150] The expression obtaining module is configured to, when it is detected that the JAVA class corresponding to the target formula statement does not exist in the cache, mark the operation components and the operators in the target formula statement to obtain a reverse Polish expression of the target formula statement.

[0151] The bytecode file generating module is configured to generate the JAVA bytecode file according to the arrangement order of the operation components and the operators in the reverse Polish expression, and load the JAVA bytecode file as the JAVA class corresponding to the target formula statement.

[0152] In a possible implementation, the bytecode file generating module is further configured to,

[0153] traverse the reverse Polish expression, and when a target operation component is traversed, encapsulate the operation component as a JAVA bytecode and place it in a JAVA bytecode temporary list.

[0154] When the target operator is traversed, the corresponding JAVA bytecode is taken out from the JAVA bytecode temporary list, spliced with the JAVA bytecode of the target operator, and the spliced JAVA bytecode is placed in the JAVA bytecode temporary list;

[0155] Based on the JAVA bytecode in the JAVA bytecode temporary list obtained by traversing the reverse polish expression, the JAVA bytecode file is generated.

[0156] In a possible implementation, the reverse polish expression further includes a target function;

[0157] The bytecode file generation module is further configured to,

[0158] When the target function is traversed, the corresponding JAVA bytecode is taken out from the JAVA bytecode temporary list according to the target function name, and the JAVA bytecode of calling the target function is spliced into the JAVA bytecode in the calling function format;

[0159] The JAVA bytecode in the calling function format is placed in the JAVA bytecode temporary list.

[0160] In a possible implementation, the apparatus further includes:

[0161] A reverse polish expression reading module is configured to acquire a target operator in the reverse polish expression and an operation component corresponding to the target operator;

[0162] A first detection module is configured to detect whether the data type of the operation component matches the execution data type of the target operator, and generate a first error message if the data types do not match.

[0163] In a possible implementation, the apparatus further includes:

[0164] A second detection module is configured to detect whether the function name of the target function exists when the target function exists in the reverse polish expression, and generate a second error message if the function name does not exist.

[0165] In a possible implementation, the apparatus further includes:

[0166] A function parameter analysis module is configured to acquire the parameter definition quantity of the target function and the parameter calling quantity of the target function;

[0167] A third detection module is configured to generate a third error message when the parameter definition quantity of the target function and the parameter calling quantity of the target function are different.

[0168] In summary, before online pricing is performed, the computer device constructs a reverse polish expression of the target formula statement, thereby representing the operation sequence of the target formula statement; the computer device then compiles and encapsulates the reverse polish expression into a JAVA bytecode file according to the operation sequence in the reverse polish expression, and generates a corresponding JAVA class to be saved in the cache of the computer device; at this time, when the computer device needs to perform calculation on target transaction data, the JAVA class can be directly called to perform data calculation on the target transaction data, so that the compiling process and the calculation process are separated, the tedious operation of interpreting a sentence and then executing a sentence by the computer device is avoided, the calculation logic is simplified, and the operation speed of online pricing is improved.

[0169] Please refer to Figure 7 According to an example embodiment of the present application, a computer device is provided, which includes a memory and a processor, the memory is configured to store a computer program, and the computer program is configured to be executed by the processor to implement the above method.

[0170] The processor can be a central processing unit (CPU), or the processor can also be another processor supporting JAVA operation.

[0171] The memory is a non-transitory computer readable storage medium, which can be configured to store a non-transitory software program, a non-transitory computer executable program and modules, such as program instructions / modules corresponding to the method in the embodiments of the present application. The processor executes various functions and data processing of the processor by running the non-transitory software program, instructions and modules stored in the memory, that is, implements the method in the above method embodiments.

[0172] The memory can include a program storage area and a data storage area, wherein the program storage area can store an operating system and at least one application required by a function; the data storage area can store data created by the processor, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-transitory memory, such as at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state memory device. In some embodiments, the memory can optionally include a memory remotely arranged with respect to the processor, and these remote memories can be connected to the processor through a network. Examples of the above network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.

[0173] In an exemplary embodiment, a computer readable storage medium storing at least one computer program is also provided, the at least one computer program is loaded and executed by a processor to implement all or part of the steps in the above method. For example, the computer readable storage medium can be a Read-Only Memory (ROM), a Random Access Memory (RAM), a Compact Disc Read-Only Memory (CD-ROM), a magnetic tape, a floppy disk and an optical data storage device, etc.

[0174] Other embodiments of the application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. It is intended that the specification and examples be considered as exemplary only, with the true scope and spirit of the application being indicated by the following claims.

[0175] It is to be understood that the application is not limited to the precise details of design and construction that have been described and exemplified above and that various modifications and changes can be made by those skilled in the art without departing from the scope of the application. The scope of the application is limited only by the claims that follow.

Claims

1. An online pricing method, characterized by, The method comprises: acquiring target transaction data and a target formula statement; when it is detected that the JAVA class corresponding to the target formula statement exists in the cache, calling the JAVA class corresponding to the target formula statement to process the target transaction data to obtain a target pricing result; wherein the JAVA class corresponding to the target formula statement is obtained by loading a JAVA bytecode file corresponding to the target formula statement; the JAVA bytecode file is generated based on the arrangement order of the operators and the operation components in the reverse polish expression of the target formula statement; when it is detected that the JAVA class corresponding to the target formula statement does not exist in the cache, marking the operation components and the operators in the target formula statement to obtain a reverse polish expression of the target formula statement; generating the JAVA bytecode file according to the arrangement order of the operation components and the operators in the reverse polish expression, and loading the JAVA bytecode file as the JAVA class corresponding to the target formula statement; wherein the generating the JAVA bytecode file according to the arrangement order of the operation components and the operators in the reverse polish expression comprises: traversing the reverse polish expression, when a target operation component is traversed, encapsulating the target operation component as JAVA bytecode and placing the JAVA bytecode in a JAVA bytecode temporary list; when a target operator is traversed, corresponding JAVA bytecode is taken out from the JAVA bytecode temporary list, the JAVA bytecode of the target operator is spliced, and the spliced JAVA bytecode is placed in the JAVA bytecode temporary list; the JAVA bytecode file is generated based on the JAVA bytecode in the JAVA bytecode temporary list obtained by traversing the reverse polish expression; the operation component of the reverse polish expression is encapsulated by the Java bytecode of new BigDecimal().

2. The method of claim 1, wherein, The reverse polish expression further comprises a target function; before the generating the JAVA bytecode file, the method further comprises: when a target function is traversed, corresponding JAVA bytecode is taken out from the JAVA bytecode temporary list according to the target function name, wherein the number of parameters required to be called by the target function is determined, a corresponding number of JAVA bytecodes are taken out according to the number of parameters required to be called by the target function, and the JAVA bytecodes are spliced into JAVA bytecodes in a calling function format; the JAVA bytecodes in the calling function format are placed in the JAVA bytecode temporary list.

3. The method according to claim 1 or 2, characterized in that, before the generating the JAVA bytecode file according to the arrangement order of the operation components and the operators in the reverse polish expression, the method further comprises: acquiring a target operator in the reverse polish expression and an operation component corresponding to the target operator; detecting whether the data type of the operation component matches the execution data type of the target operator, and generating a first error message if the data types do not match.

4. The method of claim 2, wherein, before the generating the JAVA bytecode file according to the arrangement order of the operation components and the operators in the reverse polish expression, the method further comprises: When the objective function exists in the reverse polish expression, it is detected whether the function name of the objective function exists, and if not, a second error message is generated.

5. The method of claim 4, wherein, The method further comprises: acquiring the number of parameter definitions of the objective function and the number of parameter calls of the objective function; when the number of parameter definitions of the objective function is different from the number of parameter calls, a third error message is generated.

6. An online pricing device, characterized by The device comprises: a formula acquisition module, configured to acquire target transaction data and a target formula statement; a class calling module, configured to, when it is detected that the JAVA class corresponding to the target formula statement exists in the cache, call the JAVA class corresponding to the target formula statement to process the target transaction data to obtain a target pricing result; wherein the JAVA class corresponding to the target formula statement is obtained by loading the JAVA bytecode file corresponding to the target formula statement; and the JAVA bytecode file is generated based on the arrangement order of the operators and the operation components in the reverse polish expression of the target formula statement; an expression acquisition module, configured to, when it is detected that the JAVA class corresponding to the target formula statement does not exist in the cache, mark the operation components and the operators in the target formula statement to obtain the reverse polish expression of the target formula statement; a bytecode file generation module, configured to generate the JAVA bytecode file according to the arrangement order of the operation components and the operators in the reverse polish expression, and load it as the JAVA class corresponding to the target formula statement; wherein the bytecode file generation module is further configured to: traverse the reverse polish expression, when a target operation component is traversed, encapsulate the target operation component as JAVA bytecode and place it in a JAVA bytecode temporary list; when a target operator is traversed, correspondingly take out JAVA bytecode from the JAVA bytecode temporary list, splice the JAVA bytecode of the target operator, and place the spliced JAVA bytecode in the JAVA bytecode temporary list; and generate the JAVA bytecode file based on the JAVA bytecode in the JAVA bytecode temporary list obtained by traversing the reverse polish expression; and the operation components of the reverse polish expression are encapsulated by the Java bytecode of new BigDecimal().

7. A computer device, comprising: The computer device comprises a processor and a memory, the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by the processor to realize the online pricing method according to any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, The storage medium stores at least one instruction, and the at least one instruction is loaded and executed by the processor to realize the online pricing method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method, device and system for dynamically configuring rules based on Java and readable medium

    CN111522558A